v4l2h264dec: Raspberry Pi4 fails switching to playing state
Describe your issue
When starting and stopping an RTSP video stream in a loop, video playback stops working after a few loops.
Expected Behavior
When replacing v4l2h264dec
with avdec_h264
then it keeps going without issues (tested 1000 loops with no issues).
I would expect v4l2h264dec
to work the same.
Observed Behavior
After 4 - 5 loops pipeline.set_state(Gst.State.PLAYING)
returns failure. When not exiting the script with return
statement, then it just shows an empty window:
Setup
- Operating System: Raspberry Pi OS 12 (bookworm)
- Device: SBC
- GStreamer Version: 1.22.0-2
- Command line: Script to reproduce this issue:
import time
import subprocess
import gi
gi.require_version("Gst", "1.0")
gi.require_version("GstApp", "1.0")
from gi.repository import Gst, GstApp
# public RTSP stream for testing purposes
URL = "rtsp://31.160.161.51/axis-media/media.amp"
Gst.init(None)
def mainLoop():
loopcount = 0
while True:
loopcount += 1
print("LOOP", loopcount)
pipeline = Gst.parse_launch(
f"rtspsrc location={URL} latency=0"
" ! rtph264depay"
" ! h264parse"
" ! v4l2h264dec"
# using this instead of v4l2h264dec works without issues
#" ! avdec_h264"
" ! videoscale"
" ! videoconvert"
" ! video/x-raw, width=854, height=480"
" ! xvimagesink"
)
assert pipeline, "failed to create pipeline"
print("starting video")
ret = pipeline.set_state(Gst.State.PLAYING)
print("RET:", ret)
if ret == Gst.StateChangeReturn.FAILURE:
print("ERROR: failed to set pipeline to PLAYING")
pipeline = None
return
print("waiting 10 seconds")
time.sleep(10)
print("stopping video")
pipeline.set_state(Gst.State.NULL)
pipeline = None
print("waiting 1 second")
time.sleep(1)
try:
mainLoop()
except Exception as e:
print(e)
Steps to reproduce the bug
- Pi4 with latest Bookworm Pi OS 12
- Boot into the GUI interface (X or Wayland does not matter)
- install python3 and relevant gstreamer packages
- run the script above (RTSP URL is public, so it should just work without any adjustments)
How reproducible is the bug?
Always after the 4th or 5th loop using the script above.
Screenshots if relevant
See above.
Solutions you have tried
- I have tried updating kernel and firmware to the latest using
rpi-update
with same results. - As already stated, when replacing
v4l2h264dec
withavdec_h264
it works as expected, so the problem has to be with that module.
Related non-duplicate issues
Additional Information
I am not sure if this here is the right place to report this as this could also be caused by PI kernel or firmware. However dmesg
does not show anything, so it is not exactly comparable to other similar issues reported.
EDIT: While this example might be a bit weird, my use case currently is a video wall which switches the displayed stream every 15 minutes. This currently stops working after 1 hour, which also indicates the mentioned 4 - 5 loops.