Last active
April 12, 2020 04:15
-
-
Save edoput/77aa7725d4a5b44d8b98 to your computer and use it in GitHub Desktop.
an approach to Gstreamer with Vala
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
using Gst; | |
public int main(string args[]) | |
{ | |
Gst.init(ref args); | |
Gst.Element screen = Gst.ElementFactory.make ("ximagesrc", "source"); | |
Gst.Element color_convert = Gst.ElementFactory.make ("videoconvert", "convert"); | |
Gst.Element encoder = Gst.ElementFactory.make ("x264enc","encoder"); | |
Gst.Element flv_muxer = Gst.ElementFactory.make ("flvmux", "muxer"); | |
Gst.Element file = Gst.ElementFactory.make ("filesink", "sink"); | |
if (screen == null || color_convert == null || encoder == null || flv_muxer == null || file == null) { | |
stderr.puts ("Couldn't create a element:\n"); | |
if (screen == null) stderr.puts ("screen"); | |
if (color_convert == null) stderr.puts ("color converter\n"); | |
if (encoder == null) stderr.puts ("x264 encoder"); | |
if (flv_muxer== null) stderr.puts ("flv muxer"); | |
if (file == null) stderr.puts ("file sink"); | |
return -1; | |
} | |
// create a pipeline | |
Pipeline pipe = new Pipeline ("test"); | |
pipe.add_many ( | |
screen, | |
color_convert, | |
encoder, | |
flv_muxer, | |
file); | |
// get a bus before setting playing state | |
Bus bus = pipe.get_bus (); | |
Message msg = bus.timed_pop_filtered (Gst.CLOCK_TIME_NONE, Gst.MessageType.ERROR | Gst.MessageType.EOS); | |
if (msg != null) | |
{ | |
switch (msg.type) | |
{ | |
case Gst.MessageType.ERROR: | |
break; | |
case Gst.MessageType.EOS: | |
stdout.puts ("Stream ended"); | |
break; | |
default: | |
assert_not_reached(); | |
} | |
} | |
// various check | |
bool pipe_link = screen.link_many ( | |
color_convert, | |
encoder, | |
flv_muxer, | |
file); | |
if ( !pipe_link ) | |
{ | |
stderr.puts ("Could'n link some elements\n"); | |
return -1; | |
} | |
// set parameters from ximagesrc | |
// screen.set ("use-damage", true); | |
screen.set ("num-buffers", 100); | |
// screen.set ("framerate", 25/1); | |
screen.set ("endx", 50); | |
screen.set ("endy", 50); | |
file.set ("location", "./test.flv"); | |
Gst.StateChangeReturn ret = pipe.set_state (Gst.State.PLAYING); | |
if (ret == Gst.StateChangeReturn.FAILURE) { | |
stderr.puts ("Couldn't start pipeline\n"); | |
return -1; | |
} | |
else if ( ret == Gst.StateChangeReturn.SUCCESS) | |
{ | |
stdout.puts ("Pipeline is playing\n"); | |
} | |
pipe.set_state (Gst.State.NULL); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment