My original video "test1.mp4" has following properties
Stream #0:0(eng): Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p, 640x360 [SAR 1:1 DAR 16:9], 283 kb/s, 34.55 fps, 50 tbr, 50k tbn, 50 tbc (default).
I got it from running ffmpeg -i test1.mp4
.
I had to change the video codec to h264
. So I converted the above video using below command
ffmpeg -i test1.mp4 test1.mp4
.
However the props of the converted video has changed. fps is 50 and tbr is 50. And also frame count has increased compared to original video.
Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x360 [SAR 1:1 DAR 16:9], 114 kb/s, 50 fps, 50 tbr, 12800 tbn, 100 tbc (default)
After following this link https://superuser.com/questions/1307863/why-is-ffmpeg-changing-framerate-from-60-to-120, I found that ffmpeg uses tbr
values instead of fps
while converting in order to not to lose any frames but at the cost of duplicate frames. As suggested in the link above I used vsync 0
option while converting video.
ffmpeg -i test1.mp4 -vsync 0 test1_sync.mp4.
Now the Frame count is same as the input video (checked using ffprobe
). But the fps
is still little different from the original video.
Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x360 [SAR 1:1 DAR 16:9], 61 kb/s, 12.88 fps, 50 tbr, 12800 tbn, 100 tbc (default).
How come frame count remains same even when fps is different?
To my use case I need the converted video to have same number of frames at the same timestamps as the original video, i just need the codec to be changed to h264
. I dont want duplicate or losing frames.
How can I achieve this?