How to Use FFmpeg Random Filter to Shuffle Video Frames

This article explains how to use the random video filter in FFmpeg to shuffle the frame order of a video. You will learn the basic command syntax, how the frame buffer works to control the shuffling range, and how to apply these settings to create a randomized playback effect in your video projects.

The random filter in FFmpeg works by keeping a cache of a specified number of video frames, randomly selecting one frame from this cache to output, and then bringing in a new frame from the input video to fill the empty spot. Because of this sliding-window approach, the video frames are shuffled locally rather than globally across the entire duration of the video.

Basic Command Syntax

To shuffle frames using the default settings, use the following command:

ffmpeg -i input.mp4 -vf "random" -an output.mp4

Note: Since shuffling video frames disrupts the synchronization with the audio track, the -an flag is included in these examples to disable audio.

Controlling the Shuffling Range with Parameters

The random filter accepts two main parameters: frames and seed.

1. The frames Parameter

This parameter sets the size of the frame cache. The default value is 30. A larger number increases the range of the shuffle, making the video look more chaotic, but it also consumes more system memory.

To set the buffer to 100 frames, use:

ffmpeg -i input.mp4 -vf "random=frames=100" -an output.mp4

If you want to shuffle the entire video, you must set the frames value to be equal to or greater than the total frame count of your video. For example, if your video has 900 frames:

ffmpeg -i input.mp4 -vf "random=frames=900" -an output.mp4

2. The seed Parameter

By default, the random generator uses a random seed, meaning the output will be different every time you run the command. If you want to produce the exact same scrambled sequence every time, you can specify a constant seed value:

ffmpeg -i input.mp4 -vf "random=frames=60:seed=12345" -an output.mp4

Using these options allows you to easily generate glitch effects, abstract video art, or randomized test sequences directly from the command line.