Invalid PTS from v4l2 mjpeg source [SOLVED]

Dave Blanchard dave at
Wed Nov 16 18:06:41 UTC 2022

Fixed this problem by adding 'jpegparse' before jpegdec/avdec_mjpeg. Working great now at 30 fps with no errors. Also, very little stream latency compared to my previous ffmpeg setup; it's now essentially realtime video. Now if gstreamer will work continuously over weeks or months without the occasional random crash like ffmpeg, I'll be very happy!

Thank you!

Begin forwarded message:

Date: Wed, 16 Nov 2022 11:40:39 -0600
From: Dave Blanchard via gstreamer-devel <gstreamer-devel at>
To: gstreamer-devel at
Cc: Dave Blanchard <dave at>
Subject: Invalid PTS from v4l2 mjpeg source

Hi all, I'm trying to use gstreamer to capture video from a MJPEG surveillance card. There's one last snag to get through to get this working right.

With ffmpeg I use the following command to stream the video to an HLS endpoint, which then plays perfectly at 30 fps with no trouble:

ffmpeg -r 30 -video_size 704x480 -i /dev/video1 -c:v mpeg2video -b:v 8M -f mpegts http://localhost:5000/publish/camera1

With gstreamer I'm using this command:

gst-launch-1.0 v4l2src device=/dev/video1 ! "image/jpeg,width=704,height=480,framerate=30/1" ! jpegdec [or avdec_mjpeg] ! videoconvert ! avenc_mpeg2video bitrate=8192 threads=0 ! mpegtsmux ! srtsink uri=srt://:5000 latency=0

I'm able to play the resulting video, but it seems about half of the frames are being dropped, and I'm getting a steady stream of PTS errors on the console for every other frame:


[mpeg2video @ 0x259b740] Invalid pts (108003372) <= last (108003372)
[mpeg2video @ 0x259b740] Invalid pts (108003374) <= last (108003374)
[mpeg2video @ 0x259b740] Invalid pts (108003376) <= last (108003376)
[mpeg2video @ 0x259b740] Invalid pts (108003378) <= last (108003378)


Seems DTS=PTS, which is wrong.

Weirdly, every once in a while these errors will stop, and the video will play perfectly for a moment at 30 fps, until the errors begin again and it's back to 15 real fps.

Can anyone give me a clue how to fix this? Ideally on the command line without any coding, although I can do that as a last resort. I've searched and searched and can't figure this out.

Thank you!

Dave Blanchard <dave at>
Dave Blanchard <dave at>

More information about the gstreamer-devel mailing list