Shuffle Video Frames Using FFmpeg Random Filter
This guide explains how to use FFmpeg's built-in random
filter to shuffle the order of video frames. You will learn the core
filter syntax, how the internal frame buffer dictates the randomness of
the output, and practical command-line examples to create stutter,
glitch, or randomized video effects.
Understanding the
random Filter
The random filter in FFmpeg stores incoming video frames
in an internal buffer and flushes them out in a pseudorandom sequence.
Because it relies on a local buffer rather than loading the entire file
into memory, it rearranges frames within a localized window rather than
globally shuffling the entire video from start to finish.
Filter Parameters
The random filter accepts two primary parameters:
frames(orf): Specifies the size of the internal frame cache. The default value is 30. A larger value creates a wider window of time from which frames can be shuffled, resulting in more extreme displacement.seed(ors): Sets the random seed for the generator. Setting a specific integer produces deterministic, reproducible results. If set to-1(the default), FFmpeg generates a random seed automatically.
Basic Command Syntax
To shuffle frames using the default settings (a 30-frame window),
apply the filter using the -vf (video filter) flag:
ffmpeg -i input.mp4 -vf "random" -an output.mp4Note: The -an flag removes the audio stream. The
random filter only alters video frames, meaning the
original audio will quickly fall completely out of sync with the
randomized visuals.
Customizing Buffer Size and Seed
To create a more pronounced jitter effect, increase the
frames buffer size.
Example: Shuffling Over a 100-Frame Window
ffmpeg -i input.mp4 -vf "random=frames=100" -c:a copy output.mp4In this command:
frames=100expands the internal cache to 100 frames. FFmpeg will pull frames randomly from this 100-frame window before accepting new ones.
Example: Setting a Fixed Seed for Reproducibility
ffmpeg -i input.mp4 -vf "random=frames=60:seed=12345" -an output.mp4Using seed=12345 ensures that running the command
multiple times produces the exact same frame sequence.
Memory and Performance Considerations
- RAM Usage: Setting the
framesparameter to very high values consumes substantial system memory because FFmpeg must store every uncompressed frame of the buffer in RAM. For high-resolution files (such as 4K), keep the buffer value moderate to avoid out-of-memory errors. - Audio Handling: Because there is no native
arandomfilter to mirror frame-level video shuffling for audio, you must choose whether to drop the audio (-an), preserve the original timing (-c:a copy), or replace the soundtrack during post-processing.