Copy Metadata in FFmpeg with map_metadata

This article provides a practical guide on how to use the -map_metadata option in FFmpeg to copy metadata from a specific input file or stream to an output file. You will learn the syntax structure of the -map_metadata flag, see real-world command examples for global and stream-level metadata copying, and understand how to selectively exclude metadata during conversion.

Understanding the Syntax

The -map_metadata option in FFmpeg allows you to precisely target which metadata is copied from your input files to your output file. The basic syntax is:

-map_metadata[:output_spec] input_file_index[:input_spec]

If output_spec and input_spec are omitted, FFmpeg defaults to copying global metadata.


Common Examples

1. Copy Global Metadata from the First Input

To copy all global metadata (such as title, artist, or album) from the first input file directly to the output file, use:

ffmpeg -i input.mp4 -map_metadata 0 output.mp4

Here, 0 refers to the first input file.

2. Copy Video Stream Metadata Specifically

If you want to copy the metadata of the video stream from the first input file to the video stream of the output file:

ffmpeg -i input.mp4 -map_metadata:s:v 0:s:v output.mp4

3. Copy Audio Metadata from a Second Input File

If you are combining a video file and an audio file, and you want to copy the metadata from the audio file (the second input, index 1) to the output audio stream:

ffmpeg -i video.mp4 -i audio.m4a -map_metadata:s:a 1:s:a output.mp4

4. Copy Metadata to a Different Stream Type

You can also copy metadata from one stream type to another. For example, to copy the global metadata of the first input to the output’s audio stream:

ffmpeg -i input.mp4 -map_metadata:s:a 0 output.mp4

How to Delete or Ignore Metadata

If you want to prevent any metadata from being copied to the output file, use a negative index -1:

ffmpeg -i input.mp4 -map_metadata -1 output.mp4

This strips all global metadata from the output file, resulting in a clean file containing only the default container metadata generated during encoding.