2017-08-28 101 views
0

我們使用Azure媒體服務器進行編碼和生成縮略圖。 我們有編碼組合的任務下面的代碼,並生成縮略圖Azure mediaserver視頻編碼/縮略圖任務失敗

IJob job = _context.Jobs.Create(filename + " - Media Encoder Standard"); 

     IMediaProcessor processor = GetLatestMediaProcessorByName("Media Encoder Standard"); 

     ITask task = job.Tasks.AddNew("Media Encoder Standard", processor, "H264 Single Bitrate 720p for Android", options); 

     // Specify the input asset to be encoded. 
     task.InputAssets.Add(asset); 

     task.OutputAssets.AddNew("Output asset", 
     AssetCreationOptions.None); 

     task = job.Tasks.AddNew("Media Encoder Standard", processor, configuration, options); 

     // Specify the input asset to be encoded. 
     task.InputAssets.Add(asset); 

     task.OutputAssets.AddNew("Output asset", 
     AssetCreationOptions.None); 

     // Submit the job and wait until it is completed. 
     job.Submit(); 

     job = job.StartExecutionProgressTask(
      j => 
      { 
      }, 
      CancellationToken.None).Result; 

     Console.WriteLine("Transcoding job finished."); 

     var outputAssets = job.OutputMediaAssets.ToList(); 

     return outputAssets; 

但是如果縮略圖任務失敗和視頻編碼經歷。我們仍然爲視頻生成一個網址。

我們用下面的代碼生成的URL

public string PublishAssetGetURLs(IAsset asset, string fileExt = "") 
    { 
     // Publish the output asset by creating an Origin locator for adaptive streaming, 
     // and a SAS locator for progressive download. 

     _context.Locators.Create(
      LocatorType.Sas, 
      asset, 
      AccessPermissions.Read, 
      TimeSpan.FromDays(365)); 

     IEnumerable<IAssetFile> assetFiles = asset 
      .AssetFiles 
      .ToList() 
      .Where(af => af.Name.EndsWith(fileExt, StringComparison.OrdinalIgnoreCase)); 

     // Get the URls for progressive download for each specified file that was generated as a result 
     // of encoding. 

     List<Uri> sasUris = assetFiles.Select(af => af.GetSasUri()).ToList(); 

     var url = sasUris.FirstOrDefault(); 

     if (url != null) 
     { 
      return url.ToString(); 
     } 

     return string.Empty; 
    } 

然而,當URL使用我們得到以下XML

<Error><Code>AuthenticationFailed</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. 
RequestId:a6d14469-0001-0008-7bdb-1f3b8a000000 
Time:2017-08-28T08:58:17.0773123Z</Message><AuthenticationErrorDetail>Signature fields not well formed.</AuthenticationErrorDetail></Error> 

,如果這兩項任務都成功,它工作正常。我需要在資產上設置什麼嗎?

回答

0

我懷疑我的假設是錯誤的。只是有時候我會打破。這是由sas locator創建的url造成的。有時它會有一個+字符,這將導致錯誤。但是,如果它被編碼,它就像一個魅力。我需要更多咖啡

0

很高興看到您似乎已經自己修復了定位器創建錯誤。但是,您還提到,有時編碼任務成功,而縮略圖任務錯誤結束。您是否想要在輸入視頻的特定時間戳/時間碼中生成縮略圖?這通常是我遇到的編碼成功和縮略圖失敗的唯一情況。如果您可以分享您正在使用的縮略圖預設,我們可以進一步查看。

最後,在https://docs.microsoft.com/en-us/azure/media-services/media-services-dotnet-generate-thumbnail-with-mes中,有一個示例顯示您可以將編碼和縮略圖生成組合到一個任務中。

+0

嗨,謝謝你的回覆。縮略圖任務按原樣工作。我特意製作了縮略圖任務chrash,以查看錯誤處理是否可行:)我通過在json預設文件中輸入拼寫錯誤來做到這一點。順便說一句 - 這是我跟着它的例子,非常好:) – Bjarke