Skip Menu |

This queue is for tickets about the GStreamer-Interfaces CPAN distribution.

Report information
The Basics
Id: 48069
Status: resolved
Priority: 0/
Queue: GStreamer-Interfaces

People
Owner: Nobody in particular
Requestors: potyl [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.04
Fixed in: (no value)



This patch creates a new example program that demonstrates how to write a real video player in Perl. The program is far from being completed but it works. Hopefully someone else will make a real video player in Perl! The patch is also available through my git clone at http://github.com/potyl/perl-GStreamer-Interfaces/blob/df399e0dce557f88d44a53262e44cb914293ba62/examples/gst-video-player.pl
Subject: 0001-Movie-player-example.patch
From df399e0dce557f88d44a53262e44cb914293ba62 Mon Sep 17 00:00:00 2001 From: Emmanuel Rodriguez <emmanuel.rodriguez@gmail.com> Date: Tue, 21 Jul 2009 21:00:45 +0200 Subject: [PATCH] Movie player example --- examples/gst-video-player.pl | 135 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 135 insertions(+), 0 deletions(-) create mode 100644 examples/gst-video-player.pl diff --git a/examples/gst-video-player.pl b/examples/gst-video-player.pl new file mode 100644 index 0000000..f840261 --- /dev/null +++ b/examples/gst-video-player.pl @@ -0,0 +1,135 @@ +#!/usr/bin/perl + +=head1 NAME + +gst-video-player.pl - Video player made in Perl + +=head1 SYNOPSIS + +gst-video-player.pl video + +Where I<video> is the path to a video file or an URI to a video. + +Play a video that's available locally: + + gst-video-player.pl film.ogv + +Stream a video from a website: + + gst-video-player.pl http://anon.nasa-global.edgesuite.net/qt.nasa-global/ksc/ksc_071509_sts127_launch_480i.mov + +=head1 DESCRIPTION + +This program shows how to create a video player using Gtk2 and Gstreamer. This +player can handle all video formats supported by Gstreamer. + +=cut + +use strict; +use warnings; + +use Glib qw(TRUE FALSE filename_to_uri); +use GStreamer '-init'; +use GStreamer::Interfaces; +use Gtk2 '-init'; +use File::Spec; +use Cwd; + +exit main(); + + +sub main { + die "Usage: file\n" unless @ARGV; + my ($uri) = @ARGV; + + if ($uri =~ m,^[^:]+://,) { + # Nothing to do as the input is already an URI + } + elsif (! File::Spec->file_name_is_absolute($uri)) { + my $file = File::Spec->catfile(getcwd(), $uri); + $uri = filename_to_uri($file, undef); + } + else { + $uri = filename_to_uri($uri, undef); + } + + # Create the main pipeline and GUI elements + my ($pipeline, $player, $sink) = create_pipeline(); + my ($window, $canvas, $buttons) = create_widgets(); + + $player->set(uri => $uri); + + # Buttons used to control the playback + add_button($buttons, 'gtk-media-play', sub { + $sink->set_xwindow_id($canvas->window->get_xid); + $pipeline->set_state('playing'); + }); + + add_button($buttons, 'gtk-media-stop', sub { + $pipeline->set_state('ready'); + }); + + # Run the program + Gtk2->main(); + + # Cleanup + $pipeline->set_state('null'); + return 0; +} + + +sub create_pipeline { + my $pipeline = GStreamer::Pipeline->new('pipeline'); + + # The pipeline elements + my ($player, $sink) = GStreamer::ElementFactory->make( + playbin => 'player', + xvimagesink => 'sink', + ); + + $pipeline->add($player); + $player->link($sink); + + $player->set('video-sink', $sink); + $sink->set('force-aspect-ratio', TRUE); + + return ($pipeline, $player, $sink); +} + + +sub create_widgets { + # Create the widgets + my $window = Gtk2::Window->new(); + $window->set_title("Gst video test"); + + # This is where the video will be displayed + my $canvas = Gtk2::DrawingArea->new(); + $canvas->set_size_request(300, 150); + + my $vbox = Gtk2::VBox->new(FALSE, 0); + $vbox->pack_start($canvas, TRUE, TRUE, 0); + + # Prepare a box that will hold the playback controls + my $buttons = Gtk2::HButtonBox->new(); + $vbox->pack_start($buttons, FALSE, TRUE, 0); + + $window->add($vbox); + + $window->signal_connect(delete_event => sub { + Gtk2->main_quit(); + return Glib::SOURCE_CONTINUE; + }); + + $window->show_all(); + + return ($window, $canvas, $buttons); +} + + +sub add_button { + my ($box, $stock, $callback) = @_; + my $button = Gtk2::Button->new_from_stock($stock); + $button->signal_connect(clicked => $callback); + $box->add($button); + $button->show_all(); +} -- 1.6.0.4
Subject: Re: [rt.cpan.org #48069]
Date: Mon, 01 Mar 2010 22:10:45 +0100
To: bug-GStreamer-Interfaces [...] rt.cpan.org
From: Torsten Schoenfeld <kaffeetisch [...] gmx.de>
On 21.07.2009 21:16, Emmanuel Rodriguez via RT wrote: Show quoted text
> This patch creates a new example program that demonstrates how to write > a real video player in Perl. The program is far from being completed but > it works. Hopefully someone else will make a real video player in Perl! > > The patch is also available through my git clone at > http://github.com/potyl/perl-GStreamer-Interfaces/blob/df399e0dce557f88d44a53262e44cb914293ba62/examples/gst-video-player.pl
I don't know which predates which, but we now have a video player example in the repository already: <http://git.gnome.org/browse/perl-GStreamer-Interfaces/tree/examples/gst-video-sample.pl>. Your new program seems to do more: namely, it plays actual video files instead of using just a test source. So should your new code just replace the old?
On Mon Mar 01 16:12:18 2010, TSCH wrote: Show quoted text
> On 21.07.2009 21:16, Emmanuel Rodriguez via RT wrote:
> > This patch creates a new example program that demonstrates how to
> write
> > a real video player in Perl. The program is far from being completed
> but
> > it works. Hopefully someone else will make a real video player in
> Perl!
> > > > The patch is also available through my git clone at > > http://github.com/potyl/perl-GStreamer-
> Interfaces/blob/df399e0dce557f88d44a53262e44cb914293ba62/examples/gst- > video-player.pl > > I don't know which predates which, but we now have a video player > example in the repository already: > <http://git.gnome.org/browse/perl-GStreamer- > Interfaces/tree/examples/gst-video-sample.pl>. > Your new program seems to do more: namely, it plays actual video > files > instead of using just a test source. So should your new code just > replace the old?
gst-video-sample.pl was my first attempt at getting a video embedded in a Perl script. With your help I was able to get it working. While this script is a good example it uses the input source videotestsrc which is not too fun. So I forked a new example (gst-video-player) that makes a real player that can play any input file or URI. If one example has to be kept then gst-video-player is probably the best. Otherwise you can always ship both as disk space is quite cheap today :)
On Tue Mar 02 03:31:20 2010, POTYL wrote: Show quoted text
> If one example has to be kept then gst-video-player is probably the > best. Otherwise you can always ship both as disk space is quite cheap > today :)
I've now replaced the old example with your new code: <http://git.gnome.org/browse/perl-GStreamer-Interfaces/commit/?id=b8010826>. Thanks for the code.