简体   繁体   中英

Using Windows Azure Media Services SDK in .NET, how to encode to a dynamic package using custom encoding parameters instead of a preset string?

First, some background info.

I have a code that is basically taken from here:

http://channel9.msdn.com/Series/Windows-Azure-Media-Services-Tutorials/Introduction-to-dynamic-packaging

I have done a few modifications because the code didn't work quite well out of the box. Anyway, the code uploads a source video file to Azure, encodes it using a task preset for Media Services Encoder and outputs playback URLs to screen for Smooth Streaming and HLS playback.

The code that creates the encoding task is as follows:

ITask encodeTask = job.Tasks.AddNew("Encoding", processor, "H264 Adaptive Bitrate MP4 Set SD 16x9", TaskOptions.None);

I am not sure but I guess this preset implies Dynamic Packaging.

Now, the question: how can one specify exactly the parameters for encoding, such as different video resolutions and bitrates for each quality level, then whether to enable CABAC, b-frames, closed GOP and I also need 2 second fragments for Smooth Streaming and 10 second fragments for HLS.

How to achieve that? Something tells me I should pass some XML formatted string to the configuration parameter of the job.Tasks.AddNew method. If that is true, what is the recommended method to create the XML?

Thanks!

You can include xml file and can modify the xml file according to your requirement, you can find the xml file of the "H264 Adaptive Bitrate MP4 Set SD 16x9" encoding format here

        var inputAsset = context.Assets.Where(a => a.Id == inputAssetId).FirstOrDefault();
        if (inputAsset == null)
            throw new ArgumentException("Could not find assetId: " + inputAssetId);

        var encodingPreset = "H264 Adaptive Bitrate MP4 Set SD 16x9"; // <a href="http://msdn.microsoft.com/en-us/library/windowsazure/jj129582.aspx#H264Encoding">http://msdn.microsoft.com/en-us/library/windowsazure/jj129582.aspx#H264Encoding</a>

        var encodingPresetConfig = File.ReadAllText(@"D:\WAMS\DynamicPackagingUpload\DynamicPackagingUpload\DynamicPackagingUpload\Encoding.xml");
        IJob job = context.Jobs.Create("Encoding " + inputAsset.Name + " to " + encodingPreset);

        IMediaProcessor latestWameMediaProcessor = (from p in context.MediaProcessors where p.Name == "Windows Azure Media Encoder" select p).ToList()
                                                                     .OrderBy(wame => new Version(wame.Version)).LastOrDefault();

        ITask encodeTask = job.Tasks.AddNew("Encoding", latestWameMediaProcessor, encodingPresetConfig, TaskOptions.None);
        encodeTask.InputAssets.Add(inputAsset);
        encodeTask.OutputAssets.AddNew(inputAsset.Name + " as " + encodingPreset, AssetCreationOptions.None);

也许MSDN上的这个主题可以帮到你: http//msdn.microsoft.com/en-us/library/jj933290.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM