Limit / truncate keywords for .MOV files

Started by eyeidea, January 18, 2024, 11:24:11 PM

Previous topic - Next topic

eyeidea

Hello, I have been searching and reading and experimenting all day. I am trying to get ExifTool to reduce the number of keywords in many thousands of Quicktime videos. I need to limit the number of keywords to 50. Many videos have less than 50 and many have 50+.

This post was close but I got errors and it made a copy of my video and added "_original" ...
https://exiftool.org/forum/index.php?topic=8674.0

I am on MacOS/Bridge using the Terminal; I changed "keywords" to "subject" ...

exiftool -sep xxx '-subject<${subject;my @a=split /xxx/,$val;$#a>49 and $#a=49;my @b=splice(@a,0,8);push @b,splice(@a,rand(@a),1) while @a;$_=join 'xxx',@b}' /Volumes/EyeRaid\ xHDD/EYEIDEA/EYEIDEA\ Stock/Stock\ Animations/4K\ Stock\ Video\ Masters/Breaking-News-RedBlue-Broadcast-Title-4K-v2.mov
Warning: Bareword "xxx" not allowed while "strict subs" in use for 'subject' - /Volumes/EyeRaid xHDD/EYEIDEA/EYEIDEA Stock/Stock Animations/4K Stock Video Masters/Breaking-News-RedBlue-Broadcast-Title-4K-v2.mov
    1 image files updated

Any help would be very much appreciated!

Chad

StarGeek

Quote from: eyeidea on January 18, 2024, 11:24:11 PMThis post was close but I got errors and it made a copy of my video and added "_original"

From the docs, second paragraph under "Description"
QuoteBy default, the original files are preserved with _original appended to their names -- be sure to verify that the new files are OK before erasing the originals.

You can suppress the originals with the -overwrite_original option, though if you make use of the Mac's Finder metadata, which are part of the file system, then the -overwrite_original_in_place option is needed to keep those.  But that does cause the processing time to be doubled.

Quoteexiftool -sep xxx '-subject<${subject;my @a=split /xxx/,$val;$#a>49 and $#a=49;my @b=splice(@a,0,8);push @b,splice(@a,rand(@a),1) while @a;$_=join 'xxx',@b}' /Volumes/EyeRaid\ xHDD/EYEIDEA/EYEIDEA\ Stock/Stock\ Animations/4K\ Stock\ Video\ Masters/Breaking-News-RedBlue-Broadcast-Title-4K-v2.mov
Warning: Bareword "xxx" not allowed while "strict subs" in use for 'subject' - /Volumes/EyeRaid xHDD/EYEIDEA/EYEIDEA Stock/Stock Animations/4K Stock Video Masters/Breaking-News-RedBlue-Broadcast-Title-4K-v2.mov
    1 image files updated

That error tells you there's a problem with "xxx".  If you compare your command to the original looking at the parts with "xxx", you will see that you changed
$_=join "xxx",@b
into
$_=join 'xxx',@b

Change it back and see if it works then.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

eyeidea

Thank you StarGeek,

I ran this ...

exiftool -sep -overwrite_original xxx "-subject<${subject;my @a=split /xxx/,$val;$#a>49 and $#a=49;my @b=splice(@a,0,8);push @b,splice(@a,rand(@a),1) while @a;$_=join "xxx",@b}" /Volumes/EyeRaid\ xHDD/EYEIDEA/EYEIDEA\ Stock/Stock\ Animations/4K\ Stock\ Video\ Masters/3D-Wireframe-Running-Man-Orbit-4K-30-Alpha-v2.mov
zsh: bad substitution

I think I read that because I am on MAC OS I need to change " " to ' '

Phil Harvey

On MacOS you need to do this.  (Outer quotes must be single.)

exiftool -sep -overwrite_original xxx '-subject<${subject;my @a=split /xxx/,$val;$#a>49 and $#a=49;my @b=splice(@a,0,8);push @b,splice(@a,rand(@a),1) while @a;$_=join "xxx",@b}' /Volumes/EyeRaid\ xHDD/EYEIDEA/EYEIDEA\ Stock/Stock\ Animations/4K\ Stock\ Video\ Masters/3D-Wireframe-Running-Man-Orbit-4K-30-Alpha-v2.mov

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

eyeidea

Thank you Phil,

Ran that ...

exiftool -sep -overwrite_original xxx '-subject<${subject;my @a=split /xxx/,$val;$#a>49 and $#a=49;my @b=splice(@a,0,8);push @b,splice(@a,rand(@a),1) while @a;$_=join "xxx",@b}' /Volumes/EyeRaid\ xHDD/EYEIDEA/EYEIDEA\ Stock/Stock\ Animations/4K\ Stock\ Video\ Masters/DataConst-4K-v8.mov
Warning: Error opening file - xxx
Error: File not found - xxx
    1 image files updated
    1 files weren't updated due to errors

It also did create a copy, and I still have 59 keywords.

Thank you for help!
Chad


Phil Harvey

Hi Chad,

I should have paid more attention to your command.  I only fixed the quotes, but you've put the -overwrite_original between the -sep option and its argument, which won't work.  Try this:

exiftool -overwrite_original -sep xxx '-subject<${subject;my @a=split /xxx/,$val;$#a>49 and $#a=49;my @b=splice(@a,0,8);push @b,splice(@a,rand(@a),1) while @a;$_=join "xxx",@b}' /Volumes/EyeRaid\ xHDD/EYEIDEA/EYEIDEA\ Stock/Stock\ Animations/4K\ Stock\ Video\ Masters/DataConst-4K-v8.mov

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

eyeidea

It works!!! Hooray! Thank you so, so much, Phil.

Is there a way to retain file created/modified date? I think this is a MAC OS thing. I saw a post somewhere about it but that was 100 searches ago.

Phil Harvey

Add -P to the command to preserve FileModifyDate.  To preserve FileCreateDate, change -overwrite_original to -overwrite_original_in_place.  This is a special MacOS thing, and -overwrite_original_in_place is the only way to preserve the special MacOS attributes.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

eyeidea

Thank you so much, Phil!

We have made a donation to help support this great tool.

Very grateful for all the help.

Phil Harvey

I got the donation.  Much appreciated.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).