FFmpeg Copy Metadata from Second Input to Output
When processing multiple media files with FFmpeg, the tool by default
copies global metadata from the very first input file to the output.
This article provides a quick and direct guide on how to override this
default behavior using the -map_metadata option, allowing
you to copy the global metadata from the second input file (or any
subsequent input) to your output file.
To copy global metadata from the second input file to your output,
you need to use the -map_metadata flag combined with
FFmpeg’s zero-based indexing system. In FFmpeg, the first input file is
indexed as 0, and the second input file is indexed as
1.
The Command Syntax
Use the following command structure to achieve this:
ffmpeg -i input1.mp4 -i input2.mp4 -map 0:v -map 0:a -map_metadata 1 -c copy output.mp4How It Works
-i input1.mp4: Defines the first input file (index0).-i input2.mp4: Defines the second input file (index1).-map 0:vand-map 0:a: Selects the video and audio streams from the first input file to be written to the output.-map_metadata 1: Instructs FFmpeg to copy the global metadata from the input file at index1(the second input file) and apply it to the output file.-c copy: Stream copies the video and audio without re-encoding, preserving original quality and processing the file instantly.
By explicitly declaring -map_metadata 1, you prevent
FFmpeg from using the metadata of input1.mp4 and force it
to write the global metadata tags (such as title, author, creation time,
or copyright) from input2.mp4 into the final
output.mp4.