我正在使用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();
}
答案 0 :(得分:1)
编码资产保留了与其来源的链接,这是“父”属性。
我可以使用此方法在新编码资产与其父级之间建立链接。