我正在编写代码以使用 Azure 媒体服务对媒体进行批量编码。该过程运行良好,但是我还需要在此过程中跟踪我的 SQL 数据库中的源和输出资产,以便我可以引用原始媒体(存储在 blob 中)和新的输出资产 ID。
当我摄取 blob 媒体项并对其进行编码时,编码器会将新的 IAsset.ID 分配给新编码的输出资产。但是,在将作业提交给编码器之前,这似乎不会分配给输出资产。
如何在作业提交给编码器之前获取输出的asset.id?或如何以编程方式安全地获取编码资产的asset.id?(我知道如何将资产从 Azure 中取出,但我需要绑定源和输出媒体,因此确保获得正确的输出资产很重要)
我正在使用 WCF,如果它有所作为的话。
当前方法如下
/// <summary>
/// Encodes the asset from media storge.
/// </summary>
/// <param name="encodeTaskListSubmit">The encode task list.</param>
private List<List<EncodeInputTask>> ListofEncoderTasks;
public void EncodeAssetFromMediaStorge(List<EncodeInputTask> encodeTaskListSubmit)
{
var encodeTaskList = encodeTaskListSubmit;
//check list contents
int i = 0;
foreach (var encodeTask in encodeTaskList)
{
var assetIdCheckAgainstAzureAssets = _context.Assets.Where(x => x.Id == encodeTask.Asset.Id).FirstOrDefault();
if (assetIdCheckAgainstAzureAssets == null)
{
encodeTaskList.RemoveAt(i);
}
i++;
}
var h264SmoothStreaming1080P =
encodeTaskList.Where(
x => x.EncodePreset == MediaServices.EncodePresetsForSmoothStreaming.H264SmoothStreaming1080P)
.ToList();
var h264SmoothStreaming720P =
encodeTaskList.Where(
x => x.EncodePreset == MediaServices.EncodePresetsForSmoothStreaming.H264SmoothStreaming720P)
.ToList();
var h264SmoothStreaming720Pfor3Gor4G =
encodeTaskList.Where(
x => x.EncodePreset == MediaServices.EncodePresetsForSmoothStreaming.H264SmoothStreaming720Pfor3Gor4G)
.ToList();
var h264SmoothStreamingSd16X9 =
encodeTaskList.Where(
x => x.EncodePreset == MediaServices.EncodePresetsForSmoothStreaming.H264SmoothStreamingSd16X9)
.ToList();
var h264SmoothStreamingSd4X3 =
encodeTaskList.Where(
x => x.EncodePreset == MediaServices.EncodePresetsForSmoothStreaming.H264SmoothStreamingSd4X3)
.ToList();
//create new encoder job reference
IJob encoderJobs = _context.Jobs.Create("Job " + DateTime.Now + " " + Guid.NewGuid().ToString());
var processor = GetLatestMediaProcessorByName("Windows Azure Media Encoder");
ListofEncoderTasks = new List<List<EncodeInputTask>>
{
h264SmoothStreaming1080P,
h264SmoothStreaming720P,
h264SmoothStreaming720Pfor3Gor4G,
h264SmoothStreamingSd16X9,
h264SmoothStreamingSd4X3
};
foreach (List<EncodeInputTask> encodeTasks in ListofEncoderTasks)
{
foreach (EncodeInputTask encodeTask in encodeTasks)
{
var encodePreset = Global.Common.GetEnumDescription(encodeTask.EncodePreset);
ITask task = encoderJobs.Tasks.AddNew("Task " + DateTime.Now + Guid.NewGuid(), processor, encodePreset, TaskOptions.ProtectedConfiguration);
task.InputAssets.Add(encodeTask.Asset);
string outputAssetName = encodeTask.Asset.Name + " " + encodePreset;
task.OutputAssets.AddNew(outputAssetName + " " + encodePreset, AssetCreationOptions.None);
encodeTask.Asset.Name = outputAssetName;
DatabaseAction.UpdateMediaItemState(encodeTask.Asset.Id, true, MediaServices.InternalAssetState.Encoding);
}
}
DatabaseAction.EncodeJobRegistry(encoderJobs.Name,true,ListofEncoderTasks);
DatabaseAction.RegisterSourceAssetInEncodedTable(ListofEncoderTasks);
encoderJobs.Submit();
}