FFMPEG vsync drop and regeneration

Viewed 4638

According to the ffmpeg documentation

-vsync parameter

Video sync method. For compatibility reasons old values can be specified as numbers. Newly added values will have to be specified as strings always.

drop

As passthrough but destroys all timestamps, making the muxer generate fresh timestamps based on frame-rate.

It appears that the mpegts mux does not regenerate the timestamps correctly (PTS/DTS); however, piping the output after vsync drop to a second process as raw h264 does force mpegts to regenerate the PTS.

Generate test stream

ffmpeg -f lavfi -i testsrc=duration=20:size=1280x720:rate=50 -pix_fmt yuv420p -c:v libx264 -b:v 4000000 -x264-params ref=1:bframes=0:vbv-maxrate=4500:vbv-bufsize=4000:nal-hrd=cbr:aud=1:bframes=0:intra-refresh=1:keyint=30:min-keyint=30:scenecut=0 -f mpegts -muxrate 5985920 -pcr_period 20 video.ts -y

Generate output ts that has correctly spaced PTS values

ffmpeg -i video.ts -vsync drop -c:v copy -bsf:v h264_mp4toannexb -f h264   - | ffmpeg -fflags +igndts -fflags +nofillin -fflags +genpts -r 50 -i - -c:v copy -f mpegts -muxrate 5985920  video_all_pts_ok.ts -y

Generate output ts where all PTS are zero

ffmpeg -i video.ts -vsync drop -c:v copy -bsf:v h264_mp4toannexb -f mpegts - | ffmpeg -fflags +igndts -fflags +nofillin -fflags +genpts -r 50 -i - -c:v copy -f mpegts -muxrate 5985920 video_all_pts_zero.ts -y

It appears that vsync drop does destroy them but the mpegts doesn't regenerate them? Any ideas on what needs adding to get it to work as a single ffmpeg command?

Tested on both Linux and Windows with the same result

1 Answers

Try recoding the video just using -vsync 1, without -fflags +genpts. I found some good information here. This guy talking about streaming video. So highest quality isn't his objective. But there is useful info.

https://videoblerg.wordpress.com/2017/11/10/ffmpeg-and-how-to-use-it-wrong/

Section one – Constant frame rate

"-r is used to specify the output frame rate. This must be the same as the input frame rate to eliminate judder. This is used in conjunction with the -vsync parameter using the 1 option which will retime the PTS/DTS timestamps accordingly"

Section six – Audio [Has some good advice too]

"-af "aresample=async=1:min_hard_comp=0.100000:first_pts=0" helps to keep your audio lined up with the beginning of your video. It is common for a container to have the beginning of the video and the beginning of the audio start at different points. By using this your container should have little to no audio drift or offset as it will pad the audio with silence or trim audio with negative PTS timestamps if the audio does not actually start at the beginning of the video."

I haven't tried this yet, no videos with sync problems at the moment.

Related