How to Use FFmpeg map_metadata to Copy Metadata
This article explains how to use the -map_metadata
option in FFmpeg to copy, transfer, or exclude metadata from an input
file to an output file. You will learn the basic command syntax, how to
copy global metadata, and how to target specific streams like video,
audio, or chapters.
Understanding the -map_metadata Syntax
By default, FFmpeg attempts to copy global metadata from the first
input file to the output file. However, if you want precise control over
which metadata gets copied, you must use the -map_metadata
option.
The basic syntax is:
-map_metadata[:output_metadata_spec] input_file_index[:input_metadata_spec]
- output_metadata_spec: Specifies where the metadata goes in the output (e.g., global, stream, chapter).
- input_file_index: The index of the input file
(starting at
0for the first input). - input_metadata_spec: Specifies which metadata to copy from the input.
If you do not specify a stream specifier, FFmpeg defaults to global metadata.
Common Use Cases and Examples
1. Copying Global Metadata To explicitly copy global metadata (like title, artist, and album) from the first input file to the output file, use the following command:
ffmpeg -i input.mp4 -map_metadata 0 -c copy output.mp4
Here, 0 tells FFmpeg to take the global metadata from
the first input file (index 0) and apply it globally to the output.
2. Copying Stream-Specific Metadata Sometimes you want to copy metadata belonging to specific streams, such as language tags on audio tracks. To copy audio stream metadata from the input to the output:
ffmpeg -i input.mkv -map_metadata:s:a 0:s:a -c copy output.mkv
:s:arefers to “streams:audio”.- This command maps the audio stream metadata from the first input
(
0:s:a) to the audio streams of the output (-map_metadata:s:a).
3. Copying Metadata from a Second Input File If you are merging files or adding an audio track from a second file and want to keep the metadata of the second file (index 1):
ffmpeg -i video.mp4 -i audio.m4a -map 0:v -map 1:a -map_metadata 1 -c copy output.mp4
In this command, -map_metadata 1 copies the global
metadata from the second input file (audio.m4a) to the
output.
4. Disabling Metadata Copying (Stripping Metadata)
If you want to strip all metadata from the input file so the output file
is completely clean, pass -1 to the option:
ffmpeg -i input.mp4 -map_metadata -1 -c copy output.mp4
Using -1 tells FFmpeg not to write any metadata from the
source file into the destination file.