2012-12-03 48 views
0

我使用的Windows Azure媒體服務上傳的視頻文件,編碼,然後把它們發佈。 我使用Windows Azure媒體服務示例代碼對文件進行編碼,並且我發現當我使用代碼將「.mp4」文件轉換爲Apple HLS時,它在iOS設備中無法正常工作。只有音頻播放,沒有看到視頻。而如果我使用Windows Azure媒體服務門戶在HLS中編碼和發佈文件,則它們在iOS設備(音頻和視頻播放)上工作得非常好!的Windows Azure媒體服務蘋果HLS流 - 沒有視頻只能播放音頻播放

我一直在敲打我的這頭幾天,將是非常必須是有人能指導我的編碼過程(通過代碼)?

這是我到現在爲止!

static IAsset CreateEncodingJob(IAsset asset) 
    { 


     // Declare a new job. 
     IJob job = _context.Jobs.Create("My encoding job"); 
     // Get a media processor reference, and pass to it the name of the 
     // processor to use for the specific task. 
     IMediaProcessor processor = GetLatestMediaProcessorByName("Windows Azure Media Encoder"); 
     // Create a task with the encoding details, using a string preset. 
     ITask task = job.Tasks.AddNew("My encoding task", 
      processor, 
      "H264 Broadband SD 4x3", 
      TaskOptions.ProtectedConfiguration); 
     // Specify the input asset to be encoded. 
     task.InputAssets.Add(asset); 
     // Add an output asset to contain the results of the job. 
     // This output is specified as AssetCreationOptions.None, which 
     // means the output asset is in the clear (unencrypted). 
     task.OutputAssets.AddNew("Output MP4 asset", 
      true, 
      AssetCreationOptions.None); 

     // Launch the job. 
     job.Submit(); 

     // Checks job progress and prints to the console. 
     CheckJobProgress(job.Id); 

     // Get an updated job reference, after waiting for the job 
     // on the thread in the CheckJobProgress method. 
     job = GetJob(job.Id); 

     // Get a reference to the output asset from the job. 
     IAsset outputAsset = job.OutputMediaAssets[0]; 


     return outputAsset; 


    } 


