### Install GStreamer on Fedora Source: https://github.com/gstreamer/gstreamer-rs/blob/main/gstreamer/README.md Installs GStreamer development libraries and plugins on Fedora systems. Ensure GStreamer version is at least 1.14. ```bash dnf install gstreamer1-devel gstreamer1-plugins-base-devel \ gstreamer1-plugins-good gstreamer1-plugins-bad-free \ gstreamer1-plugin-libav gstreamer1-rtsp-server-devel \ gst-editing-services-devel ``` -------------------------------- ### Initialize GStreamer with gst::init() Source: https://context7.com/gstreamer/gstreamer-rs/llms.txt Call gst::init() once before any other GStreamer function. It returns an error if initialization fails, for example, if GStreamer libraries are not installed. ```rust use gst::prelude::*; fn main() { // Initialize GStreamer; panics on failure with .unwrap(), or propagate with ? gst::init().expect("Failed to initialize GStreamer"); println!("GStreamer version: {}", gst::version_string()); // Output: GStreamer version: GStreamer 1.24.x } ``` -------------------------------- ### Install GStreamer on Debian/Ubuntu Source: https://github.com/gstreamer/gstreamer-rs/blob/main/gstreamer-allocators/README.md Installs GStreamer core libraries and essential plugins on Debian-based systems. Ensure version is >= 1.14. ```bash $ apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev \ gstreamer1.0-plugins-base gstreamer1.0-plugins-good \ gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly \ gstreamer1.0-libav libgstrtspserver-1.0-dev libges-1.0-dev ``` -------------------------------- ### Install GStreamer on Debian/Ubuntu Source: https://github.com/gstreamer/gstreamer-rs/blob/main/gstreamer/README.md Installs GStreamer development libraries and plugins on Debian/Ubuntu systems. Ensure GStreamer version is at least 1.14. ```bash apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev \ gstreamer1.0-plugins-base gstreamer1.0-plugins-good \ gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly \ gstreamer1.0-libav libgstrtspserver-1.0-dev libges-1.0-dev ``` -------------------------------- ### Install GStreamer with Homebrew on macOS Source: https://github.com/gstreamer/gstreamer-rs/blob/main/gstreamer-allocators/README.md Installs GStreamer and all its plugin modules using the Homebrew package manager. Ensure the installed version is >= 1.14. ```bash $ brew install gstreamer ``` -------------------------------- ### Install GStreamer on Debian/Ubuntu Source: https://github.com/gstreamer/gstreamer-rs/blob/main/gstreamer-gl/egl/README.md Installs GStreamer development libraries and plugins required for building GStreamer-RS or dependent projects on Debian/Ubuntu systems. ```bash $ apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev \ gstreamer1.0-plugins-base gstreamer1.0-plugins-good \ gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly \ gstreamer1.0-libav libgstrtspserver-1.0-dev libges-1.0-dev ``` ```bash $ apt-get install libgstreamer-plugins-bad1.0-dev ``` -------------------------------- ### Install GStreamer with Homebrew on macOS Source: https://github.com/gstreamer/gstreamer-rs/blob/main/gstreamer/README.md Installs GStreamer and all its plugin modules using Homebrew on macOS. Ensure the installed version is 1.14 or higher. ```bash brew install gstreamer ``` -------------------------------- ### Install GStreamer Dependencies with MSYS2 Source: https://github.com/gstreamer/gstreamer-rs/blob/main/gstreamer/README.md Install necessary GStreamer development libraries and tools using pacman in MSYS2. Ensure library versions are at least 1.14. ```shell $ pacman -S glib2-devel pkg-config \ mingw-w64-x86_64-gstreamer mingw-w64-x86_64-gst-plugins-base \ mingw-w64-x86_64-gst-plugins-good mingw-w64-x86_64-gst-plugins-bad \ mingw-w64-x86_64-gst-plugins-ugly mingw-w64-x86_64-gst-libav \ mingw-w64-x86_64-gst-rtsp-server ``` -------------------------------- ### Install Additional Fedora GStreamer Packages Source: https://github.com/gstreamer/gstreamer-rs/blob/main/gstreamer/README.md Installs optional GStreamer plugins on Fedora systems, often found in RPMFusion. These may be required for specific functionalities. ```bash dnf install gstreamer1-plugins-bad-freeworld gstreamer1-plugins-ugly ``` -------------------------------- ### Install GStreamer Dependencies on MSYS2 Source: https://github.com/gstreamer/gstreamer-rs/blob/main/gstreamer-gl/egl/README.md Installs necessary GStreamer development libraries and plugins using pacman. Ensure libraries are version 1.14 or higher. Note potential issues with the bundled pkg-config. ```bash pacman -S glib2-devel pkg-config \ mingw-w64-x86_64-gstreamer mingw-w64-x86_64-gst-plugins-base \ mingw-w64-x86_64-gst-plugins-good mingw-w64-x86_64-gst-plugins-bad \ mingw-w64-x86_64-gst-plugins-ugly mingw-w64-x86_64-gst-libav \ mingw-w64-x86_64-gst-rtsp-server ``` -------------------------------- ### Install GStreamer Dependencies with MSYS2/pacman Source: https://github.com/gstreamer/gstreamer-rs/blob/main/gstreamer-allocators/README.md Install necessary GStreamer development libraries and tools using the pacman package manager in MSYS2. Ensure library versions are at least 1.14. ```shell $ pacman -S glib2-devel pkg-config \ mingw-w64-x86_64-gstreamer mingw-w64-x86_64-gst-plugins-base mingw-w64-x86_64-gst-plugins-good mingw-w64-x86_64-gst-plugins-bad mingw-w64-x86_64-gst-plugins-ugly mingw-w64-x86_64-gst-libav mingw-w64-x86_64-gst-rtsp-server ``` -------------------------------- ### Install GStreamer Bad Plugin on Fedora Source: https://github.com/gstreamer/gstreamer-rs/blob/main/gstreamer/README.md Installs the GStreamer bad plugin development package on Fedora. This is required if building the gstreamer-player sub-crate or related examples. ```bash dnf install gstreamer1-plugins-bad-free-devel ``` -------------------------------- ### GStreamer Pipeline Setup and Execution in Rust Source: https://context7.com/gstreamer/gstreamer-rs/llms.txt Demonstrates how to create, configure, and run a GStreamer pipeline using Rust. Includes initializing GStreamer, building a pipeline with custom and factory elements, linking them, setting the state to playing, and handling bus messages. ```rust fn main() { gst::init().unwrap(); let pipeline = gst::Pipeline::default(); let src = gst::ElementFactory::make("audiotestsrc").build().unwrap(); let filter = GainFilter::new(None); filter.set_gain(0.5); // 50% volume let conv = gst::ElementFactory::make("audioconvert").build().unwrap(); let sink = gst::ElementFactory::make("autoaudiosink").build().unwrap(); pipeline.add_many([&src, filter.upcast_ref(), &conv, &sink]).unwrap(); src.link(&filter).unwrap(); filter.link(&conv).unwrap(); conv.link(&sink).unwrap(); pipeline.set_state(gst::State::Playing).unwrap(); let bus = pipeline.bus().unwrap(); for msg in bus.iter_timed(gst::ClockTime::from_seconds(3)) { match msg.view() { gst::MessageView::Eos(..) | gst::MessageView::Error(..) => break, _ => {} } } pipeline.set_state(gst::State::Null).unwrap(); } ``` -------------------------------- ### Install GStreamer Bad Plugin on Debian/Ubuntu Source: https://github.com/gstreamer/gstreamer-rs/blob/main/gstreamer/README.md Installs the GStreamer bad plugin development package on Debian/Ubuntu. This is required if building the gstreamer-player sub-crate or related examples. ```bash apt-get install libgstreamer-plugins-bad1.0-dev ``` -------------------------------- ### Configure Video Scaling and Cropping with gst_video::VideoConverterConfig Source: https://context7.com/gstreamer/gstreamer-rs/llms.txt Set crop regions and output placement on compositor sink pads to perform precise video framing using `gst_video::VideoConverterConfig`. This example configures both source cropping and destination positioning. ```rust use gst::prelude::*; fn main() { gst::init().unwrap(); let pipeline = gst::parse::launch( "videotestsrc name=src ! video/x-raw,width=640,height=480 \ ! compositor0.sink_0 compositor name=compositor0 \ ! video/x-raw,width=1280,height=720 ! videoconvert ! autovideosink", ).unwrap().dynamic_cast::().unwrap(); let compositor = pipeline.by_name("compositor0").unwrap(); let sinkpad = compositor.static_pad("sink_0").unwrap(); // Output occupies the full 1280x720 canvas sinkpad.set_property("xpos", 0i32); sinkpad.set_property("ypos", 0i32); sinkpad.set_property("width", 1280i32); sinkpad.set_property("height", 720i32); // Crop a 512x480 (5:4) region from the center of the 640x480 (4:3) source, // then letter-box it into a 900x720 area centred on the 1280x720 output. let mut cfg = gst_video::VideoConverterConfig::new(); cfg.set_src_x((640 - 512) / 2); cfg.set_src_width(Some(512)); cfg.set_src_y(0); cfg.set_src_height(Some(480)); cfg.set_dest_x((1280 - 900) / 2); cfg.set_dest_width(Some(900)); cfg.set_dest_y(0); cfg.set_dest_height(Some(720)); sinkpad.set_property("converter-config", &*cfg); pipeline.set_state(gst::State::Playing).unwrap(); let bus = pipeline.bus().unwrap(); for msg in bus.iter_timed(gst::ClockTime::from_seconds(5)) { match msg.view() { gst::MessageView::Eos(..) | gst::MessageView::Error(..) => break, _ => {} } } pipeline.set_state(gst::State::Null).unwrap(); } ``` -------------------------------- ### High-Level Playback API with `gst_play::Play` Source: https://context7.com/gstreamer/gstreamer-rs/llms.txt Utilize `GstPlay` for simplified URI playback, seeking, volume control, and stream switching. Initialize GStreamer and create a `Play` instance, then set the URI and control playback. ```rust use gst_play::{Play, PlayMessage, PlayVideoRenderer}; fn main() { gst::init().unwrap(); let play = Play::new(None::); play.set_uri(Some("https://www.freedesktop.org/software/gstreamer-sdk/data/media/sintel_trailer-480p.webm")); play.play(); for msg in play.message_bus().iter_timed(gst::ClockTime::NONE) { match PlayMessage::parse(&msg).unwrap() { PlayMessage::EndOfStream(_) => { println!("Playback finished"); play.stop(); break; } PlayMessage::Error(e) => { eprintln!("Error: {}", e.error()); play.stop(); break; } PlayMessage::DurationChanged(d) => { if let Some(dur) = d.duration() { println!("Duration: {}", dur.display()); } } PlayMessage::PositionUpdated(p) => { if let Some(pos) = p.position() { print!("\rPosition: {}", pos.display()); } } _ => {} } } // Flush pending messages before dropping Play to avoid reference cycles play.message_bus().set_flushing(true); } ``` -------------------------------- ### Handle Dynamic Media with decodebin Source: https://context7.com/gstreamer/gstreamer-rs/llms.txt Use decodebin with the pad-added signal to automatically detect and decode unknown or mixed audio/video content from a file. This example dynamically links audio or video sinks based on the detected media type. ```rust use gst::prelude::*; use std::sync::{Arc, Mutex}; fn main() { gst::init().unwrap(); let pipeline = gst::Pipeline::default(); let src = gst::ElementFactory::make("filesrc") .property("location", "video.mp4") .build().unwrap(); let decodebin = gst::ElementFactory::make("decodebin").build().unwrap(); pipeline.add_many([&src, &decodebin]).unwrap(); gst::Element::link_many([&src, &decodebin]).unwrap(); // Use a weak reference to avoid reference cycles in the closure let pipeline_weak = pipeline.downgrade(); decodebin.connect_pad_added(move |_dbin, src_pad| { let Some(pipeline) = pipeline_weak.upgrade() else { return }; let caps = src_pad.current_caps().unwrap(); let name = caps.structure(0).unwrap().name(); if name.starts_with("audio/") { let queue = gst::ElementFactory::make("queue").build().unwrap(); let convert = gst::ElementFactory::make("audioconvert").build().unwrap(); let resample= gst::ElementFactory::make("audioresample").build().unwrap(); let sink = gst::ElementFactory::make("autoaudiosink").build().unwrap(); let elements = &[&queue, &convert, &resample, &sink]; pipeline.add_many(elements).unwrap(); gst::Element::link_many(elements).unwrap(); for e in elements { e.sync_state_with_parent().unwrap(); } src_pad.link(&queue.static_pad("sink").unwrap()).unwrap(); } else if name.starts_with("video/") { let queue = gst::ElementFactory::make("queue").build().unwrap(); let convert = gst::ElementFactory::make("videoconvert").build().unwrap(); let scale = gst::ElementFactory::make("videoscale").build().unwrap(); let sink = gst::ElementFactory::make("autovideosink").build().unwrap(); let elements = &[&queue, &convert, &scale, &sink]; pipeline.add_many(elements).unwrap(); gst::Element::link_many(elements).unwrap(); for e in elements { e.sync_state_with_parent().unwrap(); } src_pad.link(&queue.static_pad("sink").unwrap()).unwrap(); } }); pipeline.set_state(gst::State::Playing).unwrap(); let bus = pipeline.bus().unwrap(); for msg in bus.iter_timed(gst::ClockTime::NONE) { match msg.view() { gst::MessageView::Eos(..) => break, gst::MessageView::Error(e) => { eprintln!("Error: {}", e.error()); break; } gst::MessageView::StateChanged(s) => { println!("{:?} -> {:?}", s.old(), s.current()); } _ => {} } } pipeline.set_state(gst::State::Null).unwrap(); } ``` -------------------------------- ### Serve RTSP Stream with `gst_rtsp_server::RTSPServer` Source: https://context7.com/gstreamer/gstreamer-rs/llms.txt Expose a GStreamer pipeline as an RTSP endpoint using `gst_rtsp_server::RTSPServer`. Configure the media factory with a launch string and mount it to a specific path. ```rust use gst_rtsp_server::prelude::*; fn main() { gst::init().unwrap(); let main_loop = glib::MainLoop::new(None, false); let server = gst_rtsp_server::RTSPServer::new(); // Optionally set port: server.set_service("8554"); let mounts = server.mount_points().expect("No mount points"); let factory = gst_rtsp_server::RTSPMediaFactory::new(); // The launch string describes the media pipeline for each client connection factory.set_launch( "( videotestsrc pattern=ball ! video/x-raw,width=640,height=480,framerate=30/1 \ ! x264enc tune=zerolatency ! rtph264pay name=pay0 pt=96 )" ); // shared=true: all clients receive the same live stream instance factory.set_shared(true); mounts.add_factory("/live", factory); let id = server.attach(None).expect("Failed to attach server"); println!("RTSP stream at rtsp://127.0.0.1:{}/live", server.bound_port()); // Connect with: vlc rtsp://127.0.0.1:8554/live main_loop.run(); id.remove(); } ``` -------------------------------- ### Build GStreamer Bindings Source: https://github.com/gstreamer/gstreamer-rs/blob/main/DEVELOPMENT.md Build the entire gstreamer-rs project after updating bindings. ```bash cargo build ``` -------------------------------- ### Install GStreamer Plugins Bad on Debian/Ubuntu Source: https://github.com/gstreamer/gstreamer-rs/blob/main/gstreamer-allocators/README.md Installs the 'bad' GStreamer plugin set, which might be required for specific features or crates like gstreamer-player. ```bash $ apt-get install libgstreamer-plugins-bad1.0-dev ```