Les traductions sont fournies par des outils de traduction automatique. En cas de conflit entre le contenu d'une traduction et celui de la version originale en anglais, la version anglaise prévaudra.
MediaConvert exemples utilisant AWS SDK for .NET
Les exemples de code suivants vous montrent comment effectuer des actions et implémenter des scénarios courants à l'aide du AWS SDK for .NET with MediaConvert.
Les actions sont des extraits de code de programmes plus larges et doivent être exécutées dans leur contexte. Les actions vous indiquent comment appeler des fonctions de service individuelles, mais vous pouvez les visualiser dans leur contexte dans les scénarios correspondants.
Chaque exemple inclut un lien vers le code source complet, où vous trouverez des instructions sur la façon de configurer et d'exécuter le code en contexte.
Mise en route
L'exemple de code suivant montre comment commencer à utiliser AWS Elemental MediaConvert.
- AWS SDK for .NET
-
Note
Il y en a plus à ce sujet GitHub. Trouvez l’exemple complet et découvrez comment le configurer et l’exécuter dans le référentiel d’exemples de code AWS
. using Amazon.MediaConvert; using Amazon.MediaConvert.Model; namespace MediaConvertActions; public static class HelloMediaConvert { static async Task Main(string[] args) { // Create the client using the default profile. var mediaConvertClient = new AmazonMediaConvertClient(); Console.WriteLine($"Hello AWS Elemental MediaConvert! Your MediaConvert Jobs are:"); Console.WriteLine(); // You can use await and any of the async methods to get a response. // Let's get some MediaConvert jobs. var response = await mediaConvertClient.ListJobsAsync( new ListJobsRequest() { MaxResults = 10 } ); foreach (var job in response.Jobs) { Console.WriteLine($"\tJob: {job.Id} status {job.Status}"); Console.WriteLine(); } } }
-
Pour API plus de détails, voir DescribeEndpointsla section AWS SDK for .NET APIRéférence.
-
Rubriques
Actions
L'exemple de code suivant montre comment utiliserCreateJob
.
- AWS SDK for .NET
-
Note
Il y en a plus à ce sujet GitHub. Trouvez l’exemple complet et découvrez comment le configurer et l’exécuter dans le référentiel d’exemples de code AWS
. Configurez les emplacements des fichiers, le client et le wrapper.
// MediaConvert role Amazon Resource Name (ARN). // For information on creating this role, see // https://docs.aws.amazon.com/mediaconvert/latest/ug/creating-the-iam-role-in-mediaconvert-configured.html. var mediaConvertRole = _configuration["mediaConvertRoleARN"]; // Include the file input and output locations in settings.json or settings.local.json. var fileInput = _configuration["fileInput"]; var fileOutput = _configuration["fileOutput"]; AmazonMediaConvertClient mcClient = new AmazonMediaConvertClient(); var wrapper = new MediaConvertWrapper(mcClient);
Console.WriteLine(new string('-', 80)); Console.WriteLine($"Creating job for input file {fileInput}."); var jobId = await wrapper.CreateJob(mediaConvertRole!, fileInput!, fileOutput!); Console.WriteLine($"Created job with Job ID: {jobId}"); Console.WriteLine(new string('-', 80));
Créez la tâche à l'aide de la méthode wrapper et renvoyez l'ID de la tâche.
/// <summary> /// Create a job to convert a media file. /// </summary> /// <param name="mediaConvertRole">The Amazon Resource Name (ARN) of the media convert role, as specified here: /// https://docs.aws.amazon.com/mediaconvert/latest/ug/creating-the-iam-role-in-mediaconvert-configured.html</param> /// <param name="fileInput">The Amazon Simple Storage Service (Amazon S3) location of the input media file.</param> /// <param name="fileOutput">The Amazon S3 location for the output media file.</param> /// <returns>The ID of the new job.</returns> public async Task<string> CreateJob(string mediaConvertRole, string fileInput, string fileOutput) { CreateJobRequest createJobRequest = new CreateJobRequest { Role = mediaConvertRole }; createJobRequest.UserMetadata.Add("Customer", "Amazon"); JobSettings jobSettings = new JobSettings { AdAvailOffset = 0, TimecodeConfig = new TimecodeConfig { Source = TimecodeSource.EMBEDDED } }; createJobRequest.Settings = jobSettings; #region OutputGroup OutputGroup ofg = new OutputGroup { Name = "File Group", OutputGroupSettings = new OutputGroupSettings { Type = OutputGroupType.FILE_GROUP_SETTINGS, FileGroupSettings = new FileGroupSettings { Destination = fileOutput } } }; Output output = new Output { NameModifier = "_1" }; #region VideoDescription VideoDescription vdes = new VideoDescription { ScalingBehavior = ScalingBehavior.DEFAULT, TimecodeInsertion = VideoTimecodeInsertion.DISABLED, AntiAlias = AntiAlias.ENABLED, Sharpness = 50, AfdSignaling = AfdSignaling.NONE, DropFrameTimecode = DropFrameTimecode.ENABLED, RespondToAfd = RespondToAfd.NONE, ColorMetadata = ColorMetadata.INSERT, CodecSettings = new VideoCodecSettings { Codec = VideoCodec.H_264 } }; output.VideoDescription = vdes; H264Settings h264 = new H264Settings { InterlaceMode = H264InterlaceMode.PROGRESSIVE, NumberReferenceFrames = 3, Syntax = H264Syntax.DEFAULT, Softness = 0, GopClosedCadence = 1, GopSize = 90, Slices = 1, GopBReference = H264GopBReference.DISABLED, SlowPal = H264SlowPal.DISABLED, SpatialAdaptiveQuantization = H264SpatialAdaptiveQuantization.ENABLED, TemporalAdaptiveQuantization = H264TemporalAdaptiveQuantization.ENABLED, FlickerAdaptiveQuantization = H264FlickerAdaptiveQuantization.DISABLED, EntropyEncoding = H264EntropyEncoding.CABAC, Bitrate = 5000000, FramerateControl = H264FramerateControl.SPECIFIED, RateControlMode = H264RateControlMode.CBR, CodecProfile = H264CodecProfile.MAIN, Telecine = H264Telecine.NONE, MinIInterval = 0, AdaptiveQuantization = H264AdaptiveQuantization.HIGH, CodecLevel = H264CodecLevel.AUTO, FieldEncoding = H264FieldEncoding.PAFF, SceneChangeDetect = H264SceneChangeDetect.ENABLED, QualityTuningLevel = H264QualityTuningLevel.SINGLE_PASS, FramerateConversionAlgorithm = H264FramerateConversionAlgorithm.DUPLICATE_DROP, UnregisteredSeiTimecode = H264UnregisteredSeiTimecode.DISABLED, GopSizeUnits = H264GopSizeUnits.FRAMES, ParControl = H264ParControl.SPECIFIED, NumberBFramesBetweenReferenceFrames = 2, RepeatPps = H264RepeatPps.DISABLED, FramerateNumerator = 30, FramerateDenominator = 1, ParNumerator = 1, ParDenominator = 1 }; output.VideoDescription.CodecSettings.H264Settings = h264; #endregion VideoDescription #region AudioDescription AudioDescription ades = new AudioDescription { LanguageCodeControl = AudioLanguageCodeControl.FOLLOW_INPUT, // This name matches one specified in the following Inputs. AudioSourceName = "Audio Selector 1", CodecSettings = new AudioCodecSettings { Codec = AudioCodec.AAC } }; AacSettings aac = new AacSettings { AudioDescriptionBroadcasterMix = AacAudioDescriptionBroadcasterMix.NORMAL, RateControlMode = AacRateControlMode.CBR, CodecProfile = AacCodecProfile.LC, CodingMode = AacCodingMode.CODING_MODE_2_0, RawFormat = AacRawFormat.NONE, SampleRate = 48000, Specification = AacSpecification.MPEG4, Bitrate = 64000 }; ades.CodecSettings.AacSettings = aac; output.AudioDescriptions.Add(ades); #endregion AudioDescription #region Mp4 Container output.ContainerSettings = new ContainerSettings { Container = ContainerType.MP4 }; Mp4Settings mp4 = new Mp4Settings { CslgAtom = Mp4CslgAtom.INCLUDE, FreeSpaceBox = Mp4FreeSpaceBox.EXCLUDE, MoovPlacement = Mp4MoovPlacement.PROGRESSIVE_DOWNLOAD }; output.ContainerSettings.Mp4Settings = mp4; #endregion Mp4 Container ofg.Outputs.Add(output); createJobRequest.Settings.OutputGroups.Add(ofg); #endregion OutputGroup #region Input Input input = new Input { FilterEnable = InputFilterEnable.AUTO, PsiControl = InputPsiControl.USE_PSI, FilterStrength = 0, DeblockFilter = InputDeblockFilter.DISABLED, DenoiseFilter = InputDenoiseFilter.DISABLED, TimecodeSource = InputTimecodeSource.EMBEDDED, FileInput = fileInput }; AudioSelector audsel = new AudioSelector { Offset = 0, DefaultSelection = AudioDefaultSelection.NOT_DEFAULT, ProgramSelection = 1, SelectorType = AudioSelectorType.TRACK }; audsel.Tracks.Add(1); input.AudioSelectors.Add("Audio Selector 1", audsel); input.VideoSelector = new VideoSelector { ColorSpace = ColorSpace.FOLLOW }; createJobRequest.Settings.Inputs.Add(input); #endregion Input CreateJobResponse createJobResponse = await _amazonMediaConvert.CreateJobAsync(createJobRequest); var jobId = createJobResponse.Job.Id; return jobId; }
-
Pour API plus de détails, voir CreateJobla section AWS SDK for .NET APIRéférence.
-
L'exemple de code suivant montre comment utiliserGetJob
.
- AWS SDK for .NET
-
Note
Il y en a plus à ce sujet GitHub. Trouvez l’exemple complet et découvrez comment le configurer et l’exécuter dans le référentiel d’exemples de code AWS
. Configurez les emplacements des fichiers, le client et le wrapper.
// MediaConvert role Amazon Resource Name (ARN). // For information on creating this role, see // https://docs.aws.amazon.com/mediaconvert/latest/ug/creating-the-iam-role-in-mediaconvert-configured.html. var mediaConvertRole = _configuration["mediaConvertRoleARN"]; // Include the file input and output locations in settings.json or settings.local.json. var fileInput = _configuration["fileInput"]; var fileOutput = _configuration["fileOutput"]; AmazonMediaConvertClient mcClient = new AmazonMediaConvertClient(); var wrapper = new MediaConvertWrapper(mcClient);
Obtenez un emploi grâce à son identifiant.
Console.WriteLine(new string('-', 80)); Console.WriteLine($"Getting job information for Job ID {jobId}"); var job = await wrapper.GetJobById(jobId); Console.WriteLine($"Job {job.Id} created on {job.CreatedAt:d} has status {job.Status}."); Console.WriteLine(new string('-', 80));
/// <summary> /// Get the job information for a job by its ID. /// </summary> /// <param name="jobId">The ID of the job.</param> /// <returns>The Job object.</returns> public async Task<Job> GetJobById(string jobId) { var jobResponse = await _amazonMediaConvert.GetJobAsync( new GetJobRequest { Id = jobId }); return jobResponse.Job; }
-
Pour API plus de détails, voir GetJobla section AWS SDK for .NET APIRéférence.
-
L'exemple de code suivant montre comment utiliserListJobs
.
- AWS SDK for .NET
-
Note
Il y en a plus à ce sujet GitHub. Trouvez l’exemple complet et découvrez comment le configurer et l’exécuter dans le référentiel d’exemples de code AWS
. Configurez les emplacements des fichiers, le client et le wrapper.
// MediaConvert role Amazon Resource Name (ARN). // For information on creating this role, see // https://docs.aws.amazon.com/mediaconvert/latest/ug/creating-the-iam-role-in-mediaconvert-configured.html. var mediaConvertRole = _configuration["mediaConvertRoleARN"]; // Include the file input and output locations in settings.json or settings.local.json. var fileInput = _configuration["fileInput"]; var fileOutput = _configuration["fileOutput"]; AmazonMediaConvertClient mcClient = new AmazonMediaConvertClient(); var wrapper = new MediaConvertWrapper(mcClient);
Répertoriez les emplois ayant un statut particulier.
Console.WriteLine(new string('-', 80)); Console.WriteLine($"Listing all complete jobs."); var completeJobs = await wrapper.ListAllJobsByStatus(JobStatus.COMPLETE); completeJobs.ForEach(j => { Console.WriteLine($"Job {j.Id} created on {j.CreatedAt:d} has status {j.Status}."); });
Répertoriez les tâches à l'aide d'un paginateur.
/// <summary> /// List all of the jobs with a particular status using a paginator. /// </summary> /// <param name="status">The status to use when listing jobs.</param> /// <returns>The list of jobs matching the status.</returns> public async Task<List<Job>> ListAllJobsByStatus(JobStatus? status = null) { var returnedJobs = new List<Job>(); var paginatedJobs = _amazonMediaConvert.Paginators.ListJobs( new ListJobsRequest { Status = status }); // Get the entire list using the paginator. await foreach (var job in paginatedJobs.Jobs) { returnedJobs.Add(job); } return returnedJobs; }
-
Pour API plus de détails, voir ListJobsla section AWS SDK for .NET APIRéférence.
-