public ActionResult RunIndexingJob(string assetId) { // Create an asset and upload the input media file to storage. IAsset asset = GetAssetById(assetId); // Declare a new job. IJob job = context.Jobs.Create("My Indexing Job"); // Get a reference to Azure Media Indexer 2 Preview. string MediaProcessorName = "Azure Media Indexer 2 Preview"; var processor = GetLatestMediaProcessorByName(MediaProcessorName); // Read configuration from the specified file. string configuration = System.IO.File.ReadAllText(HttpContext.Server.MapPath("~/config.json")); // Create a task with the encoding details, using a string preset. ITask task = job.Tasks.AddNew("My Indexing Task", processor, configuration, TaskOptions.None); // Specify the input asset to be indexed. task.InputAssets.Add(asset); // Add an output asset to contain the results of the job. task.OutputAssets.AddNew("My Indexing Output Asset", AssetCreationOptions.None); // Launch the job. job.Submit(); // Check job execution and wait for job to finish. //Task progressJobTask = job.GetExecutionProgressTask(CancellationToken.None); //progressJobTask.Wait(); Session["indexingMediaAssets"] = job.OutputMediaAssets[0]; //return job.OutputMediaAssets[0]; return(Json(new { message = "Indexing Job Submitted", assetId = assetId, jobId = job.Id })); }
public ActionResult EncodeToAdaptiveBitrateMP4s(string assetId) { // Note: You need atleast 1 reserve streaming unit for dynamic packaging of encoded media. If you don't have that, you can't see video file playing. IAsset inputAsset = GetAssetById(assetId); string token = string.Empty; string uploadFileOriginalName = string.Empty; string fileName = string.Empty; ////// Without preset (say default preset), works very well //IJob job = context.Jobs.CreateWithSingleTask(MediaProcessorNames.AzureMediaEncoder, // MediaEncoderTaskPresetStrings.H264AdaptiveBitrateMP4Set720p, // inputAsset, // "UploadedVideo-" + Guid.NewGuid().ToString().ToLower() + "-Adaptive-Bitrate-MP4", // AssetCreationOptions.None); //job.Submit(); //IAsset encodedOutputAsset = job.OutputMediaAssets[0]; //// XML Preset IJob job = context.Jobs.Create(inputAsset.Name); if (inputAsset.AssetType.ToString() == "Video") { IMediaProcessor processor = GetLatestMediaProcessorByName("Media Encoder Standard"); string configuration = System.IO.File.ReadAllText(HttpContext.Server.MapPath("~/MediaServicesCustomPreset.xml")); ITask task = job.Tasks.AddNew(inputAsset.Name + "- encoding task", processor, configuration, TaskOptions.None); task.InputAssets.Add(inputAsset); task.OutputAssets.AddNew(inputAsset.Name + "-Adaptive-Bitrate-MP4", AssetCreationOptions.None); } else if (true) { IMediaProcessor processor = GetLatestMediaProcessorByName("Media Encoder Standard"); string configuration = System.IO.File.ReadAllText(HttpContext.Server.MapPath("~/MediaServicesCustomPreset.xml")); ITask task = job.Tasks.AddNew("Media Encoder Standard encoding task", processor, "Adaptive Streaming", TaskOptions.None); //ITask task = job.Tasks.AddNew("My encoding task", processor, configuration, TaskOptions.None); task.InputAssets.Add(inputAsset); task.OutputAssets.AddNew(inputAsset.Name + "-Adaptive-Bitrate-MP4", AssetCreationOptions.None); } job.Submit(); //Task progressJobTask = job.GetExecutionProgressTask(CancellationToken.None); //progressJobTask.Wait(); IAsset encodedAsset = job.OutputMediaAssets[0]; // process policy & encryption ProcessPolicyAndEncryption(encodedAsset); // Get file name string fileSession = "CurrentFile"; if (Session[fileSession] != null) { CloudFile model = (CloudFile)Session[fileSession]; uploadFileOriginalName = model.OriginalName; fileName = model.FileName; } // Generate Streaming URL string smoothStreamingUri = GetStreamingOriginLocator(encodedAsset, fileName); // add jobid and output asset id in database var video = new Video(); video.AssetId = assetId; video.EncodingJobId = job.Id; video.EncodedAssetId = encodedAsset.Id; video.LocatorUri = smoothStreamingUri; video.IsEncrypted = useAESRestriction; video.IndexedAssetId = ((IAsset)Session["indexingMediaAssets"]).Id; video.AssetFileName = uploadFileOriginalName; video.text = Session["textParsed"].ToString(); var videoformatlist = new List <string> { ".mp4", ".avi", ".mkv", ".flv", ".wmv" }; var audioformatlist = new List <string> { ".wav", ".mp3", ".aac" }; var format = uploadFileOriginalName.Substring(uploadFileOriginalName.Length - 4); if (videoformatlist.Contains(format)) { video.filetype = "video"; } else if (audioformatlist.Contains(format)) { video.filetype = "audio"; } else { video.filetype = "other"; } // Repository dal = new Repository(); //var result = dal.SaveVideo(video); SaveVideoListtoJson(video); if (useAESRestriction) { token = AzureMediaAsset.GetTestToken(encodedAsset.Id, encodedAsset); } // Remove session Session.Remove("CurrentFile"); Session.Clear(); // return success response return(Json(new { error = false, message = "Congratulations! Video is uploaded and pipelined for encoding, check console log for after encoding playback details.", assetId = assetId, jobId = job.Id, locator = smoothStreamingUri, encrypted = useAESRestriction, token = token })); }