MediaConvert 用SDK于 C++ 的示例 - AWS SDK代码示例

AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

MediaConvert 用SDK于 C++ 的示例

以下代码示例向您展示了如何使用with来执行操作和实现常见场景 MediaConvert。 AWS SDK for C++

操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景的上下文查看操作。

每个示例都包含一个指向完整源代码的链接,您可以在其中找到有关如何在上下文中设置和运行代码的说明。

主题

操作

以下代码示例演示如何使用 CreateJob

SDK对于 C++
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库中进行设置和运行。

//! 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(); }
  • 有关API详细信息,请参阅 “AWS SDK for C++ API参考 CreateJob” 中的。

以下代码示例演示如何使用 GetJob

SDK对于 C++
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库中进行设置和运行。

//! 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(); }
  • 有关API详细信息,请参阅 “AWS SDK for C++ API参考 GetJob” 中的。

以下代码示例演示如何使用 ListJobs

SDK对于 C++
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库中进行设置和运行。

//! 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; }
  • 有关API详细信息,请参阅 “AWS SDK for C++ API参考 ListJobs” 中的。