Created
April 28, 2014 20:37
-
-
Save vividsnow/06e8eb21165d6f01a8bf to your computer and use it in GitHub Desktop.
perl gstreamer-1.0 example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use v5.18; | |
use warnings; | |
use Glib qw(TRUE FALSE); | |
use Glib::Object::Introspection; | |
my $loop = Glib::MainLoop->new; | |
map { Glib::Object::Introspection->setup(basename => $_, version => '1.0', package => 'GStreamer') } qw'Gst GstBase'; | |
GStreamer::init([$0, @ARGV]); | |
say 'GStreamer ', join '.', GStreamer::version(); | |
my $pipeline = GStreamer::Pipeline->new('video-example'); | |
my ($source, $flt, $sink) = map GStreamer::ElementFactory::make(@$_), | |
[qw'videotestsrc source'], | |
[qw'capsfilter flt'], | |
[qw'ximagesink sink']; | |
sub gval ($$) { Glib::Object::Introspection::GValueWrapper->new('Glib::'.ucfirst($_[0]) => $_[1]) } # GValue wrapper shortcut | |
$flt->set(caps => map { | |
$_->set_value(width => gval int => 800); | |
$_->set_value(height => gval int => 600); | |
$_; | |
} GStreamer::Caps->new_empty_simple('video/x-raw')); | |
map $pipeline->add($_), $source, $flt, $sink; | |
map { state $p; $p->link($_) if $p; $p = $_ } $source, $flt, $sink; | |
my $bus = $pipeline->get_bus; | |
$bus->add_signal_watch; | |
$bus->signal_connect(message => sub { | |
my ($bus, $message) = @_; | |
$loop->quit if $message->type eq 'eos'; | |
TRUE }); | |
$pipeline->set_state ('playing'); | |
$loop->run; | |
$pipeline->set_state ('null'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment