ExifTool in script, Command not found

Started by Kipowsky, August 02, 2018, 11:29:00 AM

Previous topic - Next topic

Kipowsky

Hi.

I have been trying to execute this script (Automator, Shell script) with ExifTool and FFmpeg commands, that I found on this thread (https://discussions.apple.com/thread/8264251) and when I run it I always get this error: "line 31:exiftool:command not found" and the same for line 32 and 33. Those are the three lines in the code with exiftool. I have tried the command in Terminal on a file and it works, I get a variable with for instance "$make" or "$model" that I can see with "echo". And I have tried looking at forums and manuals and exiftool tags and so on and I am lost.

Perhaps it's a problem with the first part of the script, getting the actual file name ("$fullpath") and that's where the problem is?

I use the script in an Automator schell script, with settings "The service receives marked FILES OR FOLDERS in FINDER" with shell "bin/bash" and Pass input "as argument". Sorry about images being in Swedish.

I do appreciate any help I can get. Thank you!

Kip



#Script starts with the next line
#!/bin/bash
if [ $# -eq 0 ]
  then
    echo "Converts an AVI video file to a MOV (QuickTime) video file. Transfers metadata for OriginalDate, Make and Model from the source file."
    echo "usage: $0 filename(s)"
fi

for fullpath in "$@"
do
    # Strip longest match of */ from start
    filename="${fullpath##*/}"

    # Substring from 0 thru pos of filename
    dir="${fullpath:0:${#fullpath} - ${#filename}}"

    # Strip shortest match of . plus at least one non-dot char from end
    base="${filename%.[^.]*}"

    # Substring from len of base thru end
    ext="${filename:${#base} + 1}"

    # If we have an extension and no base, it's really the base
    if [[ -z "$base" && -n "$ext" ]]; then
        base=".$ext"
        ext=""
    fi

    echo -e "$fullpath:\n\tdir  = \"$dir\"\n\tbase = \"$base\"\n\text  = \"$ext\""

    # Get tags from source file
    originalDateTag=$(exiftool -d '%Y-%m-%d %H:%M:%S' -p '$DateTimeOriginal' "$fullpath")
    makeTag=$(exiftool -p '$make' "$fullpath")
    modelTag=$(exiftool -p '$model' "$fullpath")
    echo -e "$fullpath --> $outFullpath\n\toriginalDate: $originalDateTag\n\tMake: $makeTag\n\tModel: $modelTag"

    # Set remux options according to camera model
    case $modelTag in
        EX-FH100)
            convertOptions="-c:v copy -q:a 0"
            outFullpath="$dir$base.mov"
            ;;
    FinePix\ F100fd)
            convertOptions="-c:v mjpeg -q:v 0 -q:a 0"
            outFullpath="$dir$base.mov"
            ;;
    *)
            echo "No EX-FH100 or FinePix F100fd input file found"
            exit 1
    esac

    # Convert movie
    ffmpeg -i "$fullpath" $convertOptions -metadata "make=$makeTag" -metadata "model=$modelTag" -metadata "creation_time=$originalDateTag" "$outFullpath"
done

# Script ended theline before this line

Phil Harvey

This happens because exiftool is in /usr/local/bin, and that directory apparently isn't in the automator PATH.

Replace "exiftool" with "/usr/local/bin/exiftool" in the script and it should work.

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

Kipowsky

Worked like a charm! I also had to do the same with "ffmpeg" and then it worked all the way!

You have just saved my day. And many hours to come otherwise chasing the solution (already spent 2 days on it...) :D

Kipowsky

One more question, on the same matter. To set the creation date, the original time date, FFmpeg uses the specifier "-metadata "creation_time=", but once done, in ExifTool it shows as "CreateDate" or "TrackCreateDate" or "MediaCreateDate". All three of those show in the .MOV file the date and time I got from the first .AVI file. But nowhere I can find documentation about what specifiers I can use in FFmpeg and almost nowhere it's referenced as "creation_time"...

I have been looking like crazy for a list of metadata specifiers I can use. I have found plenty, for different formats (QT Mov, AVI, etc) and different cameras, but no-one mentions "creation_time" and I don't know which works in FFmpeg. So if I want to copy for instance "Video Codec" or "Compression" or "Macro" or "Focus Mode" or anything else of the metadata from the original video - what is correct FFmpeg metadata specifier to use? Perhaps there is no such list?  :(

Thank you!


Phil Harvey

Sorry, but I can't help with ffmpeg questions.  Here is a complete list of MP4 tags recognized by ExifTool, indicating which ones are writable.

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