Question
Andrei NS on Wed, 26 Nov 2014 19:23:57
Is there a way to generate thumbnail based on what it looks like it's 'best first frame' ?
For example, generate first frame which it's not black.
Somehow I have the feeling I saw this somewhere in the changes to AMS in the last 6 months or so.. Or I might be dreaming.
Replies
Julia Kornich on Tue, 02 Dec 2014 03:45:56
You can achieve that if you modify an encoder preset by including the thumbnail generation info.
<MediaFile ThumbnailMode="BestFrame" ThumbnailJpegCompression="75" ThumbnailCodec="Jpeg" ThumbnailSize="100%, 100%" ThumbnailEmbed="False">
By the end of the encoding job, the thumbnail will be in the output asset along with other output files.
For example, I uploaded a wmv file that had black frames at the beginning.
I modified the "H264 Adaptive Bitrate MP4 Set 720p.xml" preset (located here) to include the thumbnail generation info.
<?xml version="1.0" encoding="utf-16"?> <!--Created for Azure Media Encoder, July 30 2014 --> <Presets> <Preset Version="5.0"> <Job /> <MediaFile DeinterlaceMode="AutoPixelAdaptive" ResizeQuality="Super" AudioGainLevel="1" VideoResizeMode="Stretch" ThumbnailTime="00:00:00" ThumbnailMode="BestFrame" ThumbnailJpegCompression="75" ThumbnailCodec="Jpeg" ThumbnailSize="100%, 100%" ThumbnailEmbed="False"> . . .
I used the following SDK code to encode an asset that contains WMV to H264 Adaptive Bitrate MP4 Set 720p and also generate a thumbnail jpg file.
static public IAsset EncodeToAdaptiveBitrateMP4Set(IAsset inputAsset) { var encodingPreset = "H264 Adaptive Bitrate MP4 Set 720p"; IJob job = _context.Jobs.Create(String.Format("Encoding WMV {0} to {1}", inputAsset.Name, encodingPreset)); var mediaProcessors = _context.MediaProcessors.Where(p => p.Name.Contains("Media Encoder")).ToList(); var latestMediaProcessor = mediaProcessors.OrderBy(mp => new Version(mp.Version)).LastOrDefault(); string configuration = File.ReadAllText("H264 Adaptive Bitrate MP4 Set 720p with Thumbnail.xml"); ITask encodeTask = job.Tasks.AddNew("Encoding", latestMediaProcessor, configuration, TaskOptions.None); encodeTask.InputAssets.Add(inputAsset); encodeTask.OutputAssets.AddNew(String.Format("{0} as {1}", inputAsset.Name, encodingPreset), AssetCreationOptions.None); job.StateChanged += new EventHandler<JobStateChangedEventArgs>(JobStateChanged); job.Submit(); job.GetExecutionProgressTask(CancellationToken.None).Wait(); return job.OutputMediaAssets[0]; }-Julia
This posting is provided "AS IS" with no warranties, and confers no rights.
Andrei NS on Fri, 05 Dec 2014 16:21:05
Thanks for your response, I have few more questions:
1. I haven't been able to find any documentation about the MediaFile node, do you know where I can find it?
2. In the example you gave, what is the filename of the thumbnail? How can I set it?
3. I'm generating the thumbnail with a separate task, based on the information from here: http://msdn.microsoft.com/en-us/library/azure/hh973624.aspx
If I'm going to set the 'ThumbnailXXX' attributes on MediaNode as you suggested, I suppose I won't need the thumbnail generation task anymore?
Julia Kornich on Fri, 05 Dec 2014 19:55:57
Andrei,
1. The <MediaFile> element is part of the Media Encoder presets defined here.
2. The name contains the input file name plus some encoding information appended by _Thumb.jpg. In my case the name of the file is BigBuckBunny_H264_3400kbps_AAC_und_ch2_96kbps_Thumb.jpg.
3. The creation of a thumbnail based on the first non-black frame is not currently supported by the Thumbnail preset. Using an encoding job to generate the thumbnail based on the BestFrame is a workaround.
thank you,
Julia