There are more AWS SDK examples available in the AWS Doc SDK Examples
MediaConvert examples using SDK for C++
The following code examples show you how to perform actions and implement common scenarios by using the AWS SDK for C++ with MediaConvert.
Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios.
Each example includes a link to the complete source code, where you can find instructions on how to set up and run the code in context.
Topics
Actions
The following code example shows how to use CreateJob
.
- SDK for C++
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. //! Create an AWS Elemental MediaConvert job. /*! \param mediaConvertRole: An Amazon Resource Name (ARN) for the AWS Identity and Access Management (IAM) role for the job. \param fileInput: A URI to an input file that is stored in Amazon Simple Storage Service (Amazon S3) or on an HTTP(S) server. \param fileOutput: A URI for an Amazon S3 output location and the output file name base. \param jobSettingsFile: An optional JSON settings file. \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::MediaConvert::createJob(const Aws::String &mediaConvertRole, const Aws::String &fileInput, const Aws::String &fileOutput, const Aws::String &jobSettingsFile, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::MediaConvert::Model::CreateJobRequest createJobRequest; createJobRequest.SetRole(mediaConvertRole); Aws::Http::HeaderValueCollection hvc; hvc.emplace("Customer", "Amazon"); createJobRequest.SetUserMetadata(hvc); if (!jobSettingsFile.empty()) // Use a JSON file for the job settings. { std::ifstream jobSettingsStream(jobSettingsFile, std::ios::ate); if (!jobSettingsStream) { std::cerr << "Unable to open the job template file." << std::endl; return false; } std::vector<char> buffer(jobSettingsStream.tellg()); jobSettingsStream.seekg(0); jobSettingsStream.read(buffer.data(), buffer.size()); std::string jobSettingsJSON(buffer.data(), buffer.size()); size_t pos = jobSettingsJSON.find(INPUT_FILE_PLACEHOLDER); if (pos != std::string::npos) { jobSettingsJSON.replace(pos, strlen(INPUT_FILE_PLACEHOLDER), fileInput); } pos = jobSettingsJSON.find(OUTPUT_FILE_PLACEHOLDER); if (pos != std::string::npos) { jobSettingsJSON.replace(pos, strlen(OUTPUT_FILE_PLACEHOLDER), fileOutput); } Aws::Utils::Json::JsonValue jsonValue(jobSettingsJSON); Aws::MediaConvert::Model::JobSettings jobSettings(jsonValue); createJobRequest.SetSettings(jobSettings); } else { // Configure the job settings programmatically. Aws::MediaConvert::Model::JobSettings jobSettings; jobSettings.SetAdAvailOffset(0); Aws::MediaConvert::Model::TimecodeConfig timecodeConfig; timecodeConfig.SetSource(Aws::MediaConvert::Model::TimecodeSource::EMBEDDED); jobSettings.SetTimecodeConfig(timecodeConfig); // Configure the output group. Aws::MediaConvert::Model::OutputGroup outputGroup; outputGroup.SetName("File Group"); Aws::MediaConvert::Model::OutputGroupSettings outputGroupSettings; outputGroupSettings.SetType( Aws::MediaConvert::Model::OutputGroupType::FILE_GROUP_SETTINGS); Aws::MediaConvert::Model::FileGroupSettings fileGroupSettings; fileGroupSettings.SetDestination(fileOutput); outputGroupSettings.SetFileGroupSettings(fileGroupSettings); outputGroup.SetOutputGroupSettings(outputGroupSettings); Aws::MediaConvert::Model::Output output; output.SetNameModifier("_1"); Aws::MediaConvert::Model::VideoDescription videoDescription; videoDescription.SetScalingBehavior( Aws::MediaConvert::Model::ScalingBehavior::DEFAULT); videoDescription.SetTimecodeInsertion( Aws::MediaConvert::Model::VideoTimecodeInsertion::DISABLED); videoDescription.SetAntiAlias(Aws::MediaConvert::Model::AntiAlias::ENABLED); videoDescription.SetSharpness(50); videoDescription.SetAfdSignaling(Aws::MediaConvert::Model::AfdSignaling::NONE); videoDescription.SetDropFrameTimecode( Aws::MediaConvert::Model::DropFrameTimecode::ENABLED); videoDescription.SetRespondToAfd(Aws::MediaConvert::Model::RespondToAfd::NONE); videoDescription.SetColorMetadata( Aws::MediaConvert::Model::ColorMetadata::INSERT); Aws::MediaConvert::Model::VideoCodecSettings videoCodecSettings; videoCodecSettings.SetCodec(Aws::MediaConvert::Model::VideoCodec::H_264); Aws::MediaConvert::Model::H264Settings h264Settings; h264Settings.SetNumberReferenceFrames(3); h264Settings.SetSyntax(Aws::MediaConvert::Model::H264Syntax::DEFAULT); h264Settings.SetSoftness(0); h264Settings.SetGopClosedCadence(1); h264Settings.SetGopSize(90); h264Settings.SetSlices(1); h264Settings.SetGopBReference( Aws::MediaConvert::Model::H264GopBReference::DISABLED); h264Settings.SetSlowPal(Aws::MediaConvert::Model::H264SlowPal::DISABLED); h264Settings.SetSpatialAdaptiveQuantization( Aws::MediaConvert::Model::H264SpatialAdaptiveQuantization::ENABLED); h264Settings.SetTemporalAdaptiveQuantization( Aws::MediaConvert::Model::H264TemporalAdaptiveQuantization::ENABLED); h264Settings.SetFlickerAdaptiveQuantization( Aws::MediaConvert::Model::H264FlickerAdaptiveQuantization::DISABLED); h264Settings.SetEntropyEncoding( Aws::MediaConvert::Model::H264EntropyEncoding::CABAC); h264Settings.SetBitrate(5000000); h264Settings.SetFramerateControl( Aws::MediaConvert::Model::H264FramerateControl::SPECIFIED); h264Settings.SetRateControlMode( Aws::MediaConvert::Model::H264RateControlMode::CBR); h264Settings.SetCodecProfile(Aws::MediaConvert::Model::H264CodecProfile::MAIN); h264Settings.SetTelecine(Aws::MediaConvert::Model::H264Telecine::NONE); h264Settings.SetMinIInterval(0); h264Settings.SetAdaptiveQuantization( Aws::MediaConvert::Model::H264AdaptiveQuantization::HIGH); h264Settings.SetCodecLevel(Aws::MediaConvert::Model::H264CodecLevel::AUTO); h264Settings.SetFieldEncoding( Aws::MediaConvert::Model::H264FieldEncoding::PAFF); h264Settings.SetSceneChangeDetect( Aws::MediaConvert::Model::H264SceneChangeDetect::ENABLED); h264Settings.SetQualityTuningLevel( Aws::MediaConvert::Model::H264QualityTuningLevel::SINGLE_PASS); h264Settings.SetFramerateConversionAlgorithm( Aws::MediaConvert::Model::H264FramerateConversionAlgorithm::DUPLICATE_DROP); h264Settings.SetUnregisteredSeiTimecode( Aws::MediaConvert::Model::H264UnregisteredSeiTimecode::DISABLED); h264Settings.SetGopSizeUnits( Aws::MediaConvert::Model::H264GopSizeUnits::FRAMES); h264Settings.SetParControl(Aws::MediaConvert::Model::H264ParControl::SPECIFIED); h264Settings.SetNumberBFramesBetweenReferenceFrames(2); h264Settings.SetRepeatPps(Aws::MediaConvert::Model::H264RepeatPps::DISABLED); h264Settings.SetFramerateNumerator(30); h264Settings.SetFramerateDenominator(1); h264Settings.SetParNumerator(1); h264Settings.SetParDenominator(1); videoCodecSettings.SetH264Settings(h264Settings); videoDescription.SetCodecSettings(videoCodecSettings); output.SetVideoDescription(videoDescription); Aws::MediaConvert::Model::AudioDescription audioDescription; audioDescription.SetLanguageCodeControl( Aws::MediaConvert::Model::AudioLanguageCodeControl::FOLLOW_INPUT); audioDescription.SetAudioSourceName(AUDIO_SOURCE_NAME); Aws::MediaConvert::Model::AudioCodecSettings audioCodecSettings; audioCodecSettings.SetCodec(Aws::MediaConvert::Model::AudioCodec::AAC); Aws::MediaConvert::Model::AacSettings aacSettings; aacSettings.SetAudioDescriptionBroadcasterMix( Aws::MediaConvert::Model::AacAudioDescriptionBroadcasterMix::NORMAL); aacSettings.SetRateControlMode( Aws::MediaConvert::Model::AacRateControlMode::CBR); aacSettings.SetCodecProfile(Aws::MediaConvert::Model::AacCodecProfile::LC); aacSettings.SetCodingMode( Aws::MediaConvert::Model::AacCodingMode::CODING_MODE_2_0); aacSettings.SetRawFormat(Aws::MediaConvert::Model::AacRawFormat::NONE); aacSettings.SetSampleRate(48000); aacSettings.SetSpecification(Aws::MediaConvert::Model::AacSpecification::MPEG4); aacSettings.SetBitrate(64000); audioCodecSettings.SetAacSettings(aacSettings); audioDescription.SetCodecSettings(audioCodecSettings); Aws::Vector<Aws::MediaConvert::Model::AudioDescription> audioDescriptions; audioDescriptions.emplace_back(audioDescription); output.SetAudioDescriptions(audioDescriptions); Aws::MediaConvert::Model::ContainerSettings mp4container; mp4container.SetContainer(Aws::MediaConvert::Model::ContainerType::MP4); Aws::MediaConvert::Model::Mp4Settings mp4Settings; mp4Settings.SetCslgAtom(Aws::MediaConvert::Model::Mp4CslgAtom::INCLUDE); mp4Settings.SetFreeSpaceBox(Aws::MediaConvert::Model::Mp4FreeSpaceBox::EXCLUDE); mp4Settings.SetMoovPlacement( Aws::MediaConvert::Model::Mp4MoovPlacement::PROGRESSIVE_DOWNLOAD); mp4container.SetMp4Settings(mp4Settings); output.SetContainerSettings(mp4container); outputGroup.AddOutputs(output); jobSettings.AddOutputGroups(outputGroup); // Configure inputs. Aws::MediaConvert::Model::Input input; input.SetFilterEnable(Aws::MediaConvert::Model::InputFilterEnable::AUTO); input.SetPsiControl(Aws::MediaConvert::Model::InputPsiControl::USE_PSI); input.SetFilterStrength(0); input.SetDeblockFilter(Aws::MediaConvert::Model::InputDeblockFilter::DISABLED); input.SetDenoiseFilter(Aws::MediaConvert::Model::InputDenoiseFilter::DISABLED); input.SetTimecodeSource( Aws::MediaConvert::Model::InputTimecodeSource::EMBEDDED); input.SetFileInput(fileInput); Aws::MediaConvert::Model::AudioSelector audioSelector; audioSelector.SetOffset(0); audioSelector.SetDefaultSelection( Aws::MediaConvert::Model::AudioDefaultSelection::NOT_DEFAULT); audioSelector.SetProgramSelection(1); audioSelector.SetSelectorType( Aws::MediaConvert::Model::AudioSelectorType::TRACK); audioSelector.AddTracks(1); input.AddAudioSelectors(AUDIO_SOURCE_NAME, audioSelector); Aws::MediaConvert::Model::VideoSelector videoSelector; videoSelector.SetColorSpace(Aws::MediaConvert::Model::ColorSpace::FOLLOW); input.SetVideoSelector(videoSelector); jobSettings.AddInputs(input); createJobRequest.SetSettings(jobSettings); } Aws::MediaConvert::MediaConvertClient client(clientConfiguration); Aws::MediaConvert::Model::CreateJobOutcome outcome = client.CreateJob( createJobRequest); if (outcome.IsSuccess()) { std::cout << "Job successfully created with ID - " << outcome.GetResult().GetJob().GetId() << std::endl; } else { std::cerr << "Error CreateJob - " << outcome.GetError().GetMessage() << std::endl; } return outcome.IsSuccess(); }
-
For API details, see CreateJob in AWS SDK for C++ API Reference.
-
The following code example shows how to use GetJob
.
- SDK for C++
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. //! Retrieve the information for a specific completed transcoding job. /*! \param jobID: A job ID. \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::MediaConvert::getJob(const Aws::String &jobID, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::MediaConvert::MediaConvertClient client(clientConfiguration); Aws::MediaConvert::Model::GetJobRequest request; request.SetId(jobID); const Aws::MediaConvert::Model::GetJobOutcome outcome = client.GetJob( request); if (outcome.IsSuccess()) { std::cout << outcome.GetResult().GetJob().Jsonize().View().WriteReadable() << std::endl; } else { std::cerr << "DescribeEndpoints error - " << outcome.GetError().GetMessage() << std::endl; } return outcome.IsSuccess(); }
-
For API details, see GetJob in AWS SDK for C++ API Reference.
-
The following code example shows how to use ListJobs
.
- SDK for C++
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. //! Retrieve a list of created jobs. /*! \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::MediaConvert::listJobs( const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::MediaConvert::MediaConvertClient client(clientConfiguration); bool result = true; Aws::String nextToken; // Used to handle paginated results. do { Aws::MediaConvert::Model::ListJobsRequest request; if (!nextToken.empty()) { request.SetNextToken(nextToken); } const Aws::MediaConvert::Model::ListJobsOutcome outcome = client.ListJobs( request); if (outcome.IsSuccess()) { const Aws::Vector<Aws::MediaConvert::Model::Job> &jobs = outcome.GetResult().GetJobs(); std::cout << jobs.size() << " jobs retrieved." << std::endl; for (const Aws::MediaConvert::Model::Job &job: jobs) { std::cout << " " << job.Jsonize().View().WriteReadable() << std::endl; } nextToken = outcome.GetResult().GetNextToken(); } else { std::cerr << "DescribeEndpoints error - " << outcome.GetError().GetMessage() << std::endl; result = false; break; } } while (!nextToken.empty()); return result; }
-
For API details, see ListJobs in AWS SDK for C++ API Reference.
-