2017-03-14 6 views
0

최근에 Media Services가 생성 된 뉴스가있는 몇 가지 지침이 있습니다. 우리는 "Azure Media Encoder"가 가치가 낮아지고 이제는 "Media Encoder Standard"를 사용한다는 것을 보았습니다. 따라서 동영상을 다시 업로드 할 수는 있지만 미리보기 이미지를 만들 수는 없습니다. 우리를 도울 수 있습니까? 애셋에서 미리보기 이미지를 가져 오는 방법은 무엇입니까? 당신은 썸네일에 대한 이전되지 않는 사전 스키마를 사용하는 것처럼자산에서 작은 이미지 만들기 - Azure Media Services

public void CreateThumbnails(string idAssetVideo, int iSegundo, string sPath) 
    { 
     if (string.IsNullOrEmpty(idAssetVideo)) throw new Excepcion("El idAssetVideo no puede ser nulo. Póngase en contacto con soporte."); 

     string sTime = Utilidades.GetDuracionLabelFromSegundos(iSegundo); 

     IAsset asset = _context.Assets.Where(a => a.Id == idAssetVideo).SingleOrDefault(); 
     if (asset == null) throw new Excepcion("No existe ningún Asset con el Id indicado. Póngase en contacto con soporte."); 

     // Declare a new job. 
     IJob job = _context.Jobs.Create("My Thumbnail job"); 

     // Get a media processor reference, and pass to it the name of the 
     // processor to use for the specific task. 
     IMediaProcessor processor = UtilsAzure.GetLatestMediaProcessorByName("Media Encoder Standard", _context); 

     //Configuración para generar el Thumbnail 
     string configThumbnails = @"<Thumbnail Size='50%,*' Type='Jpeg' Filename='{OriginalFilename}_{Size}_{ThumbnailTime}_{ThumbnailIndex}_{Date}_{Time}.{DefaultExtension}'> 
              <Time Value='0:0:0' Step='" + sTime + "'/></Thumbnail>"; 
     //string configThumbnails = "<?xml version='1.0' encoding='UTF-8'?><Thumbnail Size='200,*' Type='Jpeg' JpegQuality='90' Filename='" + sTime + ".jpeg'><Time Value='" + sTime + "'/></Thumbnail>"; 

     ITask task = job.Tasks.AddNew("My thumbnail task", 
      processor, 
      configThumbnails, 
      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); 

     // Use the following event handler to check job progress. 
     job.StateChanged += new 
       EventHandler<JobStateChangedEventArgs>(UtilsAzure.StateChanged); 

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

     // Check job execution and wait for job to finish. 
     Task progressJobTask = 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) 
     { 
      throw new Exception("Exiting method due to job error."); 
     } 

     List<IAssetFile> lAF = job.OutputMediaAssets[0].AssetFiles.ToList(); 

     //Valido 
     if (lAF == null || !lAF.Any()) throw new Excepcion("El trabajo azure no devolvió resultados"); 
     if (lAF.Where(x => x.Name.EndsWith(".jpg")).FirstOrDefault() == null) throw new Excepcion("El trabajo azure no contiene ningún archivo con extensión JPG"); 
     if (!Directory.GetParent(sPath).Exists) throw new Excepcion("No existe la carpeta donde guardar el thumbnail de manera provisional"); 

     lAF.Where(x => x.Name.EndsWith(".jpg")).FirstOrDefault().Download(sPath); 
    } 

답변

0

나에게 보이는 :

An error has occurred. Stage: ParsePreset. Code: System.InvalidOperationException.` 

Microsoft.Cloud.Media.Encoding.PresetException: The XML is invalid or malformed. ---> 
System.InvalidOperationException: There is an error in XML document (1, 2). ---> 
System.InvalidOperationException: <Thumbnail xmlns=''> was not expected.">An error has occurred. Stage: ParsePreset. Code: System.InvalidOperationException. 

Microsoft.Cloud.Media.Encoding.PresetException: The XML is invalid or malformed. ---> 
System.InvalidOperationException: There is an error in XML document (1, 2). ---> 
System.InvalidOperationException: &lt;Thumbnail xmlns=''&gt; was not expected. 

우리의 코드 :

이 하늘빛의 관리 페이지에 표시 오류입니다. 는이 문서에서 Media 인코더 표준 기능에 대한 새로운 사전 설정을 검토하십시오 : https://docs.microsoft.com/en-us/azure/media-services/media-services-advanced-encoding-with-mes#a-idthumbnailsagenerate-thumbnails

는 미리 사전 설정의 새로운 JSON 버전으로 configThumbnails를 교체합니다.

희망 하시겠습니까?

-JD

+0

감사합니다! 작동합니다! 실제로, 하나의 이미지 만 생성하면됩니다. 따라서 XML을 단순화했습니다. – user3809539

0

고마워요! 작동합니다! 실제로, 하나의 이미지 만 생성하면됩니다. 따라서 우리는 XML을 단순화했습니다 :

<?xml version='1.0' encoding='utf-16'?> 
<Preset xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' Version='1.0' xmlns='http://www.windowsazure.com/media/encoding/Preset/2014/03'> 
    <Encoding> 
    <JpgImage Start='00:01:16' Step='00:00:01' Range='00:00:01'> 
     <JpgLayers> 
     <JpgLayer> 
      <Width>640</Width> 
      <Height>360</Height> 
      <Quality>90</Quality> 
     </JpgLayer> 
     </JpgLayers> 
    </JpgImage> 
    </Encoding> 
    <Outputs> 
    <Output FileName='{Basename}_{Index}{Extension}'> 
     <JpgFormat /> 
    </Output> 
    </Outputs> 
</Preset>