我正在尝试使用Azure媒体服务让我的视频正常播放 . 在人像模式下拍摄的视频无法正常播放,不会旋转 . 这是我的代码(取自Azure Media Services示例)
Dim filenamewithpath As String = Server.MapPath("." & "\video2.mp4")
Dim filename As String = Path.GetFileName(filenamewithpath)
Dim preset As String = "H264 Adaptive Bitrate MP4 Set 720p"
FileVideo.SaveAs(filenamewithpath)
' Create and cache the Media Services credentials in a static class variable.
Dim assetName = "UploadSingleFile_" + DateTime.UtcNow.ToString()
Dim asset As IAsset = _context.Assets.Create(assetName, AssetCreationOptions.None)
Dim assetFile = asset.AssetFiles.Create(filename)
Dim accessPolicy As IAccessPolicy = _context.AccessPolicies.Create(assetName, TimeSpan.FromDays(30), _
AccessPermissions.Write Or AccessPermissions.List)
Dim locator As ILocator = _context.Locators.CreateLocator(LocatorType.Sas, asset, accessPolicy)
assetFile.Upload(filenamewithpath)
' Declare a new job.
Dim job As 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 a task with the encoding details, using a string preset.
Dim task As ITask = job.Tasks.AddNew(preset + " encoding task", latestMediaProcessor, preset, Microsoft.WindowsAzure.MediaServices.Client.TaskOptions.ProtectedConfiguration)
' Specify the input asset to be encoded.
task.InputAssets.Add(asset)
' Add an output asset to contain the results of the job.
task.OutputAssets.AddNew("Output asset", AssetCreationOptions.None)
job.Submit()
' Check job execution and wait for job to finish.
Dim progressJobTask As Task = job.GetExecutionProgressTask(CancellationToken.None)
progressJobTask.Wait()
' If job state is Error the event handling
' method for job progress should log errors. Here we check
' for error state and exit if needed.
If job.State = JobState.[Error] Then
Throw New Exception(vbLf & "Exiting method due to job error.")
End If
Dim MP4Asset As IAsset = job.OutputMediaAssets(0)
' BuildSasUrlForMP4File creates a SAS Locator
' and builds the SAS Url that can be used to
' progressively download the MP4 file.
Dim fullSASURL As String = BuildSasUrlForMP4File(MP4Asset)
Dim streamingURL As String _
= GetStreamingOriginLocatorURL(MP4Asset)
fullSASURL = "http://aka.ms/azuremediaplayeriframe?url=" & fullSASURL _
& "&autoplay=false"
在此链接:http://azure.microsoft.com/blog/2014/08/21/advanced-encoding-features-in-azure-media-encoder/
它表明Azure Media Services可以自动旋转:
<Presets Rotation="Auto">
<Preset
Version="5.0">
但我无法弄清楚如何将其纳入我的代码中 .
谢谢
1 回答
好的,这里至少有一个我能够挖掘的解决方案:
1)获取您尝试使用的预设的XML . 就我而言,我使用的是“H264 Adaptive Bitrate MP4 Set 720p” . 在上面的代码中,这是在字符串“预设”中 .
2)使用整个XML文件代替使用此字符串 .
3)将xml Presets标签更改为Presets Rotation =“Auto”
这里是获取预设的链接(可能还有其他)https://github.com/AzureMediaServicesSamples/Encoding-Presets/tree/master/VoD/Azure%20Media%20Encoder
创建一个新的XML文件(我把它放在我的网站的根目录-named config1.xml中) . 这是我预设的XML:
以下是我的代码中的更改:
请注意,您可以删除不再需要的预设字段 .