Selecting embedded document instance with -p output?

Started by traycer, April 05, 2024, 06:23:42 PM

Previous topic - Next topic

traycer

I would like to extract the GPS-derived time from my GoPro Hero 10 video files. Long story short, the EXIF timestamp in the MP4 header is not accurate, but the GPS one is. I have a script that renames the video files into MMDD-hhmmss.mp4 format, and I want that to be based on the GPS time.

Here's the output I see:

$ exiftool -m -ee -gpsdatetime 0201-073117.mp4
GPS Date Time                   : 2024:02:01 12:37:02.800
GPS Date Time                   : 2024:02:01 12:37:03.800
GPS Date Time                   : 2024:02:01 12:37:04.800
GPS Date Time                   : 2024:02:01 12:37:05.800
GPS Date Time                   : 2024:02:01 12:37:06.800
GPS Date Time                   : 2024:02:01 12:37:07.800
GPS Date Time                   : 2024:02:01 12:37:08.900
GPS Date Time                   : 2024:02:01 12:37:09.800
GPS Date Time                   : 2024:02:01 12:37:10.900
GPS Date Time                   : 2024:02:01 12:37:11.900
GPS Date Time                   : 2024:02:01 12:37:12.900
GPS Date Time                   : 2024:02:01 12:37:13.900
GPS Date Time                   : 2024:02:01 12:37:14.900
GPS Date Time                   : 2024:02:01 12:37:15.900
GPS Date Time                   : 2024:02:01 12:37:16.900
GPS Date Time                   : 2024:02:01 12:37:17.900
GPS Date Time                   : 2024:02:01 12:37:18.900
GPS Date Time                   : 2024:02:01 12:37:19.900

I only want the first instance of GPSDateTime, and through trial and error, I discover that this works:

$ exiftool -m -ee -doc1:gpsdatetime 0201-073117.mp4
GPS Date Time                   : 2024:02:01 12:37:02.800

So far, so good! I want to feed this into a script I will use the rename the files, so I do this:

exiftool -m -ee -p '$filename $doc1:gpsdatetime' 0201-073117.mp4
0201-073117.mp4 2024:02:01 12:37:02.800
 2024:02:01 12:37:02.800
 2024:02:01 12:37:02.800
 2024:02:01 12:37:02.800
 2024:02:01 12:37:02.800
 2024:02:01 12:37:02.800
 2024:02:01 12:37:02.800
 2024:02:01 12:37:02.800
 2024:02:01 12:37:02.800
 2024:02:01 12:37:02.800
 2024:02:01 12:37:02.800
 2024:02:01 12:37:02.800
 2024:02:01 12:37:02.800
 2024:02:01 12:37:02.800
 2024:02:01 12:37:02.800
 2024:02:01 12:37:02.800
 2024:02:01 12:37:02.800
 2024:02:01 12:37:02.800
 2024:02:01 12:37:02.800

Why does -p repeat the timestamp? I noticed it is repeated as many times as there are timestamps originally, but now it repeats the same one over and over again. It works fine without -p, so what am I doing wrong?


StarGeek

From the docs on the -ee (-extractEmbedded) option, with a slight edit to include a link
QuoteImplies the -a (-duplicates) option option.

If you remove the -ee and don't include the -a option, then you sould only get one entry and wouldn't need to include the doc number
exiftool -m -p '$filename $gpsdatetime' 0201-073117.mp4
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

traycer

Quote from: StarGeek on April 05, 2024, 09:50:14 PMIf you remove the -ee and don't include the -a option, then you sould only get one entry and wouldn't need to include the doc number

I need -ee to extract the additional GoPro metadata, though. I did try --a (two hyphens to disable duplicates), but that doesn't work either. I suspect it is because the tags are in different groups? Adding -G0:1:2:3:4:

$ exiftool -m -ee -G0:1:2:3:4 -gpsdatetime 0204-153353.mp4
[GoPro:Track4:Time:Doc1] GPS Date Time          : 2024:02:04 20:33:53.900
[GoPro:Track4:Time:Doc2:Copy1] GPS Date Time    : 2024:02:04 20:33:56.200
[GoPro:Track4:Time:Doc3:Copy2] GPS Date Time    : 2024:02:04 20:33:57.200
[GoPro:Track4:Time:Doc4:Copy3] GPS Date Time    : 2024:02:04 20:33:58.200
[GoPro:Track4:Time:Doc5:Copy4] GPS Date Time    : 2024:02:04 20:33:59.200
[GoPro:Track4:Time:Doc6:Copy5] GPS Date Time    : 2024:02:04 20:34:00.200
[GoPro:Track4:Time:Doc7:Copy6] GPS Date Time    : 2024:02:04 20:34:01.200

