FFmpeg Video Slow Motion: My Study Notes and Practical Tips
Hello everyone who works with videos!
Have you ever encountered a situation where you wanted to use FFmpeg to slow down a video's playback speed, say by half, to see details more clearly or to follow along with something? Or perhaps, you have a series of sequentially taken images and want to combine them into a video, but hope it plays back slowly instead of flashing by?
I've been pondering these questions recently and found that FFmpeg has several key points to consider, especially when setting speed and handling image sequences. I looked through some discussions on Reddit (like these two: how to make a video slow down and creating video from images), combined with my own practice, and compiled these notes.
This note doesn't talk about fancy "slow-motion effects"; it's about how to use FFmpeg to genuinely slow down video playback speed. We'll also specifically explore a common question: When using setpts to slow down, does the video's frame rate (FPS) change? And how to only extend playback time without changing the (file-marked) FPS? Finally, we'll also discuss when generating videos from images, how to correctly set that sometimes confusing frame rate (-r) parameter. Don't worry, we'll cover basic, practical methods applicable to Windows, Linux, and macOS, hoping to help you with similar needs.
Let's see how to make FFmpeg obediently "slow down"!
Behind Video Slow Motion: How is Time Stretched?
Making a video play in slow motion essentially means extending the display time of each frame, increasing the total duration of the video to achieve a slower playback speed. FFmpeg primarily achieves this by adjusting two things:
- Presentation Timestamp (PTS): Simply put, it tells the player at which point in the video this frame should be displayed.
- Frame Rate (Frame Rate): How many frames per second the video contains.
From reading discussions, I found the main sticking points are:
- How to accurately control the slow-motion multiplier?
- After using
setptsto slow down, will the output video's FPS change? - How to handle audio to keep it synchronized when the video slows down?
- What's the key difference between input and output frame rate (
-r) settings when creating videos from images? - Are there pitfalls when using FFmpeg on different operating systems?
Let's address these issues one by one.
Method 1: Slowing Down an Existing Video (Basic Operation, Including FPS Clarification)
To slow down the playback speed of an existing video file, the most direct method is to use the setpts filter (via the -vf parameter). For example, to make the video play at half its original speed:
ffmpeg -i input.mp4 -vf "setpts=2.0*PTS" output.mp4Explanation:
-vf "setpts=2.0*PTS"is key. It tells FFmpeg to multiply the original display timestamp (PTS) of each frame by 2. This way, content that originally took 1 second to play now takes 2 seconds, naturally reducing the playback speed to half. It directly acts on timestamps, stretching the time interval between frames.So, will the FPS change? How to only extend playback time without changing FPS?
- Great question!
setptsitself modifies timestamps; it does not directly change the FPS metadata recorded in the video stream (e.g., 30fps). - Typically (Default Behavior): When you use only
setptsand do not use-ron the output side to force a new frame rate, FFmpeg often keeps the output video file's FPS marking consistent with the input video. - The result is: You get a video file with doubled duration, containing the same total number of frames as the original video, and the file info shows the same FPS as before (e.g., still 30fps).
- Therefore, the command
ffmpeg -i input.mp4 -vf "setpts=2.0*PTS" output.mp4itself (in most cases) already achieves your goal: extends playback time while keeping the file's marked FPS unchanged. It achieves the slow-motion effect by making each frame display longer, not by changing the video's frame rate standard. - An important note: Although the file's marked FPS doesn't change, because the total duration increases while the total frame count remains the same, the actual number of new frames seen per second during playback is indeed reduced. This might make it feel less smooth than the original speed (but this is precisely the desired effect of slow motion).
- Great question!
Cross-Platform Compatibility: This command is written the same way on Windows, Linux, and macOS, which is very convenient.
Method 2: Handling Audio Synchronization (Sound Must Slow Down Too)
Slowing down only the visuals is often not enough. If the video has audio, the sound must also slow down; otherwise, it will go out of sync. This requires adding the atempo audio filter (via the -af parameter):
ffmpeg -i input.mp4 -vf "setpts=2.0*PTS" -af "atempo=0.5" output.mp4- Explanation:
-af "atempo=0.5"means reducing the audio playback speed to 0.5 times the original (i.e., half). This keeps the sound and picture synchronized.- Additional Note: The speed factor for the
atempofilter must be between 0.5 and 100.0. To go slower than 0.5x (e.g., 0.25x), you need to use it consecutively, like-af "atempo=0.5,atempo=0.5".
- Additional Note: The speed factor for the
- Cross-Platform Compatibility: This command is also universal across platforms.
Method 3: Creating Slow-Motion Videos from Image Sequences (Key Understanding of -r!)
This scenario is also common: You have a series of images (e.g., img1.jpg, img2.jpg, ...) and want to make them into a video, hoping this video plays back relatively slowly. Command example:
ffmpeg -r 1 -i img%d.jpg -vf "setpts=2.0*PTS" -r 30 -c:v libx264 -pix_fmt yuv420p output.mp4Understanding the two -r parameters here is key:
The first
-r(input-r 1):- Defines how long each input image represents by default when being read.
-r 1means each image takes up 1 second (input base frame rate 1fps). 10 images would be 10 seconds of base material duration. - It sets the time base for the input material.
- Defines how long each input image represents by default when being read.
The second
-r(output-r 30):- Specifies at what frame rate the final generated video file should play.
-r 30means outputting a 30fps video. - It determines the specification and smoothness of the output video. FFmpeg will calculate the total number of frames needed based on the total duration after
setptsadjustment (e.g., 10 images, input-r 1,setpts=2.0results in a target duration of 20 seconds) and this output frame rate (30fps), which is 20 * 30 = 600 frames. It will fill these 600 frames by repeating the original images (becausesetptsonly changes timestamps) to ensure the output video meets the 30fps standard.
- Specifies at what frame rate the final generated video file should play.
Working Together: Input
-rsets the base duration ->setptsadjusts the duration -> Output-rsets the final specification and frame filling method.Cross-Platform Notes: Windows recommends using
%dto match numbered sequence filenames; Linux/macOS can use*but%dis safer.
Method 4: Balancing Processing Speed and Output Quality
Video processing can be time-consuming; parameters can be adjusted for a trade-off:
- Increase Speed: Use
-preset ultrafast/fast, etc. - Control Quality: Use
-crfvalue (e.g.,-crf 20).
Balanced example:
ffmpeg -i input.mp4 -vf "setpts=2.0*PTS" -af "atempo=0.5" -c:v libx264 -preset fast -crf 20 -c:a aac output.mp4- Hardware Acceleration: Consider
-c:v h264_nvenc(Nvidia) or-c:v h264_videotoolbox(Apple) for speedup.
Alright, this time we've explored in-depth the methods for achieving "slow motion" with FFmpeg and specifically clarified the relationship between setpts and FPS. Key takeaways:
- Slowing Down Existing Videos:
- Use
-vf "setpts=N*PTS"(N>1) to extend video time. - This command typically keeps the output file's FPS marking consistent with the input while extending playback time, meeting the need for "slow motion only, without changing (marked) FPS".
- Don't forget to use
-af "atempo=1/N"(note the 0.5x speed limit) to handle audio synchronization.
- Use
- Creating Slow-Motion Videos from Image Sequences:
- Input
-rdetermines the time value of each image. - Output
-rsets the playback frame rate for the final video (recommended 25 or 30). setptsis used to further adjust the overall playback speed.
- Input
- Cross-Platform: Core commands are universal; pay attention to filename patterns.
- Efficiency and Quality: Use
-presetand-crfto adjust.
