- Published on
Increase or Decrease Audio and Video Playback Speed with FFmpeg
- Authors
- Name
- Hieu Cao
Why Adjust Playback Speed?
Changing the playback speed of audio and video files can be useful for:
- Learning and Training: Slow down playback for language learning or transcription.
- Creative Purposes: Speed up or slow down playback for specific effects.
- Testing and Analysis: Adjust playback speed to test media quality under various conditions.
Increasing or Decreasing Audio Playback Speed
You can adjust audio playback speed in FFmpeg using the atempo
audio filter. The atempo
filter supports playback speeds ranging from 0.5
(half-speed) to 2.0
(double-speed).
Increase Playback Speed
To double the playback speed:
ffmpeg -i input.mp3 -filter:a "atempo=2.0" -vn output.mp3
-i input.mp3
: Specify the input audio file.-filter:a "atempo=2.0"
: Apply theatempo
filter with a value of2.0
.-vn
: Exclude any video streams if the input file is a video.output.mp3
: Specify the output file.
Decrease Playback Speed
To reduce playback speed by half:
ffmpeg -i input.mp3 -filter:a "atempo=0.5" -vn output.mp3
atempo=0.5
: Slows down playback to half-speed.
Adjust to a Custom Playback Speed
To set a specific playback speed, replace the atempo
value with your desired factor. For example, 1.25
will speed up the audio by 25%:
ffmpeg -i input.mp3 -filter:a "atempo=1.25" -vn output.mp3
Increasing or Decreasing Video Playback Speed
To adjust the playback speed of a video, use the setpts
video filter.
Increase Video Playback Speed
To double the playback speed of a video:
ffmpeg -i input.mp4 -filter:v "setpts=0.5*PTS" -an output.mp4
-filter:v "setpts=0.5*PTS"
: Adjusts the playback speed by setting the Presentation Time Stamp (PTS) to half.-an
: Removes the audio track (optional, if you only want to adjust video speed).
Decrease Video Playback Speed
To slow down the video to half-speed:
ffmpeg -i input.mp4 -filter:v "setpts=2.0*PTS" -an output.mp4
setpts=2.0*PTS
: Doubles the PTS value, slowing down the video.
Adjust Both Audio and Video Playback Speed
If you want to adjust both audio and video playback speeds:
ffmpeg -i input.mp4 -filter:v "setpts=0.5*PTS" -filter:a "atempo=2.0" output.mp4
This command ensures that the audio and video remain synchronized after speed adjustment.
Best Practices for Adjusting Playback Speed
- Maintain Sync: Always adjust both audio and video speed if your file contains both.
- Use Compatible Codecs: Ensure the output file uses codecs compatible with your intended playback device.
- Test Quality: Verify that the audio and video quality meets your requirements after adjustments.
Conclusion
FFmpeg offers powerful tools for adjusting playback speed, whether for audio, video, or both. With simple commands, you can speed up or slow down your media files to suit your needs. From creative projects to testing scenarios, FFmpeg provides precise and efficient solutions for playback speed control.