I'm wondering if the repeated output is a side effect of this:

QuoteWhen used with -ee, the -p option is evaluated for each embedded document as if it were a separate input file.


traycer

Fiddling some more, and discovered something curious. Recapping with a different file with shorter output:

$exiftool -m -ee -filename -doc1:gpsdatetime 0214-131209.mp4
File Name                       : 0214-131209.mp4
GPS Date Time                   : 2024:02:14 18:12:09.599

$exiftool -m -ee -p '$filename $doc1:gpsdatetime' 0214-131209.mp4
0214-131209.mp4 2024:02:14 18:12:09.599
 2024:02:14 18:12:09.599
 2024:02:14 18:12:09.599

But if I omit the -m (ignore minor warnings):

$ exiftool -ee -p '$filename $doc1:gpsdatetime' 0214-131209.mp4
0214-131209.mp4 2024:02:14 18:12:09.599
Warning: [Minor] Tag 'Doc1:filename' not defined - 0214-131209.mp4

It aborts when it encounters a missing tag. I didn't notice the leading space in the repeated lines above. Confirmed by adding -f:

$exiftool -ee -f -p '$filename $doc1:gpsdatetime' 0214-131209.mp4
0214-131209.mp4 2024:02:14 18:12:09.599
- 2024:02:14 18:12:09.599
- 2024:02:14 18:12:09.599

It seems exiftool is still iterating through all the embedded docs, even though I specifically ask only for Doc1.  If it is going through Doc1, Doc2, Doc3, etc. why is it printing $gpsdatetime from Doc1 over and over again?

If I omit the -f but add in -q -q to suppress all warnings, I finally get the output I want, though it seems a bit fragile since it relies on $filename not existing in the embedded metadata.

$ exiftool -q -q -ee -p '$filename $doc1:gpsdatetime' 0214-131209.mp4
0214-131209.mp4 2024:02:14 18:12:09.599


StarGeek

You might want to look into the details of the -p (-printFormat) option and create a FMT file, as it sounds like you're making complex output.  Specifically, using #[SECT], though it's hard to tell without knowing more about your full command.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

traycer

Quote from: StarGeek on April 05, 2024, 10:53:42 PMSpecifically, using #[SECT], though it's hard to tell without knowing more about your full command.

I'm not sure a format file will help in this case, since I literally just want "$filename $gpsdatetime" output, one per file. The issue is that the -p option seems to output a single tag multiple times.

The intent is to rename the video files based on the GPS timestamp rather than the EXIF timestamp. The reason for this is because of the way the GoPro Hero 10 timestamps its files when in HindSight mode. It will begin recording video at a certain time, but only start saving out the video track with either a -15s or -30s time offset when the shutter button is pressed. Thus, the Track Creation Date is when the recording starts, which could be many minutes or sometimes hours before the actual video data is saved.

StarGeek

It took me some time digging around the net to find a good sample that had GPS data to do some testing, but I finally found some.

Quote from: traycer on April 05, 2024, 10:47:58 PMIt seems exiftool is still iterating through all the embedded docs, even though I specifically ask only for Doc1.

Ah, from the docs
QuoteWhen -ee (-extractEmbedded) is combined with -p, embedded documents are effectively processed as separate input files.

So when using -p, every GPSDateTime is Doc1:GPSDateTime.

Quote from: traycer on April 07, 2024, 08:13:51 AMThe intent is to rename the video files based on the GPS timestamp rather than the EXIF timestamp.

If you want to rename the file, then don't use the -p option.  Rename directly.
C:\>exiftool -ee -d "%Y-%m-%d_%H.%M.%S%%+c.%%e" "-Testname<Doc1:GPSDateTime" Y:/!temp/x/y/goprosample/Hero9 sample.MP4
'Y:/!temp/x/y/goprosample/Hero9 sample.MP4' --> 'Y:/!temp/x/y/goprosample/2021-09-15_17.48.15.MP4'
    0 image files updated
    1 image files unchanged

If you want to extract the data for other parts of the script, then try the -s3 (-short3) option.  You just have to parse on new line rather than comma
C:\>exiftool -s3 -filename -Doc1:GPSDateTime -ee Y:/!temp/x/y/goprosample/Hero9 sample.MP4
Hero9 sample.MP4
2021:09:15 17:48:15.374
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype