0

I am trying to change the framerate of a video so it runs a little longer. I don't want to re-encode and I want the audio to remain in sync. I was able to extract the raw video from the video and then remux using...

ffmpeg -i source.mkv -c copy -f h264 video.h264
ffmpeg -r 23.976 -i video.h264 -c copy dest.mp4

This creates a video that now runs the correct time with no audio.

How can I get a finished .mp4 with the audio?

2
  • 1
    How do you want the audio to remain in sync with the video if you have changed its timing?
    – harrymc
    Nov 15, 2019 at 21:02
  • The audio will need to be slowed down also to remain in sync. How do you tell ffmpeg to slow the audio down with the video?
    – MrRAlan
    Nov 15, 2019 at 21:06

1 Answer 1

2

You will need to adjust the audio speed to match the video and re-encode it, but you can do this without re-encoding the video.

First, compute how much you need to adjust the audio. Assuming this was originally a 25fps video you are slowing to 23.976, your speed factor is 23.976/25 = 0.959. We'll plug that into the atempo filter to adjust the speed of the audio, pulling it from the original source.mkv.

ffmpeg -i source.mkv -r 23.976 -i video.h264 -filter_complex "[0:a]atempo=0.959[out]" -map 1:v -map "[out]" -c:a aac -c:v copy out.mp4

The -filter_complex here is taking the audio stream from the zeroth input file (source.mkv) and running it through the atempo filter, then naming the output [out]. We then use -map arguments to say that we want to take that audio stream as well as the video stream from the first input file (starting from zero, so actually the second one, video.h264). We have to reencode the audio because we want to change it, but we can just copy the video into the container.

1
  • Thank you tgies. This worked! The file doesn't always play smoothly. On some Windows media players I see a slight jitter and on a PS4 it stutters pretty badly. I thought extracting the video and copying it without re-encoding gave the best results. Is there anything that can be done to correct this or is this to be expected when copying with a different frame rate? The video plays about 3 minutes too fast so I just want to slow it down.
    – MrRAlan
    Nov 25, 2019 at 0:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.