I f consult some of my previous post, you may noticed that I’m an ffmpeg fan.
I often used ffmpeg command line to pipe raw video, in my own soft or some soft I develop in my professional environment. But I recently discover a good to share trick about ffmpeg.
Imagine a video file of 20min at 24fps, you have extract those information using the ffmpeg –i command. But when you extract the raw video frame in a file, you discover that the output file is bigger than expected (like a Tardis….).
Example of simple decoding as YUV 420p:
ffmpeg –I input.mp4 –c:v raw_video –pix_fmt yuv420p – >> output.yuv
the reason can be that if the input file hasn’t PTS corresponding to a Constant Frame-Rate (CFR), ffmpeg duplicate or drop some frames.
hopefully ffmpeg is explicit and full of useful information to troubleshoot those situation, for example in the following ffmpeg output latest line we see that it “duplicate” 60 frame.
frame= 119 fps=0.0 q=0.0 Lsize= 160650kB time=00:00:02.00 bitrate=657102.5kbits/s dup=60 drop=0
To prevent that the parameter to use is “-vsync”.
Video sync method. For compatibility reasons old values can be specified as numbers. Newly added values will have to be specified as strings always.
- ‘0, passthrough’
-
Each frame is passed with its timestamp from the demuxer to the muxer.
- ‘1, cfr’
-
Frames will be duplicated and dropped to achieve exactly the requested constant frame rate.
- ‘2, vfr’
-
Frames are passed through with their timestamp or dropped so as to prevent 2 frames from having the same timestamp.
- ‘drop’
-
As passthrough but destroys all timestamps, making the muxer generate fresh timestamps based on frame-rate.
- ‘-1, auto’
-
Chooses between 1 and 2 depending on muxer capabilities. This is the default method.
So to only have the encoded frame in our output the correct line is:
ffmpeg –I input.mp4 –vsync 0 –c:v raw_video –pix_fmt yuv420p – >> output.yuv
Aucun commentaire :
Enregistrer un commentaire