Replacing camera model information with user-defined abbreviations

Started by Lenni2, November 14, 2023, 03:14:08 AM

Previous topic - Next topic

Lenni2

Hi there,

I want to use Exiftool for renaming some 100.000 pictures from different cameras (including smartphones). The camera model should be the first part of the new filenames (probably the first 4-6 characters, by all means a fixed length!), the timestamps should go afterwards.

Everything works, however, I'm not satisfied with the camera model information which is either too generic (${Make;} e.g. reveals "Canon") or too verbose (${Model;} e.g. reveals "Canon PowerShot G1 X Mark III"), both unsuitable for to be included into a filename.

Is there a possibility to use user-defined "Model" strings as abbreviations with Exiftool alone, thus avoiding a time-consuming script loop with 100.000 calls of exiftool.exe? Perhaps some kind of a lookup table:

"Canon PowerShot G1 X Mark III" -> "CANON1"
"Canon EOS 7D" -> "CANON2"
"Panasonic DMC-FZ38" -> "PANA38"


so the filenames would be

CANON1_20231103_193422_001.jpg
CANON2_20230926_132855_001.jpg
PANA38_20231104_141209_001.jpg

Thank you.

Phil Harvey

You can do this with a config file to translate the Model names any way you want.  For example with this "my.config" file:

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        MyModel => {
            Require => 'Model',
            ValueConv => q{
                return 'CANON1' if $val =~ /^Canon PowerShot G1 X Mark III/;
                return 'CANON2' if $val =~ /^Canon EOS 7D/;
                return 'PANA38' if $val =~ /^Panasonic DMC-FZ38/;
                return undef;
            },
        },
    },
);
1;  #end

(I am just testing the start of the string in case they have trailing spaces, which often happens)

Then the command would be:

exiftool -config my.config "-filename<${mymodel}_${createdate}_%.3nc.%e" -d "%Y%m%d_%H%M%S" DIR

- 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 ($).

Lenni2

Hi Phil,

thank you for your fast reply - it works like a charm.

Would it also be possible to assign a special abbreviation if the image file's EXIF data doesn't contain a "Model" tag (or even no EXIF data at all)? I tried to replace the "undef" in your file with a string ('OTHER'), this works as long as a "Model" tag exists and I'm currently planning to use this approach for rarely used cameras for which I don't want to assign camera-specific prefixes. However, if no "Model" tag (or not EXIF data) exists, currently no renaming takes place.

Thanks again!

Phil Harvey

Sure.  All you have to do is Desire your tag Instead of Require-ing it, and add also Desire another tag that always exists.  For example:

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        MyModel => {
            Desire => {
                0 => 'Model',
                1 => 'FileName',
            },
            ValueConv => q{
                return 'CANON1' if $val =~ /^Canon PowerShot G1 X Mark III/;
                return 'CANON2' if $val =~ /^Canon EOS 7D/;
                return 'PANA38' if $val =~ /^Panasonic DMC-FZ38/;
                return 'OTHER';
            },
        },
    },
);
1;  #end

- 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 ($).

Lenni2

Hm - this one only replaces the "unknown" 'Model' tag with "OTHER" but doesn't rename the file without any EXIF data (this one should get a different prefix such as "UNKNOWN").

(I used the same parameters with my call to exiftool.exe for this test.)

Phil Harvey

The file needs to contain CreateDate metadata for that command to work.  Use this command to rename any file (FileModifyDate always exists):

exiftool -config my.config "-filename<${mymodel}_${filemodifydate}_%.3nc.%e" "-filename<${mymodel}_${createdate}_%.3nc.%e" -d "%Y%m%d_%H%M%S" DIR

- Phil

But I didn't change OTHER to UNKNOWN as you wanted...  I'll leave that as an exercise for you.
...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 ($).

Lenni2

Hi Phil,

the ${filemodifydate} did the trick here. Now it works as it should: Unknown cameras get an "OTHER" prefix while files without EXIF data get "UNKNOWN".

You really rock. Thank you very much for ExifTool and your help here, I really appreciate it. It's time for another donation!