mpegtsmux not generating proper segment files
Describe your issue
We are using the following gstreamer pipeline to generate HLS playlists from an RTSP source:
gst-launch-1.0 -e rtspsrc location=<stream url> is-live=true \
! rtph264depay wait-for-keyframe=true request-keyframe=true \
! h264parse \
! splitmuxsink max-size-time=10000000000 location=video%02d.ts send-keyframe-requests=true muxer=mpegtsmux
However, the generated .ts
files do not seem to start with keyframes, as reported by ffprobe
. This issue does not happen if we use the default splitmuxsink
muxer (mp4mux
as per the docs), but obviously the generated files are of a different format.
Expected Behavior
All generated segment files start with keyframes.
Observed Behavior
When running ffprobe -i
on the generated files, a subset of them reports the following:
[h264 @ 0x1401056a0] no frame!
[h264 @ 0x1401056a0] non-existing PPS 0 referenced
We found that a similar issue has been reported on StackOverflow (link) using a slightly different pipeline, which we were able to reproduce:
gst-launch-1.0 -e rtspsrc location=<stream url> \
! rtph264depay wait-for-keyframe=true request-keyframe=true \
! h264parse \
! mpegtsmux \
! multifilesink location=/data/test%05d.ts aggregate-gops=true max-file-duration=10000000000 next-file=key-frame
The common factor between both is mpegtsmux
.
It also seems that for those bad segments that don't start with a keyframe, the previous segment ends with a keyframe, so it seems like an off-by-one error.
Setup
- Operating System: MacOS and Linux
- Device: Computer and Virtual Machine
- GStreamer Version: 1.22.2
Steps to reproduce the bug
- open terminal
- run either of the aforementioned gstreamer commands
- wait for a few minutes to gather several segment files
- run
ffprobe -i <file.ts>
on each file to see thenon-existing PPS 0 referenced
error
How reproducible is the bug?
Very consistently.
Solutions you have tried
Applied the wait-for-keyframe=true request-keyframe=true
settings to the rtph264depay
element, and the aggregate-gops=true next-file=key-frame
settings to multifilesink
as per the docs.