[perl-GStreamer-Interfaces] Turn the video sample into a video player



commit b8010826d66282abdebeeb77e4f3de2de5e7bf84
Author: Emmanuel Rodriguez <emmanuel.rodriguez gmail com>
Date:   Tue Mar 2 22:51:00 2010 +0100

    Turn the video sample into a video player
    
    Instead of simply using a test source, make it play real video files.  Rename
    it consequently.
    
    Signed-off-by: Torsten Schönfeld <kaffeetisch gmx de>

 .../{gst-video-sample.pl => gst-video-player.pl}   |   62 ++++++++++++++-----
 1 files changed, 45 insertions(+), 17 deletions(-)
---
diff --git a/examples/gst-video-sample.pl b/examples/gst-video-player.pl
similarity index 53%
rename from examples/gst-video-sample.pl
rename to examples/gst-video-player.pl
index cf9320a..9a255c3 100644
--- a/examples/gst-video-sample.pl
+++ b/examples/gst-video-player.pl
@@ -2,40 +2,64 @@
 
 =head1 NAME
 
-gst-video-sample.pl - Embed a video in a Gtk2 window
+gst-video-player.pl - Video player made in Perl
 
 =head1 SYNOPSIS
 
-perl gst-video-sample.pl
+gst-video-player.pl video
 
-=head1 DESCRIPTION
+Where I<video> is the path to a video file or an URI to a video.
+
+Play a video that's available locally:
+
+	perl gst-video-player.pl film.ogv
+
+Stream a video from a website:
 
-This program shows how to embed a video in a Gtk2 window. The window is created
-by the program using Gtk2 and the video is decoded by Gstreamer. Both frameworks
-are linked together in order to create a minimalist video player.
+	perl gst-video-player.pl http://anon.nasa-global.edgesuite.net/qt.nasa-global/ksc/ksc_071509_sts127_launch_480i.mov
 
-=head1 AUTHOR
+=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.
 
-Vala code from http://live.gnome.org/Vala/GStreamerSample ported to Perl.
+The original Vala code from http://live.gnome.org/Vala/GStreamerSample was ported to Perl and adjusted to play arbitrary video files.
 
 =cut
 
 use strict;
 use warnings;
 
-use Glib qw(TRUE FALSE);
+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, $sink) = create_pipeline();
+	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 {
@@ -60,16 +84,19 @@ sub main {
 sub create_pipeline {
 	my $pipeline = GStreamer::Pipeline->new('pipeline');
 
-	# The pipeline's elements
-	my ($src, $sink) = GStreamer::ElementFactory->make(
-		videotestsrc => 'source',
-		xvimagesink  => 'sink',
+	# The pipeline elements
+	my ($player, $sink) = GStreamer::ElementFactory->make(
+		playbin     => 'player',
+		xvimagesink => 'sink',
 	);
 
-	$pipeline->add($src, $sink);
-	$src->link($sink);
+	$pipeline->add($player);
+	$player->link($sink);
 
-	return ($pipeline, $sink);
+	$player->set('video-sink', $sink);
+	$sink->set('force-aspect-ratio', TRUE);
+
+	return ($pipeline, $player, $sink);
 }
 
 
@@ -95,6 +122,7 @@ sub create_widgets {
 		Gtk2->main_quit();
 		return Glib::SOURCE_CONTINUE;
 	});
+
 	$window->show_all();
 
 	return ($window, $canvas, $buttons);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]