Skip to content

Instantly share code, notes, and snippets.

@vividsnow
Created April 28, 2014 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vividsnow/06e8eb21165d6f01a8bf to your computer and use it in GitHub Desktop.
Save vividsnow/06e8eb21165d6f01a8bf to your computer and use it in GitHub Desktop.
perl gstreamer-1.0 example
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