Complete crash due to v4l2 allocator/bufferpool
Hello,
I'm working on a Raspberry Pi 4 on a simple pipeline to decode a h264 stream from an rtsp-src and save the re-encoded h264 stream to a file.
Everything works perfectly fine until a certain amount of time (20 seconds - 15 minutes) where suddenly a full crash occurs caused by v4l2 allocator/bufferpool.
v4l2allocator gstv4l2allocator.c:1247:gst_v4l2_allocator_qbuf:<v4l2h264dec0:pool:src:allocator> failed queueing buffer 0: Invalid argument
v4l2bufferpool gstv4l2bufferpool.c:1112:gst_v4l2_buffer_pool_qbuf:<v4l2h264dec0:pool:src> could not queue a buffer 0
I have attached my python code and a complete debug log including the crash. The index of the failing buffer is not always the same between the runs. I hope someone can help me with this issue :)
Best Regards,
Matthias
import os, gi
gi.require_version("Gst", "1.0")
from gi.repository import GObject, Gst
class Config:
def __init__(self):
self.RTSP_URL = ''
self.H264_ENC = 'omxh264enc'
# self.H264_DEC = 'v4l2h264enc' # same error
# self.H264_DEC = 'omxh264dec' # not working
self.H264_DEC = 'v4l2h264dec'
config = Config()
Gst.init(None)
pipeline = Gst.Pipeline()
src = Gst.ElementFactory.make('rtspsrc', None)
src.set_property('location', config.RTSP_URL)
src.set_property('latency', 0)
pipeline.add(src)
vdepay = Gst.ElementFactory.make('rtph264depay', None)
pipeline.add(vdepay)
def on_pad_added(element, pad):
string = pad.query_caps(None).to_string()
print('DEBUG', 'Found stream: %s' % string)
if string.startswith('application/x-rtp'):
if 'media=(string)video' in string:
pad.link(vdepay.get_static_pad('sink'))
print('INFO', 'Video connected')
vparser = Gst.ElementFactory.make('h264parse', None)
pipeline.add(vparser)
vdecode = Gst.ElementFactory.make(config.H264_DEC)
vdecode.set_property('capture-io-mode', 4)
pipeline.add(vdecode)
vqueue = Gst.ElementFactory.make('queue')
pipeline.add(vqueue)
vencode = Gst.ElementFactory.make(config.H264_ENC)
vencode.set_property('control-rate', 'variable') # constant
vencode.set_property('target-bitrate', 4500000)
pipeline.add(vencode)
vparser2 = Gst.ElementFactory.make('h264parse')
pipeline.add(vparser2)
vqueue2 = Gst.ElementFactory.make("queue")
pipeline.add(vqueue2)
flvmux = Gst.ElementFactory.make("flvmux")
flvmux.set_property("streamable", True)
pipeline.add(flvmux)
filesink = Gst.ElementFactory.make('filesink')
filesink.set_property('location', 'output.flv')
pipeline.add(filesink)
# fakesink = Gst.ElementFactory.make('fakesink')
# pipeline.add(fakesink)
src.connect('pad-added', on_pad_added) # src -> vdepay
vdepay.link(vparser)
vparser.link(vdecode)
vdecode.link(vqueue)
vqueue.link(vencode)
vencode.link(vparser2)
vparser2.link(vqueue2)
vqueue2.link(flvmux)
flvmux.link(filesink)
# Start pipeline.
pipeline.set_state(Gst.State.PLAYING)
import time
while True:
time.sleep(10)