How to Convert SWF to MP4 with FFmpeg
This article provides a quick guide on how to convert vector-based Shockwave Flash (SWF) animations into MP4 videos using the command-line tool FFmpeg. While FFmpeg can easily process SWF files containing standard embedded video streams, vector-based animations with interactive ActionScript require specific arguments to render correctly. Below, you will find the exact commands and configurations needed to perform this conversion efficiently.
The Basic Conversion Command
If your SWF file consists of standard frame-by-frame vector animations without complex interactive scripts, FFmpeg can render and convert it directly. Open your terminal or command prompt and run the following command:
ffmpeg -i input.swf -c:v libx264 -r 30 -pix_fmt yuv420p output.mp4Command Breakdown
-i input.swf: Specifies the input SWF file.-c:v libx264: Uses the H.264 video codec, which ensures high compression and wide compatibility with modern media players.-r 30: Sets the output frame rate to 30 frames per second. Vector SWFs often do not have a fixed container frame rate that FFmpeg can easily detect, so forcing a frame rate prevents synchronization issues.-pix_fmt yuv420p: Converts the pixel format to YUV 4:2:0. This is a critical step because SWF files often use RGB pixel formats that are incompatible with standard MP4 players like QuickTime or mobile devices.
Handling Audio Streams
If your SWF file contains audio, you should map and transcode the audio to AAC (the standard audio format for MP4) to ensure it plays correctly:
ffmpeg -i input.swf -c:v libx264 -c:a aac -b:a 192k -r 30 -pix_fmt yuv420p output.mp4-c:a aac: Encodes the audio stream using the AAC codec.-b:a 192k: Sets the audio bitrate to 192 kbps for high-quality sound.
Limitations with Interactive ActionScript
FFmpeg’s built-in SWF decoder reads the static timeline of the Flash file. If your SWF relies heavily on complex ActionScript, nested movie clips that play independently of the main timeline, or user interaction (like button clicks), FFmpeg will not be able to execute the code.
For highly interactive vector SWFs, the recommended workaround is to
play the SWF using a modern Flash player emulator like Ruffle or the
standalone Adobe Flash Player projector, capture the screen using
FFmpeg’s screen-grabbing utility (such as gdigrab on
Windows or x11grab on Linux), and output that capture
directly to an MP4 file.