From 2340e85b36f20f1d64ce88e69933c4cf1faefb48 Mon Sep 17 00:00:00 2001 From: Rafael Caricio Date: Wed, 29 Dec 2021 19:55:21 +0100 Subject: [PATCH] Works as expected --- src/main.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4993cfb..f443f9b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,17 +1,15 @@ use gst::prelude::*; use anyhow::Error; - fn main() -> Result<(), Error> { gst::init().unwrap(); gstrsclosedcaption::plugin_register_static().expect("Failed to register closed caption plugin"); - // TODO: create a video source with X buffers and burn the captions in the video feed using the captions tooling - + // Create a video source with X buffers and burn the captions in the video feed using the captions tooling let pipeline = gst::parse_launch( "cccombiner name=ccc ! cea608overlay ! autovideosink \ videotestsrc num-buffers=1800 ! video/x-raw,width=1280,height=720,framerate=30/1 ! queue ! ccc.sink \ - tttocea608 name=converter ! queue ! ccc.caption", + tttocea608 name=converter mode=1 ! queue ! ccc.caption", )? .downcast::() .expect("Expected a gst::Pipeline"); @@ -35,7 +33,8 @@ fn main() -> Result<(), Error> { } fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> { - let main_loop = glib::MainLoop::new(None, false); + let context = glib::MainContext::default(); + let main_loop = glib::MainLoop::new(Some(&context), false); pipeline.set_state(gst::State::Playing)?; @@ -66,7 +65,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> { .expect("Failed to add bus watch"); let pipeline_weak = pipeline.downgrade(); - let timeout_id = glib::timeout_add_local(std::time::Duration::from_secs(10), move || { + let timeout_id = glib::timeout_add_local(std::time::Duration::from_secs(20), move || { let pipeline = match pipeline_weak.upgrade() { Some(pipeline) => pipeline, None => return glib::Continue(true), @@ -92,16 +91,16 @@ fn push_buffer(pipeline: &gst::Pipeline) { .downcast::() .unwrap(); - let timestamp = pipeline.query_position::().unwrap(); + let timestamp = pipeline.query_position::().unwrap() + gst::ClockTime::from_seconds(1); println!("Trying to publish text buffer NOW! - {}", timestamp.display()); - let text = "Nice story, bro!1".to_string(); + let text = format!("Such nice: {}!", timestamp.display()); let mut buffer = gst::Buffer::from_mut_slice(text.into_bytes()); { let buffer = buffer.get_mut().unwrap(); buffer.set_pts(timestamp); - buffer.set_duration(gst::ClockTime::from_seconds(10)); + buffer.set_duration(gst::ClockTime::from_seconds(1)); } src.push_buffer(buffer).unwrap(); } \ No newline at end of file