examples: Move to the new, simplified encoding profile API

This commit is contained in:
Sebastian Dröge 2021-10-24 18:45:38 +03:00
parent 984ab87c79
commit 8cc018c164
2 changed files with 29 additions and 33 deletions

View file

@ -48,38 +48,37 @@ struct ErrorMessage {
#[gboxed(type_name = "ErrorValue")] #[gboxed(type_name = "ErrorValue")]
struct ErrorValue(Arc<Mutex<Option<Error>>>); struct ErrorValue(Arc<Mutex<Option<Error>>>);
fn configure_encodebin(encodebin: &gst::Element) -> Result<(), Error> { fn configure_encodebin(encodebin: &gst::Element) {
// To tell the encodebin what we want it to produce, we create an EncodingProfile // To tell the encodebin what we want it to produce, we create an EncodingProfile
// https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-base-libs/html/GstEncodingProfile.html // https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-base-libs/html/GstEncodingProfile.html
// This profile consists of information about the contained audio and video formats // This profile consists of information about the contained audio and video formats
// as well as the container format we want everything to be combined into. // as well as the container format we want everything to be combined into.
// Every audiostream piped into the encodebin should be encoded using vorbis. // Every audiostream piped into the encodebin should be encoded using vorbis.
let audio_profile = gst_pbutils::EncodingAudioProfileBuilder::new() let audio_profile =
.format(&gst::Caps::new_simple("audio/x-vorbis", &[])) gst_pbutils::EncodingAudioProfile::builder(&gst::Caps::builder("audio/x-vorbis").build())
.presence(0) .presence(0)
.build()?; .build();
// Every videostream piped into the encodebin should be encoded using theora. // Every videostream piped into the encodebin should be encoded using theora.
let video_profile = gst_pbutils::EncodingVideoProfileBuilder::new() let video_profile =
.format(&gst::Caps::new_simple("video/x-theora", &[])) gst_pbutils::EncodingVideoProfile::builder(&gst::Caps::builder("video/x-theora").build())
.presence(0) .presence(0)
.build()?; .build();
// All streams are then finally combined into a matroska container. // All streams are then finally combined into a matroska container.
let container_profile = gst_pbutils::EncodingContainerProfileBuilder::new() let container_profile = gst_pbutils::EncodingContainerProfile::builder(
&gst::Caps::builder("video/x-matroska").build(),
)
.name("container") .name("container")
.format(&gst::Caps::new_simple("video/x-matroska", &[]))
.add_profile(&(video_profile)) .add_profile(&(video_profile))
.add_profile(&(audio_profile)) .add_profile(&(audio_profile))
.build()?; .build();
// Finally, apply the EncodingProfile onto our encodebin element. // Finally, apply the EncodingProfile onto our encodebin element.
encodebin encodebin
.set_property("profile", &container_profile) .set_property("profile", &container_profile)
.expect("set profile property failed"); .expect("set profile property failed");
Ok(())
} }
fn example_main() -> Result<(), Error> { fn example_main() -> Result<(), Error> {
@ -112,7 +111,7 @@ fn example_main() -> Result<(), Error> {
// Configure the encodebin. // Configure the encodebin.
// Here we tell the bin what format we expect it to create at its output. // Here we tell the bin what format we expect it to create at its output.
configure_encodebin(&encodebin)?; configure_encodebin(&encodebin);
pipeline pipeline
.add_many(&[&src, &encodebin, &sink]) .add_many(&[&src, &encodebin, &sink])

View file

@ -47,25 +47,22 @@ mod examples_common;
fn configure_pipeline(pipeline: &ges::Pipeline, output_name: &str) { fn configure_pipeline(pipeline: &ges::Pipeline, output_name: &str) {
// Every audiostream piped into the encodebin should be encoded using opus. // Every audiostream piped into the encodebin should be encoded using opus.
let audio_profile = gst_pbutils::EncodingAudioProfileBuilder::new() let audio_profile =
.format(&gst::Caps::new_simple("audio/x-opus", &[])) gst_pbutils::EncodingAudioProfile::builder(&gst::Caps::builder("audio/x-opus").build())
.build() .build();
.expect("Failed to create audio profile");
// Every videostream piped into the encodebin should be encoded using vp8. // Every videostream piped into the encodebin should be encoded using vp8.
let video_profile = gst_pbutils::EncodingVideoProfileBuilder::new() let video_profile =
.format(&gst::Caps::new_simple("video/x-vp8", &[])) gst_pbutils::EncodingVideoProfile::builder(&gst::Caps::builder("video/x-vp8").build())
.build() .build();
.expect("Failed to create video profile");
// All streams are then finally combined into a webm container. // All streams are then finally combined into a webm container.
let container_profile = gst_pbutils::EncodingContainerProfileBuilder::new() let container_profile =
gst_pbutils::EncodingContainerProfile::builder(&gst::Caps::builder("video/webm").build())
.name("container") .name("container")
.format(&gst::Caps::new_simple("video/webm", &[]))
.add_profile(&video_profile) .add_profile(&video_profile)
.add_profile(&audio_profile) .add_profile(&audio_profile)
.build() .build();
.expect("Failed to create container profile");
// Apply the EncodingProfile to the pipeline, and set it to render mode // Apply the EncodingProfile to the pipeline, and set it to render mode
let output_uri = format!("{}.webm", output_name); let output_uri = format!("{}.webm", output_name);