I've seen some great articles on how to use ffmpeg to copy metadata from one file to another without re-encoding. But I have more than 100 files and would like to do this in a batch operation. Any suggestions?

Extra info: I have 2 folders, one contains the video files with correct metadata, the other contains the video files with incorrect metadata. The files have the same corresponding file names.


I'm going to give you a scripting answer, there may well be a more general tool for this.

For future readers, this script describes how to copy metadata: Using ffmpeg to copy metadata from one file to another.

The following script will loop through the the files in one directory, find corresponding files in a second directory and then combine these two files into a third output directory

for file in $(ls $dir1); do
  ffmpeg -i "$dir1/$file" -i "$dir2/$file" -map 1 -c copy \
   # copies all global metadata from in0.mkv to out.mkv  
   -map_metadata 0 \
   # copies video stream metadata from in0.mkv to out.mkv
   -map_metadata:s:v 0:s:v \
   # copies audio stream metadata from in0.mkv to out.mkv
   -map_metadata:s:a 0:s:a \

The metadata mapping command is adapted from the quoted answer.

If you want to make something reuseable you could put this in a script with the following header (remove the assignment for dir1, dir2 and output in the script above). And then call it as script.sh dir1 dir2 outdir

set -x errexit # exit immediately on error

Warning: I have no run any of these scripts.

  • Great! thanks for your helpful answer, exactly what I was looking for. – Adrian L Jan 21 '17 at 11:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.