ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: b193709 on June 07, 2023, 01:37:57 PM

Title: One liner for a complex process
Post by: b193709 on June 07, 2023, 01:37:57 PM
Hi all:

First of all thanks for all your time and dedication on helping me on this question. I've write a bash script that makes many things based on a source of photos and videos. Some context:

1) Files are organized as this %Y/%m-%Y/%d-%m-%Y
>  exiftool -progress  -d "$2/%Y/%m-%Y/%d-%m-%Y/"  '-directory<datetimeoriginal'
(this is actually one example since there are many different date source depending on the file type)

2) I have all GPS info divided on months: %Y-%m.GPX > I.E 2013-03.GPX

3) I need also to modify timestamp. Sometimes I have correct timestamp (mobile), some others not (DSLR or Handycam). Therefore I need to add a division on the destination folder based on the timestamp (UTC)

4) Some of the photos does have GPS info.. some others not. I need apply GPS only to the ones that doesn't have. I saw https://exiftool.org/forum/index.php?topic=7330.0. I think I'm ok using -if "not ($GPSLatitude and $GPSLongitude)..


Now... all together... :-).. I need to read the correct GPX file, apply GPS if needed, and then put the file into the "$2/%Y/%m-%Y/%d-%m-%Y/¿$UTC?" destination folder.

I assume that I need to repeat the process for each %Y-%m.GPX file, therefore for each folder on which I previously organized all files for this month.

I'm having some issues that I need to avoid and that's the purpose of this long question:

1) There are many different creation time depending of the file format (ARW,MP4,JPG,MOV...). I don't see how can I avoid this without running many "one liners" with different date source. AFAIK:

datetimeoriginal > DV, mp4, mov. mpg, MTS, PNG, JPG, DNG, NEF, CR2
MediaCreateDate > m4v, mp4, mov
CreationDate > mp4 , mov

2) Is timezone universal on all formats?.



Finally.. can you suggest one liner for all this process?

My bash is slow and sooo complex.

Thanks!
Title: Re: One liner for a complex process
Post by: Phil Harvey on June 07, 2023, 02:21:41 PM
Time zones may be a headache, but a basic command to do what you want could look something like this:

exiftool -geotag "*.gpx" "-geotime<mediacreatedate" "-geotime<creationdate" "-geotime<createdate" "-geotime<datetimeoriginal" -if "not $gpslatitude" DIR

This should handle the multiple gpx files and the different time tags in the various formats (with later assignments on the command line taking precedence).

- Phil
Title: Re: One liner for a complex process
Post by: b193709 on June 07, 2023, 04:13:38 PM
Thanks a lot!..

I need to add couple of things to this liner. I need to take the correct GPS file, on the format %Y-%m.GPX, and also I need to move processed files to -d "$2/%m-%Y/%d-%m-%Y/" and also add at the end the TIMEZONE value as the last folder of this directory config.

Adding this to your liner, this should work?:

exiftool -geotag $a-$b.GPX "-geotime<mediacreatedate" "-geotime<creationdate" "-geotime<createdate" "-geotime<datetimeoriginal" -if "not $gpslatitude" DIR "$1/$a-$b/" -d "$2/%m-%Y/%d-%m-%Y/%Z"  "-directory<datetimeoriginal"
Where %1 is the source route folder and %2 the destination one, and $a is the month and the $b is the year (on my bash loop).

I should loop once this line for each "%Y-%m" source folder.

Should it be ok?

Thanks

Title: Re: One liner for a complex process
Post by: Phil Harvey on June 07, 2023, 08:55:18 PM
If you add a -d then you need to copy the unformatted date/time values to Geotime by adding a "#" to each.  But you still don't need to loop:

exiftool -geotag "*.GPX" "-geotime<mediacreatedate#" "-geotime<creationdate#" "-geotime<createdate#" "-geotime<datetimeoriginal#" -if 'not $gpslatitude' -r "$1" -d "$2/%m-%Y/%d-%m-%Y/%Z"  "-directory<datetimeoriginal"

I'm not sure what you mean by adding a TIMEZONE folder.

Also, due to your use of shell variables, I'll assume you're in a Unix-based shell, in which case you need to use single quotes around arguments containing ExifTool variables (as above).

You should run this on a test folder to see if it does what you want before setting it loose on all your files.

- Phil
Title: Re: One liner for a complex process
Post by: b193709 on June 08, 2023, 03:08:07 AM
Thanks again Phil.

Something that is not clear to me. I was force to divide my GPX files in months, because the unified file is so big and takes a while on loading it (minutes). How can Exif know where the GPX data is without reading all *:GPX files until it works?. This is the reason why I need to run a bash loop and point the correct GPX file to Exif.... isn't it?

The timeZone folder helps me on the next process I need to do. On my DSLR and HandyCam I left the TimeZone to UTC always. In parallel I record the timezone on which the photo has been taken. I need afterwards change it. I know that the file has to be change because UTC is 0. This is the reason of storing it on a separate folder.

Title: Re: One liner for a complex process
Post by: Phil Harvey on June 08, 2023, 07:12:48 AM
If loading all the GPX files together takes minutes, then loading them separately in a loop should also take minutes (actually longer because you need to re-load exiftool each time).  The only reason to divide them up is if you run into memory limitations or if the individual file processing time is longer with such a large number of GPS points.

- Phil
Title: Re: One liner for a complex process
Post by: b193709 on June 08, 2023, 04:36:09 PM
Well.. you're right. It's more than 150Mb.. takes minutes to load (all GPX file). I need to try. No problems with memory.

Thanks for your support.
Title: Re: One liner for a complex process
Post by: b193709 on June 09, 2023, 06:28:06 PM
Phil:

I saw that when the condition did not match (GPS) the photo is not moved. I would need all moves, and if the GPS info is not there, just add it. I don't know exactly what should be my modification.

Thanks
Title: Re: One liner for a complex process
Post by: Phil Harvey on June 10, 2023, 05:14:52 PM
That would be a 2-step process:

1. add GPS if it doesn't exist

2. move all the files

- Phil
Title: Re: One liner for a complex process
Post by: b193709 on June 11, 2023, 11:55:19 AM
Great.. thanks I'll divide.

Last question.. I promise. Exiftool will Geotag using my GPX file.. that's ok. Since the GPX info is based on UTC I guess there will be no problems with photos on UTC, but when my photos are UTC+1 or UTC+2.. etc?. Will Exiftool applies correctly the GPS position based on UTC info the photo has (refered to the UTC info I was when I took the photo)?.

Thanks
Title: Re: One liner for a complex process
Post by: Phil Harvey on June 12, 2023, 02:00:25 PM
If the date/time value used doesn't already contain a time zone, you may specify it when setting the Geotime value (see here (https://exiftool.org/geotag.html#geotime)), otherwise the system time zone is assumed.

- Phil
Title: Re: One liner for a complex process
Post by: b193709 on June 12, 2023, 03:19:52 PM
By bad... let me explain.

My goal is having sync all photos on the time that I lived.. therefore.. if I was 7:00 AM in Miami.. should be UTC-4. My DSLR and my Handycam are always on UTC.. therefore I need to change them manually, because I'll mix phone photos (that are always correct.. in my example 7:00 AM) and DSL (3:00 AM).

When I download and organize it, I need to correct videos and photos from my DSLR and handycam +4 Hours on this case. This is the reason why I add %z at the end on my line, in order to diff if it was UTC and I need to correct it.

About the Geotag, I know that GPX file is always on UTC. My question is, if my photo is taken on UTC-4 (I.E, if I decide change timezone on my DSLR) will exiftool takes my Geo position related to 3:00 AM UTC on my previous example?, on the 7:00 AM because exiftool knows that time on the photo is UTC-4?.



PD: i'm trying also to move the _original files to the destination folder that I sent the geotag photos, should be add another step on my script?. I saw -overwrite_original but it will delete the original.

Thanks
Title: Re: One liner for a complex process
Post by: Phil Harvey on June 12, 2023, 09:13:53 PM
We don't seem to understand each other.  ExifTool only uses the date/time/zone that you pass to the -geotime tag (or DateTimeOriginal# if not specified).  There is no other magic here other than the fact that ExifTool assumes the system time zone if the -geotime value that you set doesn't have a time zone.  Try extracting the tag you are using for setting -geotime to see exactly what ExifTool is using.

Moving the _original files to the destination folder will be tricky.  Maybe it would be best to start another topic for this.

- Phil