Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void record (string outputpath){
- pipeline = new Pipeline ("screencast-pipe");
- muxer = ElementFactory.make ("matroskamux", "mux");
- dynamic Element sink = ElementFactory.make ("filesink", "sink");
- //video bin
- var videobin = new Gst.Bin ("videobin");
- dynamic Element vsrc = ElementFactory.make ("ximagesrc", "vsrc");
- dynamic Element colorspace = ElementFactory.make ("ffmpegcolorspace", "color");
- dynamic Element vencode = ElementFactory.make ("diracenc", "vencode");
- videobin.add_many (vsrc, colorspace, vencode);
- videobin.link_many (vsrc, colorspace, vencode);
- //audio bin
- var audiobin = new Gst.Bin ("audiobin");
- dynamic Element asrc = ElementFactory.make ("autoaudiosrc", "asrc");
- dynamic Element aconv = ElementFactory.make ("audioconvert", "aconv");
- dynamic Element aresample = ElementFactory.make ("audioresample", "aresample");
- dynamic Element audiorate = ElementFactory.make ("audiorate", "arate");
- dynamic Element aencode = ElementFactory.make ("vorbisenc", "aencode");
- audiobin.add_many (asrc, aconv, aresample, audiorate, aencode);
- audiobin.link_many (asrc, aconv, aresample, audiorate, aencode);
- //configure
- sink.set ("location", outputpath);
- if (pipeline==null||muxer==null||sink==null||videobin==null||vsrc==null||colorspace==null||
- vencode==null||audiobin==null||asrc==null||aconv==null||aresample==null||audiorate==null||
- aencode==null){
- stderr.printf ("Error: Elements weren't made correctly!\n");
- }
- pipeline.add_many (videobin, muxer, sink);//audiobin
- //videobin.get_static_pad ("src_%d").link(mux.get_request_pad ("video_%d"));
- videobin.add_pad (new GhostPad ("src", muxer.get_request_pad ("video_%d")));
- audiobin.add_pad (new GhostPad ("src", muxer.get_request_pad ("audio_%d")));
- muxer.link (sink);
- pipeline.get_bus ().add_watch (bus_message_cb);
- pipeline.set_state (State.PLAYING);
- Timeout.add (500, (GLib.SourceFunc) update_slide);
- }
- private bool bus_message_cb (Gst.Bus bus, Message msg){
- switch (msg.type){
- case Gst.MessageType.ERROR:
- GLib.Error err; string debug;
- msg.parse_error (out err, out debug);
- print ("Error: %s\n", err.message);
- pipeline.set_state (State.NULL);
- break;
- case Gst.MessageType.EOS:
- print ("Finished, why??\n");
- pipeline.set_state (State.NULL);
- break;
- case Gst.MessageType.STATE_CHANGED:
- Gst.State oldstate; Gst.State newstate; Gst.State pending;
- msg.parse_state_changed (out oldstate, out newstate, out pending);
- print ("state changed: %s->%s:%s\n", oldstate.to_string (), newstate.to_string (), pending.to_string ());
- break;
- default:
- break;
- }
- return true;
- }
- private void pad_added_cb (Pad pad){
- var sinkpad = muxer.get_request_pad ("video_%d");
- if (sinkpad == null){
- Caps caps = pad.get_caps_reffed ();
- Signal.emit_by_name (muxer, "request-pad", caps, out sinkpad);
- }
- if (sinkpad == null){
- stderr.printf ("Couldn't get an encoding channel for pad ...\n");
- }
- var pad_link_ok = (pad.link (sinkpad) == PadLinkReturn.OK);
- if (!pad_link_ok) {
- warning ("Failed to link pad '%s' to '%s'", pad.name, sinkpad.name);
- }
- return;
- }
Add Comment
Please, Sign In to add comment