4

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.

2

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.

1
  • I'm not able to check for myself if this works but I guess this should be the accepted answer, since you had the exact same issue I had and solved it successfully. Thank you very much! – user163919 Jan 24 '19 at 11:03
0

I found a convenient way to apply the tags from one file to another since this was my main goal.

Install tag via brew and proceed as follows:

tag -a "$(tag -Nl source_file)" destination_file

I'd still be more than interested if there was a way to apply all extended attributes from one file to another if there is any way.

You must log in to answer this question.