static IAsset CreateMp4ToSmoothJob(IAsset asset) 
    { 

     // Read the encryption configuration data into a string. 
     string configuration = File.ReadAllText(Path.GetFullPath(_configFilePath + @"\MediaPackager_MP4ToSmooth.xml")); 



     //Publish the asset. 
     //GetStreamingOriginLocatorformp4(asset.Id); 


     // Declare a new job. 
     IJob job = _context.Jobs.Create("My MP4 to Smooth job"); 
     // Get a media processor reference, and pass to it the name of the 
     // processor to use for the specific task. 
     IMediaProcessor processor = GetLatestMediaProcessorByName("Windows Azure Media Packager"); 

     // Create a task with the encoding details, using a configuration file. Specify 
     // the use of protected configuration, which encrypts sensitive config data. 
     ITask task = job.Tasks.AddNew("My Mp4 to Smooth Task", 
      processor, 
      configuration, 
      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 Smooth asset", 
      true, 
      AssetCreationOptions.None); 

     // Launch the job. 
     job.Submit(); 

     // Checks job progress and prints to the console. 
     CheckJobProgress(job.Id); 


     job = GetJob(job.Id); 
     IAsset outputAsset = job.OutputMediaAssets[0]; 

     // Optionally download the output to the local machine. 
     //DownloadAssetToLocal(job.Id, _outputIsmFolder); 

     return outputAsset; 
    } 

    // Shows how to encode from smooth streaming to Apple HLS format. 
    static IAsset CreateSmoothToHlsJob(IAsset outputSmoothAsset) 
    { 
     // Read the encryption configuration data into a string. 
     string configuration = File.ReadAllText(Path.GetFullPath(_configFilePath + @"\MediaPackager_SmoothToHLS.xml")); 


     //var getismfile = from p in outputSmoothAsset.Files 
     //     where p.Name.EndsWith(".ism") 
     //     select p; 

     //IAssetFile manifestFile = getismfile.First(); 

     //manifestFile.IsPrimary = true; 

     var ismAssetFiles = outputSmoothAsset.AssetFiles.ToList().Where(f => f.Name.EndsWith(".ism", StringComparison.OrdinalIgnoreCase)).ToArray(); 

     if (ismAssetFiles.Count() != 1) 
      throw new ArgumentException("The asset should have only one, .ism file"); 

     ismAssetFiles.First().IsPrimary = true; 
     ismAssetFiles.First().Update(); 




     //Use the smooth asset as input asset 


     IAsset asset = outputSmoothAsset; 



     // Declare a new job. 
     IJob job = _context.Jobs.Create("My Smooth Streams to Apple HLS job"); 
     // Get a media processor reference, and pass to it the name of the 
     // processor to use for the specific task. 
     IMediaProcessor processor = GetMediaProcessor("Smooth Streams to HLS Task"); 

     // Create a task with the encoding details, using a configuration file. 
     ITask task = job.Tasks.AddNew("My Smooth to HLS Task", processor, configuration, 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 HLS asset", true, AssetCreationOptions.None); 

     // Launch the job. 
     job.Submit(); 

     // Checks job progress and prints to the console. 
     CheckJobProgress(job.Id); 

     // Optionally download the output to the local machine. 
     //DownloadAssetToLocal(job.Id, outputFolder); 

     job = GetJob(job.Id); 
     IAsset outputAsset = job.OutputMediaAssets[0]; 

     return outputAsset; 
    } 

回答

2

爲了轉換爲iOS兼容的HLS,您必須使用Smooth Streaming Source,它將成爲HLS的基礎。所以,你的步驟將是:

  1. 轉換源代碼以高品質H.264(MP4)
  2. 轉換步驟的結果(1)到Microsoft Smooth Streaming的
  3. 步驟轉換的結果(2) (平滑流式傳輸)轉換成HLS

HLS與Microsoft Smooth Streaming非常相似。因此它需要不同比特率的數據源塊。通過MP4進行HLS轉換將不會執行任何操作。

可悲的是IMO,微軟提供了management門戶這樣explorative功能。這導致用戶感到困惑。它在場景下的作用正是我向你建議的 - 首先獲得高質量的MP4,然後將其轉換爲Microsoft Smooth streaming,然後通過Smooth Streaming完成HLS。但用戶的事情,HLS是通過MP4執行的,這是完全錯誤的。

如果我們看看online documentation here,我們將看到任務預設名爲Convert Smooth Streams to Apple HTTP Live Streams。從那裏我們必須弄清楚HLS的正確來源是Microsoft Smooth Stream。根據我的經驗,只有良好的H.264源(MP4)才能製作出流暢的流暢效果。如果您嘗試將非H.264源代碼轉換爲平滑流,結果很可能是錯誤的。

您可以使用小工具WaMediaWeb(github上的源文件連續傳遞到Azure WebSites)進行試驗,此處爲:http://wamediaweb.azurewebsites.net/ - 僅提供您的媒體帳戶和密鑰。看看readme on GitHub的一些細節,如什麼來源產生什麼結果。

順便說一句,你可以在一個單一的作業堆棧任務,以避免不斷找工作的結果。方法task.OutputAssets.AddNew(...)實際上會返回一個IAsset,您可以將其用作另一個任務的InputAsset,並將該任務添加到同一作業中。如果你看看這個例子,它會在某個時候做到這一點。它也在創建HLS流方面做得很好,在iOS2上使用iPad2和iPhone 4進行測試。

+0

感謝您的回答!但我爲自己找到了解決方案。我沒有使用Windows Azure媒體編碼器將我的mp4文件轉換爲各種比特率以便流暢播放。我寧願使用Windows Azure媒體包裝工具將我的mp4轉換爲流暢的流媒體,並將其轉換爲本地比特率格式(而不是其他各種比特率)。而且我會根據你的建議來堆疊我的任務! –