Advertisement
Guest User

Untitled

a guest
Jan 7th, 2011
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.68 KB | None | 0 0
  1. import gst, gobject
  2.  
  3. cap = 'video/x-raw-yuv,format=(fourcc)I420,width=640,height=480,framerate=(fraction)30000/1001'
  4.  
  5. def get_src(pattern):# creates videotestsrc->capfilter bin in a gnlsource
  6.     bin  = gst.Bin()
  7.     src  = gst.element_factory_make("videotestsrc")
  8.     src.props.pattern = pattern
  9.     caps = gst.element_factory_make("capsfilter")
  10.     caps.props.caps = gst.Caps(cap)
  11.     bin.add(src, caps)
  12.     src.link(caps)
  13.     bin.add_pad(gst.GhostPad("src", caps.get_pad("src")))
  14.     gsrc = gst.element_factory_make("gnlsource")
  15.     gsrc.add(bin)
  16.     return gsrc
  17.  
  18. # create two gnlsources and make them play different patterns
  19. gsrc1 = get_src("smpte")
  20. gsrc2 = get_src("ball")
  21.  
  22. # set the two gnlsources to play serially
  23. dur = 3
  24. gsrc1.props.start          =   0 * gst.SECOND
  25. gsrc1.props.duration       = dur * gst.SECOND
  26. gsrc1.props.media_start    =   0 * gst.SECOND
  27. gsrc1.props.media_duration = dur * gst.SECOND
  28. gsrc2.props.start          = dur * gst.SECOND
  29. gsrc2.props.duration       = dur * gst.SECOND
  30. gsrc2.props.media_start    =   0 * gst.SECOND
  31. gsrc2.props.media_duration = dur * gst.SECOND
  32.  
  33. # create a gnlcomposition to hold the two sources
  34. comp  = gst.element_factory_make("gnlcomposition")
  35. comp.add(gsrc1, gsrc2)
  36.  
  37. # put a caps filter on the output of the gnlcomposition
  38. caps  = gst.element_factory_make("capsfilter")
  39. caps.props.caps = gst.Caps(cap)
  40.  
  41. # create the pipeline
  42. pipeline = gst.Pipeline()
  43. pipeline.add(comp, caps)
  44.  
  45. # now create a backend. There are two different backend options. Change
  46. # if state to True to enable an X11 backend or set it to false to enable
  47. # an encoder backend.
  48. if 0:
  49.     sink = gst.element_factory_make("autovideosink")
  50.     pipeline.add(sink)
  51.     caps.link(sink)
  52. else:
  53.     enc  = gst.element_factory_make("ffenc_mpeg4")
  54.     #enc  = gst.element_factory_make("x264enc")
  55.     mux  = gst.element_factory_make("mp4mux")
  56.     sink = gst.element_factory_make("filesink")
  57.     sink.props.location = "test.mp4"
  58.     pipeline.add(enc, mux, sink)
  59.     gst.element_link_many(caps, enc, mux, sink)
  60.  
  61. # setup the gnlcomposition to link to the capsfilter when its pads get created
  62. def on_pad(comp, pad, caps):
  63.     pad.link(caps.get_compatible_pad(pad, pad.get_caps()))
  64. comp.connect("pad-added", on_pad, caps)
  65.  
  66. # now run the pipeline
  67. loop = gobject.MainLoop(is_running=True)
  68. gobject.threads_init()
  69. bus = pipeline.get_bus()
  70. bus.add_signal_watch()
  71. def on_message(bus, message, loop):
  72.     if message.type == gst.MESSAGE_EOS:
  73.         loop.quit()
  74.     elif message.type == gst.MESSAGE_ERROR:
  75.         print message
  76.         loop.quit()
  77. bus.connect("message", on_message, loop)
  78. pipeline.set_state(gst.STATE_PLAYING)
  79. loop.run()
  80. pipeline.set_state(gst.STATE_NULL)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement