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