Basic GStreamer pipeline project
This commit is contained in:
parent
2dae7a7d1e
commit
182ffbd3f3
2 changed files with 71 additions and 0 deletions
13
Cargo.toml
Normal file
13
Cargo.toml
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
[package]
|
||||||
|
name = "{REPO_NAME_LOWER}"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
gst = { package = "gstreamer", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs", features = ["v1_20"] }
|
||||||
|
gst-video = { package = "gstreamer-video", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" }
|
||||||
|
gst-audio = { package = "gstreamer-audio", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" }
|
||||||
|
gst-app = { package = "gstreamer-app", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" }
|
||||||
|
anyhow = "1"
|
58
src/main.rs
Normal file
58
src/main.rs
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
use anyhow::Result;
|
||||||
|
use gst::prelude::*;
|
||||||
|
use gst::glib;
|
||||||
|
use gst::glib::once_cell::sync::Lazy;
|
||||||
|
|
||||||
|
static CAT: Lazy<gst::DebugCategory> = Lazy::new(|| {
|
||||||
|
gst::DebugCategory::new(
|
||||||
|
"main",
|
||||||
|
gst::DebugColorFlags::empty(),
|
||||||
|
Some("Main function"),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
fn main() -> Result<()> {
|
||||||
|
gst::init()?;
|
||||||
|
|
||||||
|
let pipeline = gst::parse_launch(r#"
|
||||||
|
|
||||||
|
videotestsrc ! videoconvert ! timeoverlay shaded-background=true ! gtksink
|
||||||
|
|
||||||
|
"#,)?.downcast::<gst::Pipeline>().unwrap();
|
||||||
|
|
||||||
|
let context = glib::MainContext::default();
|
||||||
|
let main_loop = glib::MainLoop::new(Some(&context), false);
|
||||||
|
|
||||||
|
pipeline.set_state(gst::State::Playing)?;
|
||||||
|
|
||||||
|
let bus = pipeline.bus().unwrap();
|
||||||
|
bus.add_watch({
|
||||||
|
let main_loop = main_loop.clone();
|
||||||
|
move |_, msg| {
|
||||||
|
use gst::MessageView;
|
||||||
|
let main_loop = &main_loop;
|
||||||
|
match msg.view() {
|
||||||
|
MessageView::Eos(..) => main_loop.quit(),
|
||||||
|
MessageView::Error(err) => {
|
||||||
|
gst::error!(CAT, obj: &err.src().unwrap(),
|
||||||
|
"Error from {:?}: {} ({:?})",
|
||||||
|
err.src().map(|s| s.path_string()),
|
||||||
|
err.error(),
|
||||||
|
err.debug()
|
||||||
|
);
|
||||||
|
main_loop.quit();
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
};
|
||||||
|
glib::Continue(true)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.expect("Failed to add bus watch");
|
||||||
|
|
||||||
|
main_loop.run();
|
||||||
|
|
||||||
|
pipeline.set_state(gst::State::Null)?;
|
||||||
|
bus.remove_watch().unwrap();
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
Loading…
Reference in a new issue