Sydney Shown
Sydney Shown

Reputation: 7

Azure Media Services Stream Partial Content

I'm thinking to use Azure Media Services to store media files, mainly songs. I then want to stream only the first 20-30 seconds of the songs to users.

Can this be done?

Thanks for your help

Upvotes: 0

Views: 94

Answers (1)

Asela Chamara
Asela Chamara

Reputation: 259

The answer is Filters and dynamic manifests

You can define filters for your assets with Media Services. Starting with 2.11 release, Media Services enables you to define filters for your assets. These filters are server-side rules that help your customers do things like play a specific section of a video or specify a subset of audio and video renditions that your customer's device can handle (instead of all the renditions that are associated with the asset).

This filtering is achieved through dynamic manifests that are created when your customer requests to stream a video based on one or more specified filters.

For more information, see Filters and dynamic manifests:

https://learn.microsoft.com/en-us/azure/media-services/media-services-dynamic-manifest-overview

Also, you can use Media Services .NET SDK to create, update, and delete filters.

Note: if you update a filter, it can take up to 2 minutes for streaming endpoint to refresh the rules. If the content was served using this filter (and cached in proxies and CDN caches), updating this filter can result in player failures. It is recommending to clear the cache after updating the filter. If this option is not possible, consider using a different filter.

Create/Update/Read/Delete global filters

The following code shows how to use .NET to create, update,read, and delete asset filters.

string filterName = "GlobalFilter_" + Guid.NewGuid().ToString();

List<FilterTrackSelectStatement> filterTrackSelectStatements = new List<FilterTrackSelectStatement>();

FilterTrackSelectStatement filterTrackSelectStatement = new FilterTrackSelectStatement();
filterTrackSelectStatement.PropertyConditions = new List<IFilterTrackPropertyCondition>();
filterTrackSelectStatement.PropertyConditions.Add(new FilterTrackNameCondition("Track Name", FilterTrackCompareOperator.NotEqual));
filterTrackSelectStatement.PropertyConditions.Add(new FilterTrackBitrateRangeCondition(new FilterTrackBitrateRange(0, 1), FilterTrackCompareOperator.NotEqual));
filterTrackSelectStatement.PropertyConditions.Add(new FilterTrackTypeCondition(FilterTrackType.Audio, FilterTrackCompareOperator.NotEqual));
filterTrackSelectStatements.Add(filterTrackSelectStatement);

// Create
IStreamingFilter filter = _context.Filters.Create(filterName, new PresentationTimeRange(), filterTrackSelectStatements);

// Update
filter.PresentationTimeRange = new PresentationTimeRange(timescale: 500);
filter.Update();

// Read
var filterUpdated = _context.Filters.FirstOrDefault();
Console.WriteLine(filterUpdated.Name);

// Delete
filter.Delete();

Create/Update/Read/Delete asset filters

The following code shows how to use .NET to create, update,read, and delete asset filters.

string assetName = "AssetFilter_" + Guid.NewGuid().ToString();
var asset = _context.Assets.Create(assetName, AssetCreationOptions.None);

string filterName = "AssetFilter_" + Guid.NewGuid().ToString();


// Create
IStreamingAssetFilter filter = asset.AssetFilters.Create(filterName,
                                    new PresentationTimeRange(), 
                                    new List<FilterTrackSelectStatement>());

// Update
filter.PresentationTimeRange = 
        new PresentationTimeRange(start: 6000000000, end: 72000000000);

filter.Update();

// Read
asset = _context.Assets.Where(c => c.Id == asset.Id).FirstOrDefault();
var filterUpdated = asset.AssetFilters.FirstOrDefault();
Console.WriteLine(filterUpdated.Name);

// Delete
filterUpdated.Delete();

For more information please refer: https://learn.microsoft.com/en-us/azure/media-services/media-services-dotnet-dynamic-manifest

Upvotes: 1

Related Questions