-1

I have an MP4 from a GoPro with a gpstrack included. Now I am trying to extract a geotagged image sequence from that video. For that I am currently using FFmpeg and exiftool; I'm open to better solutions.

I have never used FFmpeg nor exiftool before and am only a beginner using powershell so this is the script I prompted myself from GPT:

$skriptFolder = Split-Path $MyInvocation.MyCommand.Path
$framerate = Read-Host "Enter framerate"
foreach ($video in (Get-ChildItem -Path $skriptFolder -Filter *.mp4)) {
    $videoName = $video.BaseName
    $outputFolder = Join-Path $skriptFolder $videoName
    if (-not (Test-Path -Path $outputFolder)) {
        New-Item -ItemType Directory -Path $outputFolder | Out-Null
    }
    ffmpeg -i $($video.FullName) -vf fps=$framerate $outputFolder\$videoName-%04d.png
    exiftool -p C:\Windows\gpx.fmt -ee3 $video.FullName -w .gpx

    exiftool -tagsfromfile $video.FullName -XMP:DateTimeOriginal<CreateDate $outputFolder
    exiftool -geotag "$videoName.gpx" "-Geotime=XMP:DateTimeOriginal+=0:0:${filesequence;$_*=1/$framerate}" $outputFolder\*.png
}
Read-Host "Press enter to exit"

I can successfully create the images and the GPX file. But then I get stuck with matching the gps data and the images. The problem I think is, that the DateTimeOriginal does not get copied from the original videofile. Also I am not sure if I implemented the file sequence correctly.

This is my error message I still get:

Warning: Invalid date/time (use YYYY:mm:dd HH:MM:SS[.ss][+/-HH:MM|Z]) in File:Geotime (ValueConvInv)

0

1 Answer 1

1

I can't fully answer your question, but here are the problems related to exiftool.

RE: UTF16 output. PowerShell is changing exiftool's output from UTF8 to UTF16 during the shell redirection to the file. This is usually a problem when redirecting/piping binary data, as it will completely corrupt the data, but as you can see, it can also be a problem with text data. See this exiftool forum's post and this post.

RE: DateTimeOriginal The first problem is that DateTimeOriginal doesn't exist in the extracted files. All the files need to be set with a default value before the -DateTimeOriginal+=0:0:$filesequence command. See this Photo.StackExchange question.

Additionally, the command is incrementing the default location for DateTimeOriginal, which will be in the EXIF group e.g. EXIF:DateTimeOriginal. But the Geotag command is using XMP:DateTimeOriginal, which is a similar tag, but in the XMP group. And for what you are doing, you want to write to the XMP group, not the EXIF group. This requires changing

exiftool -DateTimeOriginal+=0:0:${filesequence;$_*=$framesteps} $outputFolder

into

exiftool -XMP:DateTimeOriginal+=0:0:${filesequence;$_*=$framesteps} $outputFolder

The reason you need to use XMP:DateTimeOriginal and not EXIF:DateTimeOriginal is because the latter does not include the subseconds, which are required for incrementing the time for each frame. See this StackOverflow answer.

But before you can increment anything, there must be a base time stamp to increment. This can get tricky, as most video time stamps need to be in UTC, but a lot of cameras are not aware of the local time zone and will write the local time.

Run this command to list all the date/time tags in the file

exiftool -time:all -G1 -a -s file.mp4

If there is a tag that has the correct time in UTC, then replace "TAG" in the following command with that tag name. Note that this command is for Windows CMD and the quoting rules are different for PowerShell, so you'll have to figure out the correct quotes

exiftool "-XMP:DateTimeOriginal<${TAG}+00:00" /path/to/files/

If there isn't a tag with the correct UTC time, then you will have to change the time zone from in that command from +00:00 to the correct one. For example, East Coast U.S. would be

exiftool "-XMP:DateTimeOriginal<${TAG}-05:00" /path/to/files/
8
  • thanks for all your answers! So far, exiftool does not touch the videofiles, only the images. How can I connect the timestamp from the video to the ffmpeg created images?
    – e-shirt
    Commented Mar 5 at 9:45
  • This is complicated as most video time stamps are supposed to set to UTC, but not all cameras will write it correctly. Updated answer to help with copying a base date/time.
    – StarGeek
    Commented Mar 6 at 15:54
  • Thanks again for the help. I checked the given timestamps using exiftool -time:all -G1 -a -s *.mp4 and there indeed is not DateTimeOriginal, but CreateDate is the timestamp I am looking for. So I added that part to my code. I updated my question above as I am still getting errors. The time is UTC so I skipped adding tz hours and moved the filesequence into the geotagging command, so I don't have to call exiftool so many times
    – e-shirt
    Commented Mar 7 at 7:53
  • This part ` -XMP:DateTimeOriginal=${CreateDate}` is Exiftool Common Mistake #5c. When copying tags, you use less/greater than signs </>. The equal sign is used to assign a static string. Also, in this use, you can drop the dollar sign, as that was only needed when adding a time zone (combining a tag and a static string). Try -XMP:DateTimeOriginal<CreateDate
    – StarGeek
    Commented Mar 7 at 18:01
  • sry for the late reply. I had already tested out both = and <. I had a warning to use = instead of < so I had switched it. I've now narrowed down my errors to this part: exiftool -geotag "$videoName.gpx" "-Geotime=XMP:DateTimeOriginal+=0:0:${filesequence;$_*=1/$framerate}" $outputFolder\*.png which now gives me this warning: Warning: Invalid date/time (use YYYY:mm:dd HH:MM:SS[.ss][+/-HH:MM|Z]) in File:Geotime (ValueConvInv) and I just can't see, where my timestamp is formatted wrong. Or does have to be +<0: as well here? then I get the above error again to use =
    – e-shirt
    Commented Mar 25 at 13:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .