Ejemplo n.º 1
0
        /// <summary>
        /// Submits a request to Media Services to apply the specified Transform to a given input video.
        /// </summary>
        /// <param name="client">The Media Services client.</param>
        /// <param name="resourceGroupName">The name of the resource group within the Azure subscription.</param>
        /// <param name="accountName"> The Media Services account name.</param>
        /// <param name="transformName">The name of the transform.</param>
        /// <param name="jobName">The (unique) name of the job.</param>
        /// <param name="inputAssetName"></param>
        /// <param name="outputAssetName">The (unique) name of the  output asset that will store the result of the encoding job. </param>
        private static async Task <Job> SubmitJobAsync(
            IAzureMediaServicesClient client,
            string resourceGroupName,
            string accountName,
            string transformName,
            string jobName,
            string inputAssetName,
            string outputAssetName,
            ClipTime start = null,
            ClipTime end   = null
            )
        {
            JobInput jobInput = new JobInputAsset(assetName: inputAssetName, start: start, end: end);

            JobOutput[] jobOutputs =
            {
                new JobOutputAsset(outputAssetName),
            };

            // In this example, we are assuming that the job name is unique.
            //
            // If you already have a job with the desired name, use the Jobs.Get method
            // to get the existing job. In Media Services v3, Get methods on entities returns null
            // if the entity doesn't exist (a case-insensitive check on the name).
            Job job;

            try
            {
                Console.WriteLine("Creating a job...");
                job = await client.Jobs.CreateAsync(
                    resourceGroupName,
                    accountName,
                    transformName,
                    jobName,
                    new Job
                {
                    Input   = jobInput,
                    Outputs = jobOutputs,
                });
            }
            catch (Exception exception)
            {
                if (exception.GetBaseException() is ApiErrorException apiException)
                {
                    Console.Error.WriteLine(
                        $"ERROR: API call failed with error code '{apiException.Body.Error.Code}' and message '{apiException.Body.Error.Message}'.");
                }
                throw;
            }

            return(job);
        }
Ejemplo n.º 2
0
        private async Task DoSubClipAsync()
        {
            var subclipConfig = this.GetSubclippingInternalConfiguration();

            if (subclipConfig.Reencode) // reencode the clip
            {
                ProcessFromTransform form = new ProcessFromTransform(_amsClientV3, _mainform, _selectedAssets, null, subclipConfig.StartTime, subclipConfig.EndTime, true);

                if (form.ShowDialog() == DialogResult.OK)
                {
                    await _mainform.CreateAndSubmitJobsAsync(new List <Transform>() { form.SelectedTransform }, _selectedAssets, form.StartClipTime, form.EndClipTime);
                }

                /*
                 * var processor = Mainform.GetLatestMediaProcessorByName(Constants.AzureMediaEncoderStandard);
                 * EncodingMES form2 = new EncodingMES(_context, new List<IAsset>(), processor.Version, _mainform, subclipConfig, disableOverlay: true)
                 * {
                 *  EncodingLabel = (_selectedAssets.Count > 1) ?
                 *                  string.Format("{0} asset{1} selected. You are going to submit {0} job{1} with 1 task.", _selectedAssets.Count, Program.ReturnS(_selectedAssets.Count), _selectedAssets.Count)
                 *                  :
                 *                  "Asset '" + _selectedAssets.FirstOrDefault().Name + "' will be encoded (1 job with 1 task).",
                 *
                 *  EncodingJobName = "Subclipping with reencoding of " + Constants.NameconvInputasset,
                 *  EncodingOutputAssetName = Constants.NameconvInputasset + "- Subclipped with reencoding",
                 *  EncodingAMEStdPresetJSONFilesUserFolder = Properties.Settings.Default.MESPresetFilesCurrentFolder,
                 *  EncodingAMEStdPresetJSONFilesFolder = Application.StartupPath + Constants.PathMESFiles,
                 *  SelectedAssets = _selectedAssets
                 * };
                 *
                 * if (form2.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                 * {
                 *  string taskname = "Subclipping with reencoding of " + Constants.NameconvInputasset + " with " + Constants.NameconvEncodername;
                 *  _mainform.LaunchJobs_OneJobPerInputAsset_OneTaskPerfConfig(
                 *     processor,
                 *     _selectedAssets,
                 *     form2.EncodingJobName,
                 *     form2.JobOptions.Priority,
                 *     taskname,
                 *     form2.EncodingOutputAssetName,
                 *     new List<string>() { form2.EncodingConfiguration },
                 *     form2.JobOptions.OutputAssetsCreationOptions,
                 *     form2.JobOptions.OutputAssetsFormatOption,
                 *     form2.JobOptions.TasksOptionsSetting,
                 *     form2.JobOptions.StorageSelected);
                 * }
                 */
            }
            else if (subclipConfig.CreateAssetFilter) // create a asset filter
            {
                Asset             selasset = _selectedAssets.FirstOrDefault();
                DynManifestFilter formAF   = new DynManifestFilter(_amsClientV3, null, selasset, subclipConfig);
                if (formAF.ShowDialog() == DialogResult.OK)
                {
                    FilterCreationInfo filterinfo = null;
                    try
                    {
                        filterinfo = formAF.GetFilterInfo;
                        AssetFilter assetFilter = new AssetFilter()
                        {
                            PresentationTimeRange = filterinfo.Presentationtimerange
                        };

                        await _amsClientV3.AMSclient.AssetFilters.CreateOrUpdateAsync(_amsClientV3.credentialsEntry.ResourceGroup, _amsClientV3.credentialsEntry.AccountName, selasset.Name, filterinfo.Name, assetFilter);

                        _mainform.TextBoxLogWriteLine("Asset filter '{0}' created.", filterinfo.Name);
                    }
                    catch (Exception ex)
                    {
                        _mainform.TextBoxLogWriteLine("Error when creating filter '{0}'.", (filterinfo != null && filterinfo.Name != null) ? filterinfo.Name : "unknown name", true);
                        _mainform.TextBoxLogWriteLine(ex);
                    }

                    await _mainform.DoRefreshGridFiltersVAsync(false);
                }
            }
            else // no reencode or asset filter but stream copy
            {
                ClipTime startTime = null;
                ClipTime endTime   = null;

                if (checkBoxTrimming.Checked)
                {
                    startTime = new AbsoluteClipTime()
                    {
                        Time = subclipConfig.StartTime
                    };

                    endTime = new AbsoluteClipTime()
                    {
                        Time = subclipConfig.EndTime
                    };
                }

                var transform = await _mainform.CreateAndGetCopyCodecTransformIfNeededAsync();

                await _mainform.CreateAndSubmitJobsAsync(new List <Transform>() { transform }, _selectedAssets, startTime, endTime, EncodingJobName, EncodingOutputAssetName);

                MessageBox.Show("Subclipping job(s) submitted", "Sublipping", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            GenerateUniqueNamesForJobAndOutput();
        }