Modify image and sound speed

Problem

The projection or viewing speed of an audio-visual file should be changed from 24 fps (which is the cinema standard) to 25 fps (which is the «European» television standard).

Solution

ffmpeg \
    -i input_file \
    -r 25 \
    -filter_complex \
        "[0:v]setpts=24/25*PTS[v]; \
        [0:a]atempo=25/24[a]" \
    -map "[v]" \
    -map "[a]" \
    output_file

General command

ffmpeg \
    -i input_file \
    -r output_fps \
    -filter_complex \
        "[0:v]setpts=input_fps/output_fps*PTS[v]; \
        [0:a]atempo=output_fps/input_fps[a]" \
    -map "[v]" \
    -map "[a]" \
    output_file

Command syntax

ffmpeg
starts the command
-i input_file
path, name and extension of the input file
-r output_fps
sets the frame rate of the output file
-filter_complex "[0:v]setpts=input_fps/output_fps*PTS[v]; [0:a]atempo=output_fps/input_fps[a]"
A complex filter is needed (see the discussion below).
-map "[v]"
maps the video stream and
-map "[a]"
maps the audio stream together into:
output_file
path, name and extension of the output file

Discussion

A complex filter is needed here, in order to handle video stream and the audio stream separately. Please note that sadly the parameter’s order for the image and for the sound are inverted.

  • The video filter setpts modifies the PTS (presentation time stamp) of the video stream. The numerator input_fps sets the input speed and the denominator output_fps sets the output speed; both values are given in frames per second.
  • The sound filter atempo modifies the speed of the audio stream while keeping the same sound pitch. The numerator output_fps sets the output speed and the denominator input_fps sets the input speed; both values are given in frames per second.

The quotation marks allow to insert a space between the filters for readability.

As usual in the IT world, the numbering of the channels starts at 0 and not at 1 («zero-based numbering»).


2018–07–28