Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import gst, gobject
- cap = 'video/x-raw-yuv,format=(fourcc)I420,width=640,height=480,framerate=(fraction)30000/1001'
- def get_src(pattern):# creates videotestsrc->capfilter bin in a gnlsource
- bin = gst.Bin()
- src = gst.element_factory_make("videotestsrc")
- src.props.pattern = pattern
- caps = gst.element_factory_make("capsfilter")
- caps.props.caps = gst.Caps(cap)
- bin.add(src, caps)
- src.link(caps)
- bin.add_pad(gst.GhostPad("src", caps.get_pad("src")))
- gsrc = gst.element_factory_make("gnlsource")
- gsrc.add(bin)
- return gsrc
- # create two gnlsources and make them play different patterns
- gsrc1 = get_src("smpte")
- gsrc2 = get_src("ball")
- # set the two gnlsources to play serially
- dur = 3
- gsrc1.props.start = 0 * gst.SECOND
- gsrc1.props.duration = dur * gst.SECOND
- gsrc1.props.media_start = 0 * gst.SECOND
- gsrc1.props.media_duration = dur * gst.SECOND
- gsrc2.props.start = dur * gst.SECOND
- gsrc2.props.duration = dur * gst.SECOND
- gsrc2.props.media_start = 0 * gst.SECOND
- gsrc2.props.media_duration = dur * gst.SECOND
- # create a gnlcomposition to hold the two sources
- comp = gst.element_factory_make("gnlcomposition")
- comp.add(gsrc1, gsrc2)
- # put a caps filter on the output of the gnlcomposition
- caps = gst.element_factory_make("capsfilter")
- caps.props.caps = gst.Caps(cap)
- # create the pipeline
- pipeline = gst.Pipeline()
- pipeline.add(comp, caps)
- # now create a backend. There are two different backend options. Change
- # if state to True to enable an X11 backend or set it to false to enable
- # an encoder backend.
- if 0:
- sink = gst.element_factory_make("autovideosink")
- pipeline.add(sink)
- caps.link(sink)
- else:
- enc = gst.element_factory_make("ffenc_mpeg4")
- #enc = gst.element_factory_make("x264enc")
- mux = gst.element_factory_make("mp4mux")
- sink = gst.element_factory_make("filesink")
- sink.props.location = "test.mp4"
- pipeline.add(enc, mux, sink)
- gst.element_link_many(caps, enc, mux, sink)
- # setup the gnlcomposition to link to the capsfilter when its pads get created
- def on_pad(comp, pad, caps):
- pad.link(caps.get_compatible_pad(pad, pad.get_caps()))
- comp.connect("pad-added", on_pad, caps)
- # now run the pipeline
- loop = gobject.MainLoop(is_running=True)
- gobject.threads_init()
- bus = pipeline.get_bus()
- bus.add_signal_watch()
- def on_message(bus, message, loop):
- if message.type == gst.MESSAGE_EOS:
- loop.quit()
- elif message.type == gst.MESSAGE_ERROR:
- print message
- loop.quit()
- bus.connect("message", on_message, loop)
- pipeline.set_state(gst.STATE_PLAYING)
- loop.run()
- pipeline.set_state(gst.STATE_NULL)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement