FFmpeg – Speed Up Video with Audio Without Changing Pitch

audioffmpegvideo

Is there a relatively simple way to speed up a video (mp4, with aac encoded audio), by say "x1.25" or "x1.3" while keeping the original audio-video sync, but also retaining the original pitch of the audio ?

I've read some discussions about extracting audio track into separate file, then use rubberband to lower the pitch by the requisite value, and then merge the audio video tracks using ffmpeg with speed-up, which raises the pitch of the audio back again to original. However, it appears that this is a bit of hit-n-miss, because rubberband appears to use number of octaves as the parameter to raise or lower pitch, and this may not always align perfectly with the video, as musical notes / octaves have specific ratios. Also, this is cumbersome.

So, is there any simpler ways using ffmpeg alone ?

Best Answer

It can be done with ffmpgeg using a complex filter:

  ffmpeg -i input.mkv -filter_complex "[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]" -map "[v]" -map "[a]" output.mkv

Doku: https://trac.ffmpeg.org/wiki/How%20to%20speed%20up%20/%20slow%20down%20a%20video

The command above works if you want to multiply by 2 the speed. If you want to multiply by any , the parameters become:

  ffmpeg -i input.mkv -filter_complex "[0:v]setpts=<1/x>*PTS[v];[0:a]atempo=<x>[a]" -map "[v]" -map "[a]" output.mkv

For instance, if you want to multiply by 1.15, the command is

  ffmpeg -i input.mkv -filter_complex "[0:v]setpts=0.87*PTS[v];[0:a]atempo=1.15[a]" -map "[v]" -map "[a]" output.mkv
Related Question