【问题标题】:Convert gst-launch command to Python program将 gst-launch 命令转换为 Python 程序
【发布时间】:2011-08-02 12:18:12
【问题描述】:

如何使用 PyGST 模块在 Python 程序中实现以下 gst-launch 命令?

gst-launch-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

【问题讨论】:

    标签: python pipeline gstreamer gst-launch


    【解决方案1】:

    您不能真正将“gst-launch 语法”转换为“python 语法”。

    您可以使用 gst.element_factory_make() 和朋友“手动”(以编程方式)创建相同的管道,然后自己链接所有内容。

    或者你只是使用类似的东西:

    管道 = gst.parse_launch ("v4l2src ! .....")

    您可以为管道字符串中的元素命名,例如v4l2src 名称=mysrc ! ...然后使用

    从管道中检索元素

    src = pipeline.get_by_name ('mysrc')

    然后在其上设置属性,例如:

    src.set_property("位置", 文件路径)

    【讨论】:

    • 感谢蒂姆的回复,但我一直在寻找相同的方法,即程序化转换(不使用任何工具)。
    【解决方案2】:

    看看我对gst 模块的封装:https://github.com/vmlaker/gstwrap

    请注意,分支和复用是通过仔细链接元素来定义的。您的特定管道是:

    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.')
    

    【讨论】:

      猜你喜欢
      • 2011-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-17
      相关资源
      最近更新 更多