[英]Azure Media Services Video Rotation
我正在嘗試使用Azure Media Services使我的視頻正常播放。 以人像模式拍攝的視頻無法正常播放,並且無法旋轉。 這是我的代碼(摘自Azure媒體服務示例)
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媒體服務可以通過以下方式自動旋轉:
<Presets Rotation="Auto">
<Preset
Version="5.0">
但是我不知道如何將其合並到我的代碼中。
謝謝
好的,這是我至少能夠找到的一種解決方案:
1)獲取您要使用的預設的XML。 就我而言,我使用的是“ H264自適應比特率MP4設置720p”。 在我上面的代碼中,這是在字符串“ preset”中。
2)不用整個字符串,而是使用整個XML文件作為預置。
3)將xml Presets標簽更改為Presets Rotation =“ Auto”
這是獲取預設的鏈接(可能還有其他預設) https://github.com/AzureMediaServicesSamples/Encoding-Presets/tree/master/VoD/Azure%20Media%20Encoder
使用創建新的XML文件(我將我的文件放在名為config1.xml的網站的根目錄中)。 這是我的預設XML:
<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>
這是我上面代碼中的更改:
Dim configuration1 As String = File.ReadAllText(Server.MapPath("config1.xml"))
Dim task As ITask = job.Tasks.AddNew(preset + " encoding task", _
latestMediaProcessor, configuration1, _
TaskOptions.None)
請注意,您可以刪除預設字段,因為它不再需要。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.