FFmpeg is a powerful command-line tool for processing audio and video files. You can use it for everything from simple operations, such as removing audio or changing playback speed, to more advanced tasks like joining multiple recordings, adding watermarks, and changing video properties.
The examples below use `.mov` files, but most commands work with other common formats, such as MP4, MKV, and AVI. You can replace the filenames and extensions with your own.
How to speed up a video (fast-forward / timelapse) without audio
You can speed up an ordinary video by changing its presentation timestamps (PTS). FFmpeg uses the `setpts` video filter for this purpose.
For example, to make a video play five times faster:
$ ffmpeg -i video.mov -an -vf "setpts=0.20*PTS" video-fast.movLet's break down the options:
- `-i video.mov` specifies the input video.
- `-an` disables audio in the output.
- `-vf` applies a video filter.
- `setpts=0.20*PTS` reduces the presentation timestamps to 20% of their original values, making the video play five times faster.
- `video-fast.mov` is the resulting file.
You can adjust the multiplier to achieve different speeds:
setpts=0.50*PTS # 2x faster
setpts=0.25*PTS # 4x faster
setpts=0.20*PTS # 5x faster
setpts=0.10*PTS # 10x fasterWhat about keeping the sound?
The `setpts` filter only changes video playback speed. It does not automatically adjust the audio, so simply removing `-an` will result in audio and video playing at different speeds.
If you want to speed up both video and audio, you need to use the `atempo` audio filter as well.
For example, to speed up both by 2x:
$ ffmpeg -i video.mov -filter_complex "[0:v]setpts=0.5*PTS[v];[0:a]atempo=2[a]" -map "[v]" -map "[a]" video-fast-audio.movHow to slow down a video (slow motion) without audio
The same principle applies when creating slow-motion footage. Instead of reducing the presentation timestamps, you increase them.
For example, to make a video play at half its original speed:
$ ffmpeg -i video.mov -an -vf "setpts=2*PTS" video-slow.movHere, `setpts=2*PTS` doubles the presentation timestamps, making the video take twice as long to play.
Some other examples:
setpts=1.5*PTS # 1.5x slower
setpts=2*PTS # 2x slower
setpts=3*PTS # 3x slower
setpts=4*PTS # 4x slowerWhat about keeping the sound?
As with fast-forward, the audio must also be adjusted if you want it to remain synchronized.
For example, to slow down both video and audio by 2x:
$ ffmpeg -i video.mov -filter_complex "[0:v]setpts=2*PTS[v];[0:a]atempo=0.5[a]" -map "[v]" -map "[a]" video-slow-audio.movKeep in mind that slow motion looks best when the original footage was recorded at a sufficiently high frame rate. Slowing down ordinary 30 FPS footage does not create additional frames or new motion detail.
You can read more about changing video playback speed in the official FFmpeg documentation.
How to join multiple videos together
FFmpeg can join multiple video files into a single video using its concat demuxer.
This is particularly useful when you have recorded several clips and want to combine them into one continuous video without re-encoding everything.
1. Create a text file containing the video filenames.
For example, if you have multiple `.MOV` files in the current directory, you can generate the list automatically:
$ for vid in *.MOV; do
[ -f "$vid" ] || continue
printf "file '%s'\n" "$vid"
done > vids.txtThis creates a file called `vids.txt`, containing entries similar to these:
file '01170531_2651.MOV'
file '01170532_2652.MOV'
file '01170532_2653.MOV'
file '01170532_2654.MOV'
file '01170532_2655.MOV'
file '01170533_2656.MOV'
file '01170533_2657.MOV'You can inspect the beginning or end of the list using:
$ head vids.txt
$ tail vids.txtThe shell expands `*.MOV` in filename order. This example assumes ordinary filenames without embedded single quotes.
2. Join the videos using FFmpeg.
$ ffmpeg -f concat -safe 0 -i vids.txt -c copy video_draft.movHere's what the options mean:
- `-f concat` tells FFmpeg to use the concat demuxer.
- `-safe 0` allows filenames that would otherwise be rejected by the safe-path checks. It is not required for simple filenames in the current directory.
- `-i vids.txt` specifies the list of video files.
- `-c copy` copies the existing audio and video streams without re-encoding them.
**Important:** This method works when the source files have compatible stream parameters, including codecs, resolution, frame rate, and audio configuration. If the clips have different properties, FFmpeg may fail or produce an unexpected result. In that case, the videos need to be normalized and re-encoded before joining.
The advantage of using `-c copy` is that it is extremely fast and avoids additional quality loss from video re-encoding.
How to add a watermark to a video
You can use FFmpeg's `overlay` filter to place an image, such as a PNG logo, over your video.
For example:
$ ffmpeg -i video.mov -i watermark.png -filter_complex "overlay=1400:830" watermarked-video.movThe first input is the original video, while the second input is the watermark image.
The `overlay=1400:830` part specifies the horizontal and vertical position where the watermark will appear, measured in pixels from the top-left corner of the video.
You can also position the watermark relative to the video dimensions.
For example, to place it in the bottom-right corner with a 30-pixel margin:
$ ffmpeg -i video.mov -i watermark.png -filter_complex "overlay=W-w-30:H-h-30" -c:v libx264 -crf 18 -preset medium -c:a copy watermarked-video.movHere:
- `W` and `H` represent the original video's width and height.
- `w` and `h` represent the watermark's width and height.
- `30` provides a 30-pixel margin from the right and bottom edges.
- `-crf 18` specifies the video quality for the H.264 encoder. Lower values mean higher quality and larger files.
- `-preset medium` controls encoding speed versus compression efficiency.
- `-c:a copy` copies the original audio without re-encoding it.
**A note about quality:** Applying an overlay requires re-encoding the video stream. Therefore, this operation is not technically lossless, even when using a high-quality encoding setting. Using a transparent PNG is also recommended so that the watermark does not cover more of the picture than necessary.
How to remove the audio from a video
Sometimes you only need the video stream and want to remove its audio entirely.
You can do this without re-encoding the video:
$ ffmpeg -i video.mov -c:v copy -an no-sound-video.movThe options are straightforward:
- `-c:v copy` copies the original video stream without re-encoding.
- `-an` disables audio in the output file.
This operation is very fast because FFmpeg does not need to process or encode the video itself.
How to rotate a video
There are two ways to rotate a video using FFmpeg: changing its rotation metadata or physically rotating its image.
1. Change the rotation metadata
For compatible MOV/MP4 files, you can instruct supported players to display the video with a 90-degree rotation:
$ ffmpeg -i video.mov -c copy -metadata:s:v:0 rotate=90 video-rotated-90degrees.movThis operation does not physically rotate the image. Instead, it changes the rotation information stored in the container.
Some players may ignore this metadata, so the result can vary depending on the software being used.
2. Physically rotate the video
If you want the actual video frames to be rotated, use the `transpose` filter.
For example, to rotate the video 90 degrees clockwise:
$ ffmpeg -i video.mov -vf "transpose=1" -c:v libx264 -crf 18 -preset medium -c:a copy video-rotated.movOther available values include:
transpose=0 # 90 degrees counterclockwise
transpose=1 # 90 degrees clockwise
transpose=2 # 90 degrees counterclockwise and vertical flip
transpose=3 # 90 degrees clockwise and vertical flipUnlike changing metadata, physically rotating the image requires video re-encoding.
How to change the frame rate of a video
FFmpeg can also change the frame rate of a video using the `fps` filter.
For example, if you have a video recorded at 256 FPS and want to convert it to 60 FPS:
$ ffmpeg -i 256fps-video.mov -vf "fps=60" Result-60fps-video.movThe `fps=60` filter tells FFmpeg to produce an output video with 60 frames per second.
**What actually happens when changing the frame rate?**
When converting from a higher frame rate to a lower one, FFmpeg drops frames to achieve the requested output frame rate.
For example:
- 256 FPS to 60 FPS: frames are discarded.
- 60 FPS to 30 FPS: approximately half the frames are discarded.
- 30 FPS to 60 FPS: additional frames are generated by duplicating existing frames.
Keep in mind that changing the frame rate is not the same as creating slow motion.
For example, if you recorded footage at 256 FPS and want to play it back at 60 FPS while retaining all the original frames, you can slow it down using `setpts`:
$ ffmpeg -i 256fps-video.mov -an -vf "setpts=256/60*PTS,fps=60" slow-motion-60fps.movThis produces approximately 4.27 times slower playback, using the original 256 captured frames per second to create smooth 60 FPS slow motion.
---
A few useful things to remember
- FFmpeg normally re-encodes video when you apply filters such as `setpts`, `fps`, `overlay`, or `transpose`.
- The `-c copy` option avoids re-encoding, but it cannot be used when the video itself needs to be modified by a filter.
- Audio and video filters are independent. Changing video playback speed does not automatically change audio playback speed.
- Always keep your original recordings if you intend to perform several editing operations. Repeated lossy re-encoding can gradually reduce quality.
- You can check the properties of a video before processing it with `ffprobe`, which is included with FFmpeg.
For example:
$ ffprobe -v error -show_streams -show_format video.movThis displays information about the video and audio streams, including resolution, frame rate, codecs, duration, and other useful properties.
- Log in to post comments
- 24394 views