Select correct file extension when using "-picture -b" option

Started by nixda, September 22, 2013, 09:20:19 AM

Previous topic - Next topic

nixda

Hello again,

This command works good. T
exiftool -picture -b input.mp3 > output.jpg

The problem is the name of the output file. I have a picture viewer (NexusImage) which relies on a correct file extension.
Some of my mp3 files have a PNG file embedded rather than a typical JPG. My command extracts them and name it "output.jpg" even when its actually a PNG

How can I tell exiftool to use "output.png" as output filename when a PNG is embedded and "output.jpg" when a JPG is embedded?

If you need two example mp3 files: http://ge.tt/7dvBnis?c
One with embedded JPG cover and one with embedded PNG cover

Phil Harvey

#1
This can be accomplished using 2 different techniques:

1) using the -if option and 2 commands, one for each file type

exiftool -if '$picturemimetype eq "image/jpeg"' -picture -b -w jpg -ext mp3 DIR
exiftool -if '$picturemimetype eq "image/png"' -picture -b -w png -ext mp3 DIR


(the above quoting is for Mac/Linux)

or

2) using the new -W option with %s for the output file extension

exiftool -picture -b -W %d%f.%s -ext mp3 DIR

The second command also has the advantage that it can be used to extract multiple pictures from a single mp3 file (all you need to do is add -a to the command, and some form of %c to the output file name format string).

Read the application documentation for details.

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

nixda

old command (this works, but my initial problem still stands)
:: both PNG and JPG covers will have the same extension .JPG
:: has the advantage that you can specify a new output file and a single input file - and not whole folders like the below solutions
exiftool -picture -binary D:\input\JPG_file.mp3 > D:\output\JPG_file.jpg
exiftool -picture -binary D:\input\PNG_file.mp3 > D:\output\PNG_file.jpg


:: new solution #1 by Phil
:: says: File not found: eq  File not found: image/png'
exiftool -if '$picturemimetype eq "image/jpeg"' -picture -b -w jpg -ext mp3 D:\input
exiftool -if '$picturemimetype eq "image/png"' -picture -b -w png -ext mp3 D:\input
:: so I played around and substituted eq with = , replaced single quotation with double quotation, nothing helped
exiftool -if "$picturemimetype = image/jpeg" -picture -binary -w jpg -ext mp3 D:\input
exiftool -if "$picturemimetype = image/png" -picture -binary -w png -ext mp3 D:\input


:: new solution #2 by Phil
:: says: no files specified
exiftool -picture -binary -W %d%f.%s -ext mp3 D:\input
:: when I replace "%s" with ".JPG", the command does work
:: But that doesn't solve my problem where a proper extension should be chosen automatically
:: whats more interesting, this command fails to read the PNG_test.mp3 file whereas my old command can process both files O.o
exiftool -picture -binary -W %d%f.jpg -ext mp3 D:\input


I have two questions:
- Whats the correct syntax for automatically choose a proper file extension
- How can I use a potential solution to specify a single input file and a different output folder/file


Phil Harvey

Case number 1 didn't work because the quoting is for Mac/Linux.  Exchange the single for double quotes since you are on Windows.

Case number 2 won't work if you are a version of ExifTool older than 9.23

Also, if you are running in a Windows .bat file you will need to double all "%" characters.

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

nixda

Hello Phil,

thank you for being so patient with me. But I was already on the newest exiftool version (case 2). And as said above, I already exchanged the single quotations against double quotation marks (case 1)

exiftool -if "$picturemimetype eq "image/png"" -picture -b -w png -ext mp3 D:\input

The system cannot find the path specified.
    1 directories scanned
    2 files failed condition
    0 image files read
    0 output files created


"D:\input" is my input folder with 2 mp3 files with PNG covers embedded




exiftool -picture -binary -W %d%f.%s -ext mp3 D:\input
Despite the fact that I am on exiftool v9.37 (according to -ver and redownloading), "%s" doesn't work for me

I guess I am not able to understand the syntax

Phil Harvey

Quote from: nixda on September 22, 2013, 04:12:51 PM
exiftool -if "$picturemimetype eq "image/png"" -picture -b -w png -ext mp3 D:\input

The system cannot find the path specified.
    1 directories scanned
    2 files failed condition
    0 image files read
    0 output files created

Odd.  I have no idea what this error message means.  It is not an exiftool error.  Regardless, ExifTool found 2 MP3 files in the specified directory, but your condition failed, perhaps because your quoting is still incorrect.  It should be:

exiftool -if "$picturemimetype eq 'image/png'" -picture -b -w png -ext mp3 D:\input

Quoteexiftool -picture -binary -W %d%f.%s -ext mp3 D:\input
Despite the fact that I am on exiftool v9.37 (according to -ver and redownloading), "%s" doesn't work for me

You still get a "no files specified" warning?  Odd again.  The command works fine for me exactly as typed above.  If this doesn't work for you, the only thing I can think of is that your exiftool installation is corrupt.  Follow the Windows uninstalling instructions, then try again.

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