Copy extended attributes to new file (ffmpeg)

I'm currently trying to decode some video files with ffmpeg on my computer but am not able to make ffmpeg copy the tags from the source file to the destination file. I read through the man page but there seems to be no way to extract the file tags from the source file or am I missing something?

I was able to extract the information via mdls but this isn't getting me anywhere. Also, I found about xattr and tried to apply extended attributes this way but the option -x seems to be removed and applying the attribute without that option doesn't work either.


Solution 1:

I needed this too—also after running FFmpeg!—so I wrote a shell script to do it. It’s not very quick, and it won’t work if any individual attribute contains more than about 128 KB of data. (Behind the scenes, it’s encoding each attribute value in hexadecimal to make sure that binary data is copied correctly.) It worked fine for my needs, though.

Save this to a file called copy_xattrs:

#!/usr/bin/env zsh

if [[ $# -ne 2 ]]; then
    print >&2 "usage: copy_xattrs SOURCE_FILE TARGET_FILE"
    exit 1
fi

set -e

IFS=$'\n' attr_names=($(xattr "$1"))
for attr in $attr_names; do
    value=$(xattr -p -x "$attr" "$1" | tr -d " \n")
    xattr -w -x "$attr" "$value" "$2"
done

Then run chmod u+x copy_xattrs to make it executable. Now you can run copy_xattrs source target to copy all of the extended attributes from the file source to the file target.