How to Decrypt Media with FFmpeg Crypto Protocol
This article provides a practical guide on how to decrypt encrypted
video and audio files using FFmpeg’s built-in crypto
protocol. You will learn the exact command-line syntax, how to format
your decryption keys and initialization vectors (IVs), and how to output
a fully playable, decrypted media file.
To decrypt a media file using FFmpeg, you must use the
crypto protocol prefix followed by the path to your
encrypted file. You must also supply the decryption key and the
initialization vector (IV) used during the encryption process.
The Basic Command Syntax
The standard syntax for decrypting a file with the
crypto protocol is as follows:
ffmpeg -hexkey "YOUR_HEX_KEY" -hexiv "YOUR_HEX_IV" -i crypto:encrypted_file.mp4 -c copy decrypted_file.mp4Parameter Breakdown
-hexkey: Specifies the decryption key in hexadecimal format.-hexiv: Specifies the initialization vector (IV) in hexadecimal format.crypto:encrypted_file.mp4: Instructs FFmpeg to read the input file using thecryptoprotocol. Thecrypto:prefix must immediately precede the input file path.-c copy: Tells FFmpeg to copy the video and audio streams directly without re-encoding them, preserving the original quality and completing the process almost instantly.
Step-by-Step Decryption Example
If you have an AES-128 encrypted file named
secured_video.enc, a 32-character hex key, and a
32-character hex IV, run the following command:
ffmpeg -hexkey e5e9fa7f4c3e80a5196328bc6e3a9fa2 -hexiv 57c2a939f8d0e1273cb61109a256f108 -i crypto:secured_video.enc -c copy output_playable.mp4Alternative Binary Key Input
If your decryption key and IV are in binary format rather than
hexadecimal, use the -key and -iv options
instead:
ffmpeg -key "BINARY_KEY" -iv "BINARY_IV" -i crypto:encrypted_file.mp4 -c copy decrypted_file.mp4