Author Topic: Renaming .MOV video files from DSLR  (Read 10345 times)

gerlos

  • Newbie
  • *
  • Posts: 4
Renaming .MOV video files from DSLR
« on: June 02, 2013, 12:50:26 PM »
Hello, I'm new here!  :)
I'm dealing with a large collection of media files from several different cameras and camcorders. I want to rename all of them with their creation date and time, maker and model. Everything using a bash script in Mac OSX.

I tried with:

exiftool -m -P '-filename<${DateTimeOriginal}_${Make}_${Model}.%e' ./*

It works fine for most files, obvilously for pictures, but also for .MTS videos from a camcorder (they are missing the "Model" tag, but I'm fine with the resulting name).

My problem is with .MOV videos from my Canon DSLR. They're missing the DateTimeOriginal tag (need to use the MediaCreateDate tag), and the Make tag.
But worst of all, after exiftool renamed them, they're missing the .mov extension.

So for example a file named "abc.mov" became "2013-05-31 18.13.05__Canon EOS 550D". I'v tried replacing the .%e from the name model, putting .mov instead, but exiftool drops it anyway.

1. How can I rename those file keeping their extension?
2. Is there a way I can check if a tag is there, and decide to use another one if that one is missing?

About this last question: I tried with something like:

if [ -n `exiftool -m -p '$DateTimeOriginal' filename]
then
...


But exiftool is dropping me an error, so the empty string check always fails. Any tip?

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 16680
    • ExifTool Home Page
Re: Renaming .MOV video files from DSLR
« Reply #1 on: June 02, 2013, 03:16:46 PM »
The missing extension is due to trailing nulls in the model name that weren't being properly removed.  This will be fixed in 9.31.  If you are using 9.30, you can work around this for now by adding a semicolon after "Model", like this: ${Model;}  Thanks for pointing out this problem, and for giving me enough details so I could reproduce it (knowing the model, I could use one of my samples here to test with).

Also, I would suggest using CreateDate since both JPG and MOV files should contain this tag.  The alternative would have been to use the exiftool -if option instead of your shell conditional.

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

gerlos

  • Newbie
  • *
  • Posts: 4
Re: Renaming .MOV video files from DSLR
« Reply #2 on: June 03, 2013, 04:46:21 PM »
you can work around this for now by adding a semicolon after "Model", like this: ${Model;} 

It works! Thanks!

Also, I would suggest using CreateDate since both JPG and MOV files should contain this tag.  The alternative would have been to use the exiftool -if option instead of your shell conditional.

Thanks for the tip about CreateDate: it works with JPGs and MOVs, but not with MTS files from my camcorder, that miss this tag and have DateTimeOriginal instead. :-(

About the -if option: I looked at the documentation, but didn't understand how could I use it to test for empty tags. Maybe it's because I'm not so familiar with perl (I know a little of python).
Can you please point me to an example closer to my use case, to understand it better?

Thanks again for your kindness and for such great piece of software!

regards
gerlos

gerlos

  • Newbie
  • *
  • Posts: 4
Re: Renaming .MOV video files from DSLR
« Reply #3 on: June 03, 2013, 05:40:47 PM »
Anyway, found what I think as an elegant solution to my problem:

#!/bin/bash
datemodel='%Y-%m-%d %H.%M.%S'
exiftool -preserve --ext MTS --ext MOV \
    -d $datemodel \
    '-filename<${CreateDate}_${Make}_${Model;}.%e' $@

exiftool -preserve -ext MTS \
    -d $datemodel \
    '-filename<${DateTimeOriginal}_${Make;}.%e' $@

exiftool -preserve -ext MOV \
    -d $datemodel \
    '-filename<${CreateDate}_${Model;}.%e' $@


Only one nuisance: after first pass, file names passed to exiftool from command line ($@) will be the same, but some of those may be already renamed in previous pass, so you'll get some File not found: messages in your terminal. Anyway, they don't annoy me.

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 16680
    • ExifTool Home Page
Re: Renaming .MOV video files from DSLR
« Reply #4 on: June 03, 2013, 06:25:23 PM »
I should have thought of this earlier:

exiftool -P -d '%Y-%m-%d %H.%M.%S' \
    '-filename<${DateTimeOriginal}_${Make;}.%e' \
    '-filename<${CreateDate}_${Make;}_${Model;}.%e' \
    '-filename<${DateTimeOriginal}_${Make;}_${Model;}.%e' \
    $@


This should do what you want in one command.  The last valid assignment supersedes the others.

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

gerlos

  • Newbie
  • *
  • Posts: 4
Re: Renaming .MOV video files from DSLR
« Reply #5 on: June 04, 2013, 09:17:54 PM »
exiftool -P -d '%Y-%m-%d %H.%M.%S' \
    '-filename<${DateTimeOriginal}_${Make;}.%e' \
    '-filename<${CreateDate}_${Make;}_${Model;}.%e' \
    '-filename<${DateTimeOriginal}_${Make;}_${Model;}.%e' \
    $@


This should do what you want in one command.  The last valid assignment supersedes the others.

Great! I didn't know this trick was possible!

Just needed a little rearranging to make it work with my files. I'm writing it here to help others with my same setup:

exiftool -P -d '%Y-%m-%d %H.%M.%S' \
    '-filename<${CreateDate}_${Model;}.%e' \
    '-filename<${DateTimeOriginal}_${Make;}.%e' \
    '-filename<${DateTimeOriginal}_${Make;}_${Model;}.%e' \
    $@


I'm also attaching an Automator app for Mac OSX users that want to use it with their files: just drop files on it, and exiftool will rename them in place using this command.

Thank you again!!!

metso

  • Newbie
  • *
  • Posts: 7
Re: Renaming .MOV video files from DSLR
« Reply #6 on: August 19, 2013, 04:06:50 PM »
Hello Gerlos,

Having searched the forum and found your post I am hopeful you may be able to help me.

I am wishing to create an automator workflow to rename a selected number of .mov files with their respective focal length.

Because I am using a zoom lens I can never know for sure what the lens size is,

so I wish to change from the original file name

MVI_0013.MOV (supposing this was a 55mm)
MVI_0014.MOV (supposing this was a 35mm)
MVI_0015.MOV (supposing this was a 25mm)
MVI_0016.MOV (supposing this was a 55mm)
MVI_0017.MOV (supposing this was a 45mm)
MVI_0018.MOV (supposing this was a 135mm)

to

description_55mm_tk1.mov
description_35mm_tk2.mov
description_25mm_tk3.mov
description_55mm_tk4.mov
description_45mm_tk5.mov
description_135mm_tk6.mov

I've already written the automator element to add the description and the sequential tk number, But I also wish to include the focal length.

I'm figuring you can extract the focal length and write it to the filename.

I've adapted your script to
do
   exiftool -P -d '%S' \
       '-filename<${FocalLength;}.%e' \
       "$fname"
done
and i've managed to rename the file to
55.0 mm.MOV

but I can only do one at a time,

is there a way of making it name a multiple and formating the name so that it renames it as follows:

55_0mm.mov

thanks for your help.
« Last Edit: August 19, 2013, 04:22:56 PM by metso »

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 3776
Re: Renaming .MOV video files from DSLR
« Reply #7 on: August 19, 2013, 04:48:35 PM »
First of all, you could probably remove the -d '%S' part.  The -d is used to set the date format and since you're not using the date in the rename, it isn't needed.

Try using this to remove the space:
'-filename<${FocalLength;s/ /_/}.%e' \

The s/ /_/ performs a regex substitution, changing spaces into underlines in the FocalLength variable.
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

metso

  • Newbie
  • *
  • Posts: 7
Re: Renaming .MOV video files from DSLR
« Reply #8 on: August 19, 2013, 06:21:13 PM »
i wish I could go further but all I seem to get now is
The action “Run Shell Script” encountered an error. Check the actionʼs properties and try running the workflow again.

this happens on the original "renshot" file that Gerlos uploaded and was working fine.

I'm wondering if there is something in a cache somewhere, because i've downloaded it again and I still get the same error...

driving me a little crazy...

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 16680
    • ExifTool Home Page
Re: Renaming .MOV video files from DSLR
« Reply #9 on: August 20, 2013, 06:49:47 AM »
Sounds like maybe the automator just isn't finding ExifTool.  Try starting with something simple to see if it works.  Maybe a shell script like this:

echo "hello world"

and then an exiftool command like this:

exiftool -echo "hello world"

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

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 3776
Re: Renaming .MOV video files from DSLR
« Reply #10 on: August 20, 2013, 01:14:58 PM »

Sorry, I didn't look closely enough at what you wanted.  I see now that you wanted to remove the spaces and change the dots into underscore.  I believe this will do what you want.

'-filename<${FocalLength;s/ //;s/\./_/}.%e' \
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

metso

  • Newbie
  • *
  • Posts: 7
Re: Renaming .MOV video files from DSLR
« Reply #11 on: August 30, 2013, 06:08:48 PM »
Sorry its taken me so long to respond, (busy at work)

Firstly thank you, Phil, Stargeek for your helpful reply.

I worked out why automator wasn't working, basically I had one file which I trimmed down to a reasonable size and duplicated it, so when automator tried to extract the focal length and rename the file according to the exif data, once it renamed the first file it couldn't write the second file because the file name would be the same as the first.

Stargeek,

'-filename<${FocalLength;s/ //;s/\./_/}.%e' \ worked with my second attempt having tested the automator service using unique files.

this kind of solves one of my requirements.

Basically,

I am trying to create an automator service to rename a bunch of files based on some user input variables.

these variables are
asking the user if the footage is
1) Witness (W), or Reference (R) footage
2) Cam A (A), B (B), or C (C)
3) Slate

this bit i've managed to work out
but I'm having trouble using exiftool to extract the focal length as a variable so I can recreate a new filename based on the user input.

As an example my intention is to rename the following file names:

using the following variables
Slate : 27A, Witness (W), Cam (A)
MVI_0007.mov
MVI_0008.mov
MVI_0009.mov
MVI_0010.mov
MVI_0011.mov
MVI_0012.mov

as

027A_tk7_WA_55mm.mov
027A_tk8_WA_55mm.mov
027A_tk9_WA_55mm.mov
027A_tk10_WA_55mm.mov
027A_tk11_WA_55mm.mov
027A_tk12_WA_55mm.mov

If you could help me get the focal length output as a variable i'll be able to write it to the filename.

thanks once again for your help.

metso

  • Newbie
  • *
  • Posts: 7
Re: Renaming .MOV video files from DSLR
« Reply #12 on: September 01, 2013, 06:19:24 AM »
I realize i'm trying to run before I can walk here with what i'm trying to accomplish

so trying to break it down step by step,

the first problem I am getting is (in my example of files)
using the code

'-filename<${FocalLength;s/ //;s/\./_/}.%e' \


MVI_0007.mov (18mm.mov)
MVI_0008.mov (10mm.mov)
MVI_0009.mov (20mm.mov)
MVI_0010.mov (18mm.mov)
MVI_0011.mov (18mm.mov)
MVI_0012.mov (18mm.mov)

once the code

reaches the file
MVI_0010.mov (18mm.mov)
the automator workflow stops because it cannot write another file 18mm.mov because it already exists

To solve this, I hoped added a sequential number would help to make each file have a unique name. This would also help because the sequential number could be part of the take number

searching the forum I found this:
https://exiftool.org/forum/index.php?topic=4660.0

though having found this, I have no idea how to add this to the code to give me a sequential number.

i've tried adjusting the code


IFS=$(echo -en "\n\b")
while read fname
do
   exiftool \
       '-filename<${FocalLength;s/ //;s/\./_/-.2nc.}.%e ' \
      "$fname"
done


this doesn't work,

appreciate your help with this.

thankyou

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 16680
    • ExifTool Home Page
Re: Renaming .MOV video files from DSLR
« Reply #13 on: September 01, 2013, 06:38:08 AM »
The copy number is added outside the braces, with a leading '%'.  Try this:

'-filename<${FocalLength;s/ //;s/\./_/}%-.2nc.%e'

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

metso

  • Newbie
  • *
  • Posts: 7
Re: Renaming .MOV video files from DSLR
« Reply #14 on: September 01, 2013, 07:03:29 AM »
this kind of works
but
reorders the order of the files and
doesn't give a sequential number

using the code on the following
MVI_0007.mov
MVI_0008.mov
MVI_0009.mov
MVI_0010.mov
MVI_0011.mov
MVI_0012.mov

gives the following result:

10.0_mm-01.mov
17.0_mm-01.mov
18.0_mm-01.mov
18.0_mm-02.mov
18.0_mm-03.mov
55.0_mm-01.mov