webvtt-playground/src/main.rs
2021-12-29 17:00:06 +01:00

83 lines
2.5 KiB
Rust

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
let pipeline = gst::parse_launch(
"videotestsrc num-buffers=1800 ! video/x-raw,width=1280,height=720,framerate=30/1 ! glimagesink"
// "cccombiner name=ccc ! cea608overlay ! autovideosink \
// videotestsrc num-buffers=1800 ! video/x-raw,width=1280,height=720,framerate=30/1 ! queue ! ccc.sink \
// appsrc name=text-src ! tttocea608 ! queue ! ccc.caption",
)?
.downcast::<gst::Pipeline>()
.expect("Expected a gst::Pipeline");
// let text_src = pipeline.by_name("text-src")
// .unwrap()
// .downcast::<gst_app::AppSrc>()
// .unwrap();
// text_src.set_is_live(true);
// text_src.set_caps(Some(
// &gst::Caps::builder("text/x-raw")
// .field("format", "utf8")
// .build(),
// ));
println!("Starting pipeline..");
main_loop(pipeline)
}
fn push_buffer(pipeline: &gst::Pipeline) {
let src = pipeline
.by_name("text-src")
.unwrap()
.downcast::<gst_app::AppSrc>()
.unwrap();
let timestamp = pipeline.current_clock_time().unwrap() + gst::ClockTime::from_seconds(1);
let text = "Nice story, bro!1".to_string();
let mut buffer = gst::Buffer::from_slice(text);
{
let buffer = buffer.get_mut().unwrap();
buffer.set_pts(timestamp);
buffer.set_duration(gst::ClockTime::from_seconds(10));
buffer.set_flags(gst::BufferFlags::DELTA_UNIT);
}
src.push_buffer(buffer).unwrap();
}
fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
// let main_loop = glib::MainLoop::new(None, false);
pipeline.set_state(gst::State::Playing)?;
let bus = pipeline.bus().unwrap();
for msg in bus.iter_timed(gst::ClockTime::NONE) {
use gst::MessageView;
match msg.view() {
MessageView::Eos(..) => break,
MessageView::Error(err) => {
println!(
"Error from {:?}: {} ({:?})",
msg.src().map(|s| s.path_string()),
err.error(),
err.debug()
);
break;
}
_ => (),
}
}
pipeline.set_state(gst::State::Null)?;
Ok(())
}