Works as expected
This commit is contained in:
parent
0e572be6c0
commit
2340e85b36
1 changed files with 8 additions and 9 deletions
17
src/main.rs
17
src/main.rs
|
@ -1,17 +1,15 @@
|
||||||
use gst::prelude::*;
|
use gst::prelude::*;
|
||||||
use anyhow::Error;
|
use anyhow::Error;
|
||||||
|
|
||||||
|
|
||||||
fn main() -> Result<(), Error> {
|
fn main() -> Result<(), Error> {
|
||||||
gst::init().unwrap();
|
gst::init().unwrap();
|
||||||
gstrsclosedcaption::plugin_register_static().expect("Failed to register closed caption plugin");
|
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(
|
let pipeline = gst::parse_launch(
|
||||||
"cccombiner name=ccc ! cea608overlay ! autovideosink \
|
"cccombiner name=ccc ! cea608overlay ! autovideosink \
|
||||||
videotestsrc num-buffers=1800 ! video/x-raw,width=1280,height=720,framerate=30/1 ! queue ! ccc.sink \
|
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>()
|
.downcast::<gst::Pipeline>()
|
||||||
.expect("Expected a gst::Pipeline");
|
.expect("Expected a gst::Pipeline");
|
||||||
|
@ -35,7 +33,8 @@ fn main() -> Result<(), Error> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main_loop(pipeline: gst::Pipeline) -> 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)?;
|
pipeline.set_state(gst::State::Playing)?;
|
||||||
|
|
||||||
|
@ -66,7 +65,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
|
||||||
.expect("Failed to add bus watch");
|
.expect("Failed to add bus watch");
|
||||||
|
|
||||||
let pipeline_weak = pipeline.downgrade();
|
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() {
|
let pipeline = match pipeline_weak.upgrade() {
|
||||||
Some(pipeline) => pipeline,
|
Some(pipeline) => pipeline,
|
||||||
None => return glib::Continue(true),
|
None => return glib::Continue(true),
|
||||||
|
@ -92,16 +91,16 @@ fn push_buffer(pipeline: &gst::Pipeline) {
|
||||||
.downcast::<gst_app::AppSrc>()
|
.downcast::<gst_app::AppSrc>()
|
||||||
.unwrap();
|
.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());
|
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 mut buffer = gst::Buffer::from_mut_slice(text.into_bytes());
|
||||||
{
|
{
|
||||||
let buffer = buffer.get_mut().unwrap();
|
let buffer = buffer.get_mut().unwrap();
|
||||||
buffer.set_pts(timestamp);
|
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();
|
src.push_buffer(buffer).unwrap();
|
||||||
}
|
}
|
Loading…
Reference in a new issue