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]

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

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.