Change framerate on MKV container
Solution 1
You can try recoding the video and audio to a different frame rate while keeping the subtitles as they are:
ffmpeg -i input.mkv -c:v libx264 -crf 21 -c:a aac -strict experimental -b:a 128k -r 23.98 -c:s copy output.mkv
The CRF sets the video quality. Choose something lower for even better quality, like 18. 23 is the default for x264.
Solution 2
As people said in the comments, the right way to handle the problem you're actually trying to solve is to tweak the subtitles, or tell your player they're for a different speed video. (e.g. mpv --sub-fps 25
will keep subs for a 25fps show in sync with a 24/1.001 fps copy of it.) (http://mpv.io/)
But to answer the actual question:
You don't need to re-encode to change the fps. ffmpeg can't remux with new timestamps without re-encoding, unfortunately, but that's a design limitation of ffmpeg. Video encoding is lossy and very slow, so don't do it.
Try mkvmerge --default-duration 0:24000/1001fps --fix-bitstream-timing-information 0 in.mkv -o out.mkv
to change the video FPS. That won't touch the audio timing, so you will get a/v desync. 0:
selects track 0
in your input file, which I think is usually the video.
You will need to re-encode the audio after processing it with a pitch-preserving speedup filter. I usually only do this at playback time with mpv / mplayer's scaletempo
filter (mpv inserts it automatically). ffmpeg has an atempo
filter which probably does the trick.
So mux the slowed-down audio with the 24/1.001fps video, and you should have a working file again.
I didn't really test all this, because normally you never need to do this. Just tell your player what speed the subs are for. And you can even use mpv --speed 25025/24000 -subfps 25 myfile.mkv
to on-the-fly play back your video at 25fps, if you have a 24/1.001 fps copy of a British show that was originally 25fps, and you want to play it back at the original speed, with constant-pitch audio speedup.
Solution 3
no need to encode and lose quality, for windows at least. Use subtitle edit software, go to synchronization, change frame rate from the one of your original subtitle to whatever you want, save to new synched subtitle afterward.
Related videos on Youtube
mainstream
Updated on September 18, 2022Comments
-
mainstream over 1 year
I got a problem with playback of some MKV containers (89 items, totalling 196,3 GB).
The audio+video are encoded in 25 fps, but the subs are totally out of sync - these are encoded on 23.976 fps.
My question: Is there anyway i can batch change/reencode the framerate on these movies to 23.976?
-
slhck over 9 yearsWouldn't it be easier to change the subtitles? If you speed up the movie from 25 to 23.98, you'll also have to pitch up the audio and it'll look/sound unnatural. Also, you'd have to recompress the bitstreams.
-
mainstream over 9 yearsIt's quite allot of work to sync 89 subtitles manually :(
-
slhck over 9 yearsActually, you may just want to try to do something like
ffmpeg -i input.mkv -c:v libx264 -crf 21 -c:a aac -strict experimental -b:a 128k -r 23.98 -sn output.mkv
to convert the framerate by dropping a few frames. Of course this will re-encode. Are the subtitles inside the file? Or as an.srt
file? -
slhck over 9 yearsYeah, with
-sn
you disable the subtitles. With-c:s copy
you can copy them over, for example. -
mainstream over 9 yearsThanks :) offtopic: why is my question voted down? :(
-
slhck over 9 yearsNot sure. People are not required to explain why. Maybe your question does not show enough of what you've tried to solve the problem?
-
-
Peter Cordes about 9 yearsYou can do it with no video quality loss if you use a tool like
mkvmerge
that can modify container timestamps while remuxing. You do still need to decode/process/encode the audio, though.