繁体   English   中英

Azure媒体服务视频轮播

[英]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.

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