Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Gstreamer qtdemux从appsrc读取,工作在可搜索模式,但不是随机访问_Python_Gstreamer - Fatal编程技术网

Python Gstreamer qtdemux从appsrc读取,工作在可搜索模式,但不是随机访问

Python Gstreamer qtdemux从appsrc读取,工作在可搜索模式,但不是随机访问,python,gstreamer,Python,Gstreamer,我有一个管道,其中qtdemix从appsrc读取其输入。当appsrc处于可搜索模式时,管道工作正常,但在随机访问模式下,它读取一组数据,然后抛出此错误: Error from demux0: This file contains no playable streams. Debug info: qtdemux.c(716): gst_qtdemux_post_no_playable_stream_error (): /GstPipeline:pipeline0/GstQTDemux:demu

我有一个管道,其中qtdemix从appsrc读取其输入。当appsrc处于可搜索模式时,管道工作正常,但在随机访问模式下,它读取一组数据,然后抛出此错误:

Error from demux0: This file contains no playable streams.
Debug info: qtdemux.c(716): gst_qtdemux_post_no_playable_stream_error (): /GstPipeline:pipeline0/GstQTDemux:demux0:
no known streams found
这是一个用Python编写的最小程序,演示了这一点。这里的管道仅由一个appsrc、一个qtdemux和一个fakesink组成

导入操作系统
导入gi
gi.require_版本('Gst','1.0')
gi.require_版本('GstApp','1.0')
gi.require_版本('GLib','2.0')
从gi.repository导入Gst、GstApp、GLib
添加def demux_pad_(元件,pad):
caps=pad.get_current_caps()
st=caps.get_结构(0)
如果不是st.get_name().startswith('video/'):
打印('忽略非视频流:{}'
.format(caps.to_string())
返回
打印('找到的视频流:{}'。格式(caps.to_string())
打印('linking demux…')
结果=pad.link(sink.get\u static\u pad('sink'))
如果有结果!=Gst.PadLinkReturn.OK:
打印('无法将解复用器链接到接收器')
返回
文件名='。/foo.mp4'
filesize=os.path.getsize(文件名)
文件偏移量=0
def src_需要_数据(src,大小):
全局文件偏移量
打印('接收信号:需要数据cur_offset={}'
'请求的大小={}总大小={}'
.format(文件偏移量、大小、文件大小))
如果文件偏移量+大小>文件大小:
打印('请求超出范围。已忽略')
返回
将open(filename,'rb')作为f:
f、 寻道(文件偏移量)
chunk=f.read(大小)
断言len(块)=大小
buf=Gst.Buffer.new_wrapped(块)
buf.offset=文件偏移量
buf.offset\u end=文件偏移量+大小-1
src.push_缓冲区(buf)
文件偏移量+=大小
def src_足够的_数据(src):
打印('接收到的信号:足够的数据')
def src_seek_数据(src,偏移量):
全局文件偏移量
打印('接收信号:查找数据偏移量={}'。格式(偏移量))
如果偏移量>=文件大小:
打印('搜索超出范围')
返回错误
文件偏移量=偏移量
返回真值
def on_消息(总线,消息):
mtype=message.type
如果mtype==Gst.MessageType.EOS:
打印('流结束')
elif mtype==Gst.MessageType.ERROR:
err,debug=message.parse_error()
打印({}:{}的错误。格式(message.src.get_name(),err.message))
打印('调试信息:{}'。格式(调试))
elif mtype==Gst.MessageType.WARNING:
err,debug=message.parse_warning()
打印({}:{}的警告)。格式(message.src.get_name(),err.message))
打印('调试信息:{}'。格式(调试))
返回真值
Gst.init()
loop=GLib.MainLoop()
管道=Gst.pipeline()
src=Gst.ElementFactory.make('appsrc','src0')
src.set_属性('format',Gst.format.BYTES)
src.set_属性('blocksize',10*1000000)
src.set_属性('max-bytes',20*1000000)
src.set_属性('min-percent',5)
src.set_属性('size',filesize)
src.set_属性('stream-type',GstApp.AppStreamType.RANDOM_访问)
src.set_属性('emit-signals',True)
connect('need-data',src\u need\u data)
connect('sound-data',src\u-sound\u-data)
src.connect('seek-data',src\u seek\u data)
demux=Gst.ElementFactory.make('qtdemux','demux0')
sink=Gst.ElementFactory.make('fakesink','sink0'))
对于[src、demux、sink]中的e:
管道.添加(e)
如果不是src.link(解复用器):
打印('无法将src链接到demux')
出口(1)
demux.connect('增加了pad',增加了demux\u pad\u)
总线=管道。获取_总线()
总线.添加信号\u手表()
总线连接(“消息”,在消息上)
管道。设置_状态(Gst.state.PLAYING)
loop.run()
如果我们改变这一行:

src.set\u属性('stream-type',GstApp.AppStreamType.RANDOM\u访问)
为此:

src.set\u属性('stream-type',GstApp.AppStreamType.SEEKABLE)
文件被读取到最后,我们得到“流结束”消息

在Ubuntu 20.04中使用Python 3.8.5和Gstreamer 1.16.2进行测试