Azure Media Services Video Rotation -
i trying videos play using azure media services. videos taken in portrait mode not play properly, not rotated. here codes (taken azure media services sample)
dim filenamewithpath string = server.mappath("." & "\video2.mp4") dim filename string = path.getfilename(filenamewithpath) dim preset string = "h264 adaptive bitrate mp4 set 720p" filevideo.saveas(filenamewithpath) ' create , cache media services credentials in static class variable. dim assetname = "uploadsinglefile_" + datetime.utcnow.tostring() dim asset iasset = _context.assets.create(assetname, assetcreationoptions.none) dim assetfile = asset.assetfiles.create(filename) dim accesspolicy iaccesspolicy = _context.accesspolicies.create(assetname, timespan.fromdays(30), _ accesspermissions.write or accesspermissions.list) dim locator ilocator = _context.locators.createlocator(locatortype.sas, asset, accesspolicy) assetfile.upload(filenamewithpath) ' declare new job. dim job ijob = _context.jobs.create(preset + " encoding job") dim mediaprocessors = _context.mediaprocessors.where(function(p) p.name.contains("media encoder")).tolist() dim latestmediaprocessor = mediaprocessors.orderby(function(mp) new version(mp.version)).lastordefault() ' create task encoding details, using string preset. dim task itask = job.tasks.addnew(preset + " encoding task", latestmediaprocessor, preset, microsoft.windowsazure.mediaservices.client.taskoptions.protectedconfiguration) ' specify input asset encoded. task.inputassets.add(asset) ' add output asset contain results of job. task.outputassets.addnew("output asset", assetcreationoptions.none) job.submit() ' check job execution , wait job finish. dim progressjobtask task = job.getexecutionprogresstask(cancellationtoken.none) progressjobtask.wait() ' if job state error event handling ' method job progress should log errors. here check ' error state , exit if needed. if job.state = jobstate.[error] throw new exception(vblf & "exiting method due job error.") end if dim mp4asset iasset = job.outputmediaassets(0) ' buildsasurlformp4file creates sas locator ' , builds sas url can used ' progressively download mp4 file. dim fullsasurl string = buildsasurlformp4file(mp4asset) dim streamingurl string _ = getstreamingoriginlocatorurl(mp4asset) fullsasurl = "http://aka.ms/azuremediaplayeriframe?url=" & fullsasurl _ & "&autoplay=false"
in link: http://azure.microsoft.com/blog/2014/08/21/advanced-encoding-features-in-azure-media-encoder/
it shows azure media services can rotate automatically with:
<presets rotation="auto"> <preset version="5.0">
but can't figure out how incorporate in code.
thanks
ok, here @ least 1 solution have been able dig up:
1) obtain xml preset trying use. in case, using present "h264 adaptive bitrate mp4 set 720p". in code above, in string "preset".
2) instead of using string, use entire xml file preset.
3) change xml presets tag presets rotation="auto"
here link presets (there may others) https://github.com/azuremediaservicessamples/encoding-presets/tree/master/vod/azure%20media%20encoder
create new xml file (i put mine in root directory of website -named config1.xml). here xml preset:
<presets rotation="auto"> <preset version="5.0"> <job /> <mediafile deinterlacemode="autopixeladaptive" resizequality="super" audiogainlevel="1" videoresizemode="stretch"> <metadata mergecollection="true"> <item name="wm/encodedby" value="azure media encoder 4 - h264 adaptive bitrate mp4 set 720p, 07/30/2014 " /> </metadata> <outputformat> <mp4outputformat streamcompatibility="standard"> <videoprofile> <mainh264videoprofile bframecount="3" entropymode="cabac" rdoptimizationmode="speed" hadamardtransform="false" subblockmotionsearchmode="speed" multireferencemotionsearchmode="balanced" referencebframes="false" adaptivebframes="false" scenechangedetector="false" fastintradecisions="false" fastinterdecisions="false" subpixelmode="quarter" slicecount="0" keyframedistance="00:00:02" inloopfilter="true" mepartitionlevel="eightbyeight" referenceframes="4" searchrange="64" autofit="true" force16pixels="false" framerate="0" separatefilesperstream="true" smoothstreaming="false" numberofencoderthreads="0"> <streams autosize="false" freezesort="false"> <streaminfo size="1280, 720"> <bitrate> <constantbitrate bitrate="3400" istwopass="false" bufferwindow="00:00:05" /> </bitrate> </streaminfo> <streaminfo size="960, 540"> <bitrate> <constantbitrate bitrate="2250" istwopass="false" bufferwindow="00:00:05" /> </bitrate> </streaminfo> <streaminfo size="960, 540"> <bitrate> <constantbitrate bitrate="1500" istwopass="false" bufferwindow="00:00:05" /> </bitrate> </streaminfo> <streaminfo size="640, 360"> <bitrate> <constantbitrate bitrate="1000" istwopass="false" bufferwindow="00:00:05" /> </bitrate> </streaminfo> <streaminfo size="640, 360"> <bitrate> <constantbitrate bitrate="650" istwopass="false" bufferwindow="00:00:05" /> </bitrate> </streaminfo> <streaminfo size="320, 180"> <bitrate> <constantbitrate bitrate="400" istwopass="false" bufferwindow="00:00:05" /> </bitrate> </streaminfo> </streams> </mainh264videoprofile> </videoprofile> <audioprofile> <aacaudioprofile codec="aac" channels="2" bitspersample="16" samplespersecond="44100"> <bitrate> <constantbitrate bitrate="96" istwopass="false" bufferwindow="00:00:00" /> </bitrate> </aacaudioprofile> </audioprofile> </mp4outputformat> </outputformat> </mediafile> </preset> <preset version="5.0"> <job /> <mediafile audiogainlevel="1"> <metadata mergecollection="true"> <item name="wm/encodedby" value="azure media encoder 3 - h264 adaptive bitrate mp4 set 720p, 07/30/2014 " /> </metadata> <outputformat> <mp4outputformat streamcompatibility="standard"> <audioprofile> <aacaudioprofile codec="aac" channels="2" bitspersample="16" samplespersecond="44100"> <bitrate> <constantbitrate bitrate="96" istwopass="false" bufferwindow="00:00:00" /> </bitrate> </aacaudioprofile> </audioprofile> </mp4outputformat> </outputformat> </mediafile> </preset> <preset version="5.0"> <job /> <mediafile audiogainlevel="1"> <metadata mergecollection="true"> <item name="wm/encodedby" value="azure media encoder 3 - h264 adaptive bitrate mp4 set 720p, 07/30/2014 " /> </metadata> <outputformat> <mp4outputformat streamcompatibility="standard"> <audioprofile> <aacaudioprofile codec="aac" channels="2" bitspersample="16" samplespersecond="44100"> <bitrate> <constantbitrate bitrate="56" istwopass="false" bufferwindow="00:00:00" /> </bitrate> </aacaudioprofile> </audioprofile> </mp4outputformat> </outputformat> </mediafile> </preset> </presets>
here changes in code above:
dim configuration1 string = file.readalltext(server.mappath("config1.xml")) dim task itask = job.tasks.addnew(preset + " encoding task", _ latestmediaprocessor, configuration1, _ taskoptions.none)
note can remove preset field no longer needed.
Comments
Post a Comment