[FFmpeg-user] Help needed to work around incorrect DTS when capturing H264 from a Logitech C920
Peter Rabbitson
rabbit+list at rabbit.us
Mon Dec 15 17:46:51 CET 2014
I investigated more and was able to fully recreate the issue in a "lab
setting". It seems that the C920 is producing invalid PTS values in the
output H264 stream. What is, however, more interesting is that ffplay is
somehow able to compensate for it if "treated right".
My initial setup is running the following command and capturing video of
a high-speed timer running on my screen:
ffmpeg -r 30 -f v4l2 -s 1920x1080 -vcodec h264 -i
/dev/v4l/by-id/*HD_Pro_Webcam_C920* \
-c:v copy -f matroska - | \
tee stdin.mkv | \
strace -ttt -ff -o ffplay.trace -s 65536 ffplay -i -
The result is the (incomplete, no index at the end) stdin.mkv [1], a
perfect smooth video on my screen produced by ffplay, and a bunch of
tracefiles [2.1]. As described in the previous email [3], if I attempt
to play stdin.mkv with anything (including ffplay itself via `ffplay -i
stdin.mkv`) I get micro-freezes every ~2.5 sec as can be seen in the
playback of [1] on vimeo.
My questions:
1) The PTS of the stream is clearly mangled. If I look at it via ffprobe
and calculate the PTS differences I end up with [2.2]. Is there a way to
rewrite the PTS alone without recoding, using a stable clocksource? I
tried in various combinations the following options - nothing seem to
change the outcome (is it due to -c:v copy, affecting even input-side
flags?):
(input side): -re, -ts abs, -ts mono2abs
(output side): -fflags genpts
2) (the more interesting question) I want to understand what exactly
causes ffplay to process the apparently broken stream. I took the strace
of the reader thread, and after some manipulation ended up with a "read
schedule" as seen in [2.3]. Then I wrote a simple "delayed cat" program
that reads out [1] as per the schedule - it can be found in [2.4]. The
result is:
Hang every ~2.5 secs: `cat stdin.mkv | ffplay -i -`
Smooth no-hang video: `./scheduler | ffplay -i -`
If anyone has any ideas - please do share ;)
[1] 7Mb SHA1 649434a5aa0082f81cfc447af173203a970fda84, downloadable from
https://vimeo.com/114550042 (you need to login to vimeo to see the
"download original" link)
[2.1]
https://gist.github.com/ribasushi/fab13b785c3c6e1b70a3#file-strace_results
[2.2] https://gist.github.com/ribasushi/fab13b785c3c6e1b70a3#file-ptsdeltas
[2.3]
https://gist.github.com/ribasushi/fab13b785c3c6e1b70a3#file-read_schedule
[2.4] https://gist.github.com/ribasushi/fab13b785c3c6e1b70a3#file-scheduler
[3]
http://lists.mplayerhq.hu/pipermail/ffmpeg-user/2014-December/024507.html
More information about the ffmpeg-user
mailing list