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]output_spec: Specifies where the metadata should go in the output (e.g., globally, or to a specific stream like video or audio).input_file_index: The zero-based index of the input file (e.g.,0for the first input file,1for the second).input_spec: Specifies which part of the input file to copy the metadata from (e.g., global, or a specific stream).
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.mp4Here, 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:s:vtargets the video stream. This command ensures video-specific metadata (like rotation or creation time) is preserved on the video track.
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.mp41:s:atells FFmpeg to look at the second input file (1) and copy its audio stream metadata (s:a) to the output’s audio stream (:s:a).
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.mp4How 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.mp4This strips all global metadata from the output file, resulting in a clean file containing only the default container metadata generated during encoding.