image thumbnail

FFmpeg Toolbox

version (181 KB) by Kesh Ikuma
A set of wrapper functions to run FFmpeg directly from Matlab


Updated 13 Jul 2018

View License

FFmpeg ( is a complete, cross-platform solution to record, convert and stream audio and video. FFmpeg Toolbox is aimed to bring FFmpeg features to Matlab. While FFmpeg supports a vast number of multimedia formats and codecs, FFmpeg Toolbox brings a selected few (MP3, AAC, mpeg4, x264, animated GIF) closer to the user with its output option parameters.
To use this toolbox, FFmpeg binaries must already be downloaded and made available on the PC. (E.g., in Windows, ffmpeg.exe must be available). In MATLAB, run the toolbox setup m-file (ffmpegsetup.m) and follow its instructions. Note that if a newer version of FFmpeg is placed elsewhere on the PC, you must rerun ffmpegsetup to specify which ffmpeg executable is used with the toolbox.
Example 1. Convert an AVI movie file to MP4 with AAC audio codec and x264 video codec:
ffmpegtranscode('input.avi', 'output.mp4', 'AudioCodec', 'aac', 'VideoCodec', 'x264');

Example 2. To create animated GIF of a running sinusoid:

t = linspace(0,1,1001);
phi = linspace(0,2*pi,21);
for n = 1:numel(phi)
print('-dpng',sprintf('test%02d.png',n)); % create an intermediate PNG file

Example 3: Overlay a transparent mask to a video

videofile = 'video.mp4';
maskfile = 'mask.png'; % same size as video.mp4 frame
filtgraph = [ffmpegfilter.head ffmpegfilter.overlay ffmpegfilter.tail];
filtgraph(1).link(filtgraph(2),'0:v'); % video.mp4 as the main
filtgraph(1).link(filtgraph(2),'1:v',true); % mask.png as overlayed
ffmpegcombine({'videofile.mp4' 'maskfile'},'output.mp4',filtgraph);


Toolbox Setup
ffmpegsetup - Run this first to use this toolbox

FFmpeg feature list functions
ffmpegcodecs - Gets supported video codecs
ffmpegcolor - Convert color expression from MATLAB to FFmpeg
ffmpegcolors - Gets FFmpeg color names and their RGB values
ffmpegformats - Gets multimedia file formats
ffmpegpixfmts - Gets supported video pixel formats

FFmpeg wrapper functions
ffmpegextract - Extract a stream from a media file
ffmpegimage2video - Create video file from a series of images
ffmpeginfo - Retrieves media file information
ffmpegtranscode - Transcode media file (supports croping & scaling)
ffmpegcombine - Marge multiple media files with a filtergraph

FFmpeg filtergraph generator functions
ffmpegfiltersvideotform - To apply a series of spatial transformations
ffmpegfilterspalette - To generate and apply 256-color palette

FFmpeg filters (ffmpegfilter package)
ffmpegfilter.crop - Crop video
ffmpegfilter.hflip - Flip video horizontally
ffmpegfilter.histeq - Apply global color histogram equalization
ffmpegfilter.null - Pass through
ffmpegfilter.overlay - Overlay a video on top of another
ffmpegfilter.pad - Pad video
ffmpegfilter.palettegen - Generate a 256-color palette for a video
ffmpegfilter.paletteuse - Use a palette to reduce colors in video
ffmpegfilter.rotate - Rotate video
ffmpegfilter.scale - Scale or resize video
ffmpegfilter.setdar - Change display-aspect-ratio (DAR) setting
ffmpegfilter.setsar - Change sample-aspect-ratio (SAR) setting
ffmpegfilter.split - Split into several identical outputs
ffmpegfilter.transpose - Transpose rows of video with columns
ffmpegfilter.vflip - Flip video vertically

ffmpegfilter.head - Start of filtergraph (one per filtergraph)
ffmpegfilter.tail - End of filtergraph (one per filtergraph)
ffmpegfilter.base - Base class for all ffmpegfilter classes

Low-level FFmpeg wrapper functions
ffmpegexecargs - Run FFmpeg with custom option structs
ffmpegexec - Run FFmpeg with custom argument string

Cite As

Kesh Ikuma (2022). FFmpeg Toolbox (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2013a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!