尝试在 Azure 媒体服务中上传、转换/编码和准备 .3gp 视频文件时,我们收到错误消息,File type or codec not supported.
根据此信息,应支持导入 3gp。如何正确导入 3gp 并将其转换为 MP4?
这是我们的内部日志所说的:
The job stopped due to cancellation or an error.
Job ID: nb:jid:UUID:6dc360df-de54-eb45-ae0d-bdc3d2c810fe
Job Name: Encoding and Packaging for dedf426e0b5b41199e8a111f27744890
Job State: Error
Error Details:
Task Id: nb:tid:UUID:12424cbb-0013-4685-8e6b-b224d99db186
Error Code: UserInput
Error Message: File type or codec not supported.
我们的代码:
/// <summary>
/// This method performs all processing necessary to the media in question. This method will wait while processing is completed.
/// </summary>
/// <param name="fileName">Unique file name with extension</param>
/// <returns>IsSuccess</returns>
public bool ProcessMedia(string fileName)
{
var mediaCloud = GetCloudMediaContext();
string assetName = GetAssetNameFromFileName(fileName);
var asset = mediaCloud.Assets.Where(a => a.Name == assetName).SingleOrDefault();
IJob job = mediaCloud.Jobs.Create("Encoding and Packaging for " + asset.Name);
var encoder = GetMediaProcessor(_mediaProcessorNameMap[MediaProcessors.WindowsAzureMediaEncoder]);
/* Firing off a chain of encoding jobs
* 1) Original Encoding -> MP4 (Direct download stream)
* 2) MP4 -> IIS Smooth Streaming (Microsoft Silverlight)
* 3) IIS -> HLS (Apple and IOS) */
//MP4
var mp4Task = job.Tasks.AddNew(String.Format("MP4 Encoding for {0}", asset.Name), encoder, "H264 Broadband 720p", TaskOptions.None);
mp4Task.InputAssets.Add(asset);
var mp4Asset = mp4Task.OutputAssets.AddNew(String.Format(MP4_ASSET_NAME_FORMAT, asset.Name), AssetCreationOptions.None);
//Generate thumbnails from MP4
foreach (ThumbnailTypes thumbnailType in Enum.GetValues(typeof(ThumbnailTypes)))
{
var thumbnailTask = job.Tasks.AddNew(String.Format("Thumbnail Generation for {0}", asset.Name), encoder,
String.Format(TASK_THUMBNAIL_GENERATION_FORMAT, thumbnailType, ImageProcessor.ThumbnailSizes[thumbnailType].Height),
TaskOptions.None);
thumbnailTask.InputAssets.Add(mp4Asset);
var thumnailAsset = thumbnailTask.OutputAssets.AddNew(String.Format(THUMBNAIL_ASSET_NAME_FORMAT, thumbnailType, asset.Name), AssetCreationOptions.None);
}
//IIS
var encodingTask = job.Tasks.AddNew(String.Format("IIS Encoding for {0}", asset.Name), encoder, "H264 Smooth Streaming 720p", TaskOptions.None);
encodingTask.InputAssets.Add(mp4Asset);
var ssOutput = encodingTask.OutputAssets.AddNew(String.Format(IIS_ASSET_NAME_FORMAT, asset.Name), AssetCreationOptions.None);
//HLS
var packager = GetMediaProcessor(_mediaProcessorNameMap[MediaProcessors.WindowsAzureMediaPackager]);
var conversionTask = job.Tasks.AddNew(String.Format("HLS Packaging for {0}", asset.Name), packager, TASK_MSMOOTH_TO_HLS, TaskOptions.None);
conversionTask.InputAssets.Add(ssOutput);
conversionTask.OutputAssets.AddNew(String.Format(HLS_ASSET_NAME_FORMAT, asset.Name), AssetCreationOptions.None);
if (job.Tasks.Count() == 0) //no processing was required
return true;
job.StateChanged += new EventHandler<JobStateChangedEventArgs>(StateChanged);
job.Submit();
// Check job execution and wait for job to finish.
Task progressJobTask = job.GetExecutionProgressTask(CancellationToken.None);
progressJobTask.Wait();
return job.State == JobState.Finished;
}