Works as expected

This commit is contained in:
Rafael Caricio 2021-12-29 19:55:21 +01:00
parent 0e572be6c0
commit 2340e85b36
Signed by: rafaelcaricio
GPG key ID: 3C86DBCE8E93C947

View file

@ -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::<gst::Pipeline>()
.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::<gst_app::AppSrc>()
.unwrap();
let timestamp = pipeline.query_position::<gst::ClockTime>().unwrap();
let timestamp = pipeline.query_position::<gst::ClockTime>().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();
}