How to Use the FFmpeg Shuffleframes Filter
This article explains how to use the FFmpeg
shuffleframes video filter to rearrange, repeat, or drop
specific frames within a video stream. You will learn the core syntax of
the filter, understand how frame blocking works, and see practical
command-line examples for common video editing tasks like swapping
frames, repeating frames to create a stutter effect, and dropping
frames.
The shuffleframes filter works by grouping video frames
into destination blocks of a specific size, and then mapping the source
frames within that block to new positions. The number of space-separated
indexes you provide to the filter determines the size of the block. For
example, if you provide four indexes, FFmpeg will process the video in
consecutive blocks of four frames (indexes 0, 1, 2, and 3).
Rearranging Frames
To swap or rearrange frames, specify the desired order of the indexes in the filter configuration. The source frames are zero-indexed.
For a block of 4 frames (0, 1, 2, 3), if you want to swap the second
and third frames, the order becomes 0 2 1 3. Use the
following command:
ffmpeg -i input.mp4 -vf "shuffleframes=0 2 1 3" output.mp4In this command, every block of four frames throughout the entire video will have its middle two frames swapped.
Repeating Frames
You can repeat frames by referencing the same source index multiple times within your mapping block. This is useful for creating artistic stutter or freeze-frame effects.
For a block of 4 frames, if you want to repeat the first frame (index
0) twice, keep the second and third, and drop the fourth, map them as
0 0 1 2:
ffmpeg -i input.mp4 -vf "shuffleframes=0 0 1 2" output.mp4Because the list contains four indexes, the output video maintains the same overall frame count and frame rate, but frame 0 is displayed twice while frame 3 is discarded.
Dropping Frames
To drop a frame entirely from a block without replacing it with a
repeated frame, use the value -1. This will exclude the
frame at that position from the output sequence.
To drop the fourth frame (index 3) of every four-frame block, use the following mapping:
ffmpeg -i input.mp4 -vf "shuffleframes=0 1 2 -1" output.mp4Using -1 reduces the overall frame rate of the output
video because frames are actively being removed from the stream.