Forum: Ruby-Gnome 2 gstreamer : how to put video in a gtk widget on windows ?

B078cb4f4fb473c7a54d1fc36d10c70e?d=identicon&s=25 Regis d'Aubarede (raubarede)
on 2013-09-02 20:01
Hello,

On windows with old gst version, we use to put video in a
gtk window with  xwindow_id:

view =            Gst::ElementFactory.make('playbin')
view.video_sink = Gst::ElementFactory.make('directdrawsink')
handle = Win32API.new('user32', 'GetForegroundWindow', [], 'N').call
view.video_sink.xwindow_id=handle

but it's seem that from now 'xwindow_id' do not exist.

NOTA:
(view.video_sink.methods - Object.methods) give :

copy,gtype,type,value
(class GLib::Value)
394f372e936f867e4e43bfd1315a0a4e?d=identicon&s=25 Masafumi Yokoyama (Guest)
on 2013-09-15 18:09
(Received via mailing list)
Hi,

2013/9/3 Regis d'Aubarede <ruby-forum-incoming@andreas-s.net>:
> NOTA:
> (view.video_sink.methods - Object.methods) give :
>
> copy,gtype,type,value
> (class GLib::Value)

Please let me identify the problem.
I tried the following codes on Windows.

In GStreamer 0.10 (Ruby/GStreamer 1.2.6 or earlier), "directdrawsink"
exist.

    gem "glib2", "1.2.6"
    gem "gstreamer", "1.2.6"
    require "gst"
    p Gst::ElementFactory.make('directdrawsink')
    #=> #<Gst::ElementDirectDrawSink:02BC1670 ptr=02C3D918>

In GStreamer 1.0 (Ruby/GStreamer 2.0.0 or later), "directdrawsink"
does not seem to exist.

    gem "glib2", "2.0.2"
    gem "gstreamer", "2.0.2"
    require "gst"
    p Gst::ElementFactory.make('directdrawsink')
    #=> nil

I'm looking for a list of elements.

--
Masafumi Yokoyama
GitHub: myokoym
B078cb4f4fb473c7a54d1fc36d10c70e?d=identicon&s=25 Regis d'Aubarede (raubarede)
on 2013-09-17 16:03
Attachment: v.rb (772 Bytes)
> I'm looking for a list of elements.


here the code (i try to use d3dvideosink) :
    require "gtk3"
    require "gst"

    Gem.loaded_specs.map {|n,g| puts "  | %10s %6s " %
[g.name,g.version] }

    window = Gtk::Window.new
    wid=Gtk::DrawingArea.new()
    wid.set_size_request(200,100)
    v =Gst::ElementFactory.make('playbin')
    v.video_sink = Gst::ElementFactory.make('d3dvideosink')

    require('win32api');
    handle = Win32API.new('user32', 'GetForegroundWindow', [], 'N').call
    p window.window.methods
    v.video_sink.xwindow_id(handle) # !!!!scratch!!!!

    v.uri = "file:///d:/usr/local/video/avi/film3.avi"

    wid.events |= ( ::Gdk::Event::Mask::BUTTON_PRESS_MASK |
::Gdk::Event::Mask::POINTER_MOTION_MASK |
::Gdk::Event::Mask::BUTTON_RELEASE_MASK)
    wid.signal_connect('draw') do |w1,e|   end

    window.signal_connect("destroy") {Gtk.main_quit}
    window.add(wid)
    window.show_all
    Gtk.main



And the execution:


d:\usr\Ruby\local\Ruiby\samples>ruby v.rb
  | pkg-config  1.1.4
  |      glib2  2.0.2
  |       gio2  2.0.2
  |        atk  2.0.2
  |      cairo 1.12.6
  |      pango  2.0.2
  | gdk_pixbuf2  2.0.2
  |       gdk3  2.0.2
  |       gtk3  2.0.2
  | gobject-introspection  2.0.2
  |  gstreamer  2.0.2
DL is deprecated, please use Fiddle
[:to_i, :to_f, :to_s, :to_a, :to_h, :inspect, :&, :|, :^, :nil?, :to_r,
:rationalize, :to_c, :===, :=~, :!~, :eql?, :hash, :<=>, :class,
:singleton_class, :clone, :dup, :taint, :tainted?, :untaint, :untrust,
:untrusted?, :trust, :freeze, :frozen?, :methods, :singleton_methods,
:protected_methods, :private_methods, :public_methods,
:instance_variables, :instance_variable_get, :instance_variable_set,
:instance_variable_defined?, :remove_instance_variable, :instance_of?,
:kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :extend,
:display, :method, :public_method, :define_singleton_method, :object_id,
:to_enum, :enum_for, :==, :equal?, :!, :!=, :instance_eval,
:instance_exec, :__send__, :__id__]

(ruby.exe:7228): GStreamer-CRITICAL **: gst_child_proxy_get_property:
assertion `G_IS_VALUE (value)' failed
v.rb:15:in `<main>': undefined method `xwindow_id' for
#<GLib::Value:0692E3B0 ptr=06902908 own=true> (NoMethodError)
394f372e936f867e4e43bfd1315a0a4e?d=identicon&s=25 Masafumi Yokoyama (Guest)
on 2013-09-17 19:16
(Received via mailing list)
Hi,

2013/9/17 Regis d'Aubarede <ruby-forum-incoming@andreas-s.net>:
>     window = Gtk::Window.new
>     v.uri = "file:///d:/usr/local/video/avi/film3.avi"
>
>   |      cairo 1.12.6
> :untrusted?, :trust, :freeze, :frozen?, :methods, :singleton_methods,
> v.rb:15:in `<main>': undefined method `xwindow_id' for
> #<GLib::Value:0692E3B0 ptr=06902908 own=true> (NoMethodError)
>
> Attachments:
> http://www.ruby-forum.com/attachment/8729/v.rb

Umm... The API seemed to change.

Now, there is also the following way:

require "clutter-gtk"  # gem install clutter-gtk (It uses gtk3)
require "clutter-gst"  # gem install clutter-gstreamer

clutter = ClutterGtk::Embed.new
stage = clutter.stage

# For Clutter-GStreamer 2.0.2. This API will change.
video_texture = ClutterGst::VideoTexture.new
stage.add_child(video_texture)
video_texture.uri = "file:///d:/usr/local/video/avi/film3.avi"
video_texture.playing = true

window = Gtk::Window.new
window.signal_connect("destroy") {Gtk.main_quit}
window.add(clutter)
window.show_all
Gtk.main

--
Masafumi Yokoyama
GitHub: myokoym
B078cb4f4fb473c7a54d1fc36d10c70e?d=identicon&s=25 Regis d'Aubarede (raubarede)
on 2013-09-17 21:28
That's work !
Thank you.

Discovering Clutter, it's seem very mysterious, no tutorials...

bye
394f372e936f867e4e43bfd1315a0a4e?d=identicon&s=25 Masafumi Yokoyama (Guest)
on 2013-09-19 18:03
(Received via mailing list)
Good evening.

2013/9/18 Regis d'Aubarede <ruby-forum-incoming@andreas-s.net>:
> Discovering Clutter, it's seem very mysterious, no tutorials...

I started to write Ruby/Clutter tutorial.

http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-clutter

Tell me if it is difficult to understand.

--
Masafumi Yokoyama
GitHub: myokoym
B078cb4f4fb473c7a54d1fc36d10c70e?d=identicon&s=25 Regis d'Aubarede (raubarede)
on 2013-09-19 22:24
> http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-clutter
>
> Tell me if it is difficult to understand.
>

Nice start !

Found that on wikipedia:
"
Clutter is an open source graphics library for creating
hardware-accelerated user interfaces. It relies upon OpenGL (1.4+) or
OpenGL ES (1.1 or 2.0) for rendering, can be compiled on different
platforms (X11, Wayland, Darwin and Win32) and has multiple bindings to
other languages (including Mono, Perl, Python, Ruby and Vala). It also
supports media playback using GStreamer and 2D graphics rendering using
Cairo.[4]
"

If Clutter is done for performence, its usage via Ruby is it relevant ?
I use Gosu for graphics (smooth) animations (sprites,vectors for
games...),
Is Clutter better for that ?
394f372e936f867e4e43bfd1315a0a4e?d=identicon&s=25 Masafumi Yokoyama (masafumi_y)
on 2013-09-20 18:21
Hi,

Regis d'Aubarede wrote in post #1121938:
> Found that on wikipedia:
> "
> Clutter is an open source graphics library for creating
> hardware-accelerated user interfaces. It relies upon OpenGL (1.4+) or
> OpenGL ES (1.1 or 2.0) for rendering, can be compiled on different
> platforms (X11, Wayland, Darwin and Win32) and has multiple bindings to
> other languages (including Mono, Perl, Python, Ruby and Vala). It also
> supports media playback using GStreamer and 2D graphics rendering using
> Cairo.[4]
> "
>
> If Clutter is done for performence, its usage via Ruby is it relevant ?

Umm, I don't know much about it...


> I use Gosu for graphics (smooth) animations (sprites,vectors for
> games...),
> Is Clutter better for that ?

Oh, Gosu is looking good. But I think that uses are different.
Gosu is for game application, and Clutter is for general desktop
application.

Clutter is able to make game application, but it will be some hard work.
If not making game application, I think that Clutter may be better than
Gosu.


--
Masafumi Yokoyama
GitHub: myokoym
B078cb4f4fb473c7a54d1fc36d10c70e?d=identicon&s=25 Regis d'Aubarede (raubarede)
on 2013-09-23 22:13
Video in Ruiby dsl done!

require "gtk3"
require 'Ruiby'
require "gst"
require "clutter-gtk"  # gem install clutter-gtk
require "clutter-gst"  # gem install clutter-gstreamer

module  Ruiby_dsl

  def video(url=nil,w=300,h=200)
    clutter = ClutterGtk::Embed.new
    video=ClutterGst::VideoTexture.new
    clutter.stage.add_child(video)
    video.width=w
    video.height=h
    video.uri = url if url
    video.playing = false
    isNotify=false
    clutter.define_singleton_method(:url=) { |u| video.url = url }
    clutter.define_singleton_method(:play) { video.playing = true }
    clutter.define_singleton_method(:stop) { video.playing = false }
    clutter.define_singleton_method(:progress=) { |pp|
            video.progress=(pp) unless isNotify
    }
    if block_given?
      video.signal_connect("notify") { |o,v,param|
            isNotify=true ;
            yield(video.progress()) rescue p $! ;
            isNotify=false
      }
    end
    attribs(clutter,{})
  end
end

Ruiby.app width: 600,height: 400 do
   video_file= ARGV[0] || "d:/usr/XT.avi"
   unless File.exists?(video_file)
      error("File video does not exists : '#{video_file}'")
      exit!(0)
   end
   video_url="file:///#{video_file}"
  stack do
    @video=video(video_url,600,400-40)  {|progress|
             @prog &&  @prog.progress=progress*100
    }
    flowi do
      buttoni("  Start  ")    {  @video.play }
      buttoni("  Stop  ")     {  @video.stop }
      @prog=slider(0,0,100.0) { |pos| @video.progress= pos/100.0}
      buttoni("  Exit  ")     { exit!(0) }
    end
  end
end

Screen copy at :
http://raubarede.tumblr.com/post/62084710192/new-v...
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.