Change Video Frame Rate with FFmpeg on Linux
Changing the frame rate of a video file is a common task in video editing and post-production, often necessary for matching project settings, reducing file size, or creating smooth playback. This guide provides a straightforward overview of how to alter a media file’s frame rate (FPS) using the powerful command-line tool FFmpeg on Linux. You will learn the essential commands for basic frame rate conversion, adjusting playback speed via raw bitstream modification, and handling audio synchronization.
The Standard Frame Rate Conversion
The most common and safest way to change a video’s frame rate is by
using the -r option. This method tells FFmpeg to
recalculate the frame rate by either dropping frames (if you are
lowering the FPS) or duplicating frames (if you are raising the FPS) to
match your target rate, all while keeping the video’s original playback
speed and audio sync intact.
To change the frame rate using this method, use the following command structure:
ffmpeg -i input.mp4 -r 30 output.mp4In this example, -i input.mp4 specifies your source
file, -r 30 sets the new target frame rate to 30 frames per
second, and output.mp4 is the resulting file. You can
replace 30 with any standard frame rate, such as
24, 60, or 29.97.
Advanced Conversion with Video Filters
If you need a more precise method that gives you control over how
frames are dropped or duplicated, you can use FFmpeg’s video filter
graph (-vf) with the fps filter. This is
highly effective when dealing with fractional frame rates or when the
standard -r flag produces choppy results.
ffmpeg -i input.mp4 -vf "fps=24" output.mp4The fps filter ensures that the output strictly adheres
to the specified rate by generating accurate presentation timestamps
(PTS) for each frame, making it the preferred choice for professional
video processing pipelines.
Changing Playback Speed via Bitstream
Sometimes, your goal is not to drop or duplicate frames, but to change how fast the existing frames are played back. For instance, you might want to turn a 60 FPS video into a 30 FPS slow-motion video. This requires changing the speed of both the video and the audio.
To achieve this, you must modify the presentation timestamps of the
video using the setpts filter, and adjust the audio speed
using the atempo filter to maintain synchronization:
ffmpeg -i input.mp4 -vf "setpts=2.0*PTS" -af "atempo=0.5" output.mp4setpts=2.0*PTS: This slows down the video by a factor of 2, effectively cutting the perceived frame rate in half and doubling the duration. To speed up a video, you would use a fraction less than 1.0 (e.g.,0.5*PTSto double the speed).atempo=0.5: This slows down the audio to match the new video duration. Note that theatempofilter only accepts values between 0.5 and 2.0.