Question

I'm writing code to bulk encode media with Azure media services. The process works fine, however I also need to track the source and output assets in my SQL database during the process so I can reference the original media (stored in blob) and the new output asset ID.

When I ingest the blob media item and encode it, a new IAsset.ID is assigned by the encoder to the newly encoded out asset. However this does not seem to get assigned to the output asset until the job is submitted to the encoder.

How can I obtain the output asset.id before the job is submitted to the encoder? or How can I safely obtain the asset.id of the encoded asset programatically? (I know how to get the assets out the Azure, but I need to tie up source and output media so making sure I get the correct output asset is important)

I'm using WCF, if it makes a difference.

Current method below

/// <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();         

        }
Was it helpful?

Solution

the encoded asset retains a link to it's source, this is the 'Parent' property.

I can make the link between the new encoded asset and it's parent using this method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top