开发者

Convert gst-launch command to Python program

开发者 https://www.devze.com 2023-03-25 19:55 出处:网络
How do I implement the following gst-launch command into a Python program using the PyGST module? gst-laun开发者_JAVA百科ch-0.10 v4l2src ! \\

How do I implement the following gst-launch command into a Python program using the PyGST module?

gst-laun开发者_JAVA百科ch-0.10 v4l2src ! \
'video/x-raw-yuv,width=640,height=480,framerate=30/1' ! \
tee name=t_vid ! \
   queue ! \
   videoflip method=horizontal-flip ! \
   xvimagesink sync=false \
t_vid. ! \
   queue ! \
   videorate ! \
   'video/x-raw-yuv,framerate=30/1' \
   ! queue ! \
mux. \
   alsasrc ! \
   audio/x-raw-int,rate=48000,channels=2,depth=16 ! \
   queue ! \
   audioconvert ! \
   queue ! \
mux. avimux name=mux ! \
   filesink location=me_dancing_funny.avi


You can't really convert "gst-launch syntax" to "python syntax".

Either you create the same pipeline 'manually' (programmatically) using gst.element_factory_make() and friends, and link everything yourself.

Or you just use something like:

pipeline = gst.parse_launch ("v4l2src ! ..... ")

You can give elements in your pipeline string names with e.g. v4l2src name=mysrc ! ... and then retrieve the element from the pipeline with

src = pipeline.get_by_name ('mysrc')

and then set properties on it like:

src.set_property("location", filepath)


Take a look at my wrapper of the gst module: https://github.com/vmlaker/gstwrap

Note the branching and muxing is defined by careful linking of the elements. Your particular pipeline is then:

from gstwrap import Element, Pipeline

ee = (

    # From src to sink [0:5]
    Element('v4l2src'),
    Element('capsfilter', [('caps','video/x-raw-yuv,framerate=30/1,width=640,height=360')]),
    Element('tee', [('name', 't_vid')]),
    Element('queue'),
    Element('videoflip', [('method', 'horizontal-flip')]),
    Element('xvimagesink', [('sync', 'false')]),

    # Branch 1 [6:9]
    Element('queue'),
    Element('videorate'),
    Element('capsfilter', [('caps', 'video/x-raw-yuv,framerate=30/1')]),
    Element('queue'),

    # Branch 2 [10:15]
    Element('alsasrc'),
    Element('capsfilter', [('caps', 'audio/x-raw-int,rate=48000,channels=2,depth=16')]),
    Element('queue'),
    Element('audioconvert'),
    Element('queue'),

    # Muxing
    Element('avimux', [('name', 'mux')]),
    Element('filesink', [('location', 'me_dancing_funny.avi')]),
)

pipe = Pipeline()
for index in range(len(ee)):
    pipe.add(ee[index])

ee[0].link(ee[1])
ee[1].link(ee[2])
ee[2].link(ee[3])
ee[3].link(ee[4])
ee[4].link(ee[5])

# Branch 1
ee[2].link(ee[6])
ee[6].link(ee[7])
ee[7].link(ee[8])
ee[8].link(ee[9])

# Branch 2
ee[10].link(ee[11])
ee[11].link(ee[12])
ee[12].link(ee[13])
ee[13].link(ee[14])
ee[14].link(ee[15])

# Muxing
ee[9].link(ee[15])
ee[15].link(ee[16])

print(pipe)
pipe.start()
raw_input('Hit <enter> to stop.')
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号