Basic Tutorial 5 missing from GStreamer-rs

Hello there!

Longtime user of GStreamer through the gstreamer-rs bindings. Our application is overdue for an API version update ( GitHub - decode-detroit/apollo: Realtime Remote-Controlled Multimedia Player · GitHub ), but don’t want to spend too much time pounding my head against the wall. :slight_smile:

Does the absence of Basic Tutorial 5 (GUI Toolkit) for the GStreamer-rs bindings mean that it is not reliably supported, or is it just that no one has had a chance to port it over? https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/tree/main/tutorials/src/bin

My primary concern is creating the video sink element and integrating is into the GTK window. If this works, than I’m not too worried about other typical user interface elements.

Thanks for your help!

You can do things like tutorial 5 with rust however you would need to delve into unsafe code in order to pass the relevant window handles around. There are better solutions for GTK (and other toolkits) these days like gtk(gl)sink (GTK3), or gtkpaintablesink (GTK4) that more closely integrate with the relevant UI toolkit.

Ah, excellent! Thanks for the clarification!

Do you happen to know where I could find an example for gtkpaintablesink? We’re planning to upgrade to gtk4, but a gtksink example would be helpful instead if you know where one is.

In particular, I’m struggling with how to coerce the gstreamer::element_factory::ElementBuilder<'_> that I get from gst::ElementBuilder::make(“gtkpaintablesink”) in to a `glib::object::IsAgtk4::Widget.

Without adding/coercing the Widget trait, I’m unable to manipulate the gtkpaintablesink like a normal Widget in GTK-rs.

gtkpaintablesink is not a gtk::Widget.

An example is available from video/gtk4/examples · main · GStreamer / gst-plugins-rs · GitLab

Gotcha! I didn’t realize it was a separate plugin/crate to import. Thanks again for your assistance!

To anyone skimming in the future:

# In Cargo.toml
[dependencies]
gst-plugin-gtk4 = “^0.15” 
// Right after you initialize GStreamer
gst::init().unwrap()

// Load the plugin
gst_plugin_gtk4::plugin_register_static()
// After you've created your gtk4paintablesink
let video_sink = gst::ElementFactory::make("gtk4paintablesink").build().unwrap();

// And added it to your pipeline, for example
playbin.set_property("video-sink", &video_sink);

// Wrap it into a widget and place it where you want
let video_widget = gst_plugin_gtk4::RenderWidget::new(&video_sink);

Patton

P.S. My version of GTK is apparently too out of date to compile this code, so I will edit this answer if it is incorrect once I can compile.

Just confirming this is the correct solution (slight edits below):

# In Cargo.toml
[dependencies]

gstreamer = "0.25"
gstreamer-video = "0.25"
gst-plugin-gtk4 = { version = "0.15", features = ["gtk_v4_14", "waylandegl"] }
// Initialize GStreamer
gst::init().unwrap()

// And load the plugin
gstgtk4::plugin_register_static() // note that this crate imports gstgtk4, not gst_plugin_gtk4
// Create your gtk4paintablesink
let video_sink = gst::ElementFactory::make("gtk4paintablesink").build().unwrap();

// Create a playbin, or other pipeline
let playbin = gst::ElementFactory::make_with_name("playbin", None).unwrap();

// And added it to your pipeline, for example
playbin.set_property("video-sink", &video_sink);

// Wrap it into a widget and place it where you want
let video_widget = gstgtk4::RenderWidget::new(&video_sink);

// And manipulate the widget just like you would any other gtk widget

Thanks again for your help!