Note that there are some explanatory texts on larger screens.

plurals
  1. POAdd overlay text to gstreamer video in Ruby
    text
    copied!<p>I have write this very simple video player that use gstreamer and gtk2 in Ruby.</p> <pre><code>require 'gtk2' require 'gst' if ARGV.size != 1 puts "Usage: #{$0} &lt;file&gt;" exit 0 end class VideoWidget &lt; Gtk::DrawingArea def initialize(file) super() @playbin = Gst::ElementFactory.make('playbin2') @video = Gst::ElementFactory.make('xvimagesink') @video.force_aspect_ratio = true @overlay = Gst::ElementFactory.make('textoverlay') @overlay.text = 'Foo bar' @playbin.text_sink = @overlay @playbin.video_sink = @video @playbin.audio_sink = Gst::ElementFactory.make('autoaudiosink') @playbin.signal_connect('notify') do @playbin.video_sink.xwindow_id = self.window.xid if self.window @playbin.video_sink.expose end @playbin.uri = "file://#{File.absolute_path(file)}" @playbin.ready end def play @playbin.play end def pause @playbin.pause end def stop @playbin.stop end def seek(time) @playbin.seek(1.0, Gst::Format::TIME, Gst::Seek::FLAG_FLUSH | Gst::Seek::FLAG_KEY_UNIT, Gst::Seek::TYPE_CUR, time * Gst::SECOND, Gst::Seek::TYPE_NONE, -1); end end window = Gtk::Window.new video = VideoWidget.new(ARGV.first) buttonbox = Gtk::HButtonBox.new button = Gtk::Button.new(Gtk::Stock::MEDIA_PLAY) button.signal_connect('clicked') { video.play } buttonbox.add(button) button = Gtk::Button.new(Gtk::Stock::MEDIA_PAUSE) button.signal_connect('clicked') { video.pause } buttonbox.add(button) button = Gtk::Button.new(Gtk::Stock::MEDIA_STOP) button.signal_connect('clicked') { video.stop } buttonbox.add(button) button = Gtk::Button.new(Gtk::Stock::MEDIA_REWIND) button.signal_connect('clicked') { video.seek(-10) } buttonbox.add(button) button = Gtk::Button.new(Gtk::Stock::MEDIA_FORWARD) button.signal_connect('clicked') { video.seek(10) } buttonbox.add(button) hbox = Gtk::HBox.new hbox.pack_start(buttonbox, false) vbox = Gtk::VBox.new vbox.pack_start(video) vbox.pack_start(hbox, false) window.add(vbox) window.signal_connect('destroy') do video.stop Gtk.main_quit end window.set_default_size(640, 480) window.window_position = Gtk::Window::POS_CENTER window.show_all Gtk.main </code></pre> <p>It works, but i want to display some text over the video. I've try to use the gstreamer element <code>textoverlay</code>, but i do not figured out to link this element in the pipeline. Someone have an idea?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload