v4l2src: recalculate timestamp to avoid getting multiple 0 timestamps
When encoding with v4l2src and muxing the encoded file, baseparse will mark current buffer's pts as GST_CLOCK_TIME_NONE if it is equal to prev_pts, which causes muxer to report error "Buffer has no PTS". To avoid this, need to retry calculating pts if clock running time is lower than the buffer timestamp delay.
Pipeline:
gst-launch-1.0 v4l2src device=/dev/video2 num-buffers=60 ! video/x-raw,width=1280,height=720,framerate=30/1 ! v4l2h264enc ! h264parse ! queue ! mux. pulsesrc num-buffers=86 blocksize=4096 ! audio/x-raw, rate=44100, channels=2 ! queue ! avenc_mp2 ! mpegaudioparse ! queue ! mux. qtmux name=mux ! filesink location=v4l2src.qtmux
And here is the log:
0:00:00.339980985 1493013 0xffffa00011f0 DEBUG v4l2src gstv4l2src.c:1291:gst_v4l2src_create: ts: 16:54:48.650755000 now 16:54:48.676332878 delay 0:00:00.025577878
0:00:00.340053610 1493013 0xffffa00011f0 LOG v4l2src gstv4l2src.c:1328:gst_v4l2src_create: sync to 0:00:00.033333333 out ts 0:00:00.000000000
0:00:00.377897724 1493013 0xffffa00011f0 DEBUG v4l2src gstv4l2src.c:1291:gst_v4l2src_create: ts: 16:54:48.667423000 now 16:54:48.714266993 delay 0:00:00.046843993
0:00:00.377979016 1493013 0xffffa00011f0 LOG v4l2src gstv4l2src.c:1328:gst_v4l2src_create: sync to 0:00:00.066666666 out ts 0:00:00.000000000
0:00:00.379099021 1493013 0xffffa00011f0 DEBUG v4l2src gstv4l2src.c:1291:gst_v4l2src_create: ts: 16:54:48.684115000 now 16:54:48.715499039 delay 0:00:00.031384039
0:00:00.379155563 1493013 0xffffa00011f0 LOG v4l2src gstv4l2src.c:1328:gst_v4l2src_create: sync to 0:00:00.099999999 out ts 0:00:00.007684961
ERROR: from element /GstPipeline:pipeline0/GstQTMux:mux: Could not multiplex stream.
Additional debug info:
/usr/src/debug/gstreamer1.0-plugins-good/1.22.5.imx-r0/gst/isomp4/gstqtmux.c(5410): gst_qt_mux_add_buffer (): /GstPipeline:pipeline0/GstQTMux:mux:
Buffer has no PTS.
Execution ended after 0:00:00.163228257