How to obtain Original Create time and its offset on any photo

Started by b193709, April 09, 2022, 05:02:21 PM

Previous topic - Next topic

b193709

Hi all:

I'm working on a script that tries to set any kind of photo / video (from Mobile, DSLR, old DSLR, etc etc) from it's Create time data to UTC 0.

What I found is that ARW format stores on different place that CR2, than MP4, than MOV, etc etc.

is there any way of read the source time on which the video/photo was taken (the one that the camera has), and its timezone?.

All my cameras are correctly sync, but when I travel, I don't change the timezone, therefore I'm looking for having everything on UTC 0.

The problem is I have thousands of photos / Videos that I need to organize and the are not on UTC 0

Thanks


StarGeek

Quote from: b193709 on April 09, 2022, 05:02:21 PM
is there any way of read the source time on which the video/photo was taken (the one that the camera has), and its timezone?.

It really depends upon the camera.  Some newer phones will set the EXIF time zone tags (EXIF:OffsetTimeOriginal/EXIF:OffsetTimeDigitized/EXIF:OffsetTime).  Some DSLRs will keep trace of the time zone if it is properly set in the camera.  You can usually find these in the MakerNotes.  For example, my Nikon holds the time zone in Nikon:TimeZone.  But that has to be correctly manually set.  And then, you have to manually set the Nikon:DaylightSavings to Yes or No whenever Daylight savings starts/ends.

But otherwise, there's no way of knowing the time zone if the camera either doesn't have it properly set or doesn't even save it in the first place.  Unless you know where the image was taken and are able to geotag it correctly.  GPS timestamps are set to UTC and geotagging programs can usually set things correctly if the coordinates and time stamps are correct.

"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

b193709

Thanks for the response.

I have a track of GPX data for my position 24h, so I can obtain the timezone using it. The problem is that I need to know the timezone the camera has when it shoot. The objective is set all those photos/videos to UTC 0. I saw that for my Sony DSLR, I have EXIF:OffsetTimeOriginal, I.E. But on CR2 format I need to find another, MP4 from videocam another... It's complex.

I wonder if I asking for  timezone (%z) to exiftool on '-datetimeoriginal' on any format will it reply the timezone the camera uses when writes the file, but I'm not looking for the information of the metadata of the file system, but the one related to the photo/video creation.



StarGeek

Quote from: b193709 on April 10, 2022, 03:55:31 AM
I wonder if I asking for  timezone (%z) to exiftool on '-datetimeoriginal' on any format will it reply the timezone the camera uses when writes the file

Exiftool cannot magically create the timezone out of nothing.  As per note #3 under Common Date Format Codes, if the time zone does not already exist in the image, then %z will return the computer's time zone.

You can use this command to see all available date/time tags in the file.
exiftool -time:all -G1 -a -s file.jpg

If you have the GPS data, your best bet is to find a GPS program that can do the look up for you.
"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

b193709

Thanks.

Maybe I have a concept issue here. AFAIK, all devices knows its timezone. I don't mean that this is the real one, but the one that is configured (manually) on each one. I.E > my video cam. my DSLR, etc.. all of them allows to set time and timezone. In my case, all are set to UTC 0 and time is correct.

Now, I suppose that all devices are able to add the timezone they have configured when the shot the photo, right?. Why is this important?, because it changes the time and when I try to sync with other devices that "knows" via GPS where are they, times for 2 instant photos are different (I.E.. from my mobile and from my DSLR).

I have ways to know the real timezone when I shot, but I need to extract the timezone/offset  that the camera had configured in  order to be able to set UTC 0 (if they are not already, because my fault), and then appy the correct timezone / offset time.

The original question was... if there is a unified way to know this (the configured camera one) timezone / offset, instead of multiple different ways based on each camera / photo raw format.

Thanks

StarGeek

Quote from: b193709 on April 10, 2022, 12:09:10 PMThe original question was... if there is a unified way to know this (the configured camera one) timezone / offset, instead of multiple different ways based on each camera / photo raw format.

No.  Different cameras and different file formats save data differently.  The command I give above will show you the locations of all time related data in the file and you'll have to proceed from there.
"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

Alan Clifford

I don't know if this is helpful to you but the way I approach it is for a script to refer to an adjustment file for the timezone offset.  For example, for a trip to South Africa, I had

photofilename   actual  datetimeoriginal
default         2       2
ft30_0821.jpg   2       1:10   
ft30_0826.jpg   2       1:10
ft30_0827.jpg   2       1:10
fz18_0040.jpg   2       -11:8:42

which shows the actual time zone and the time zone of exif:datetimeoriginal

I like to put my cameras to local time but, as can been seen above, my wife's camera was not quite correct.  And not all my cameras actually store the time zone anywhere in the photo metadata.  But two do, but in different formats.

The logic of using this is essentially:

if the photo is explicity named, use these values
otherwise use exif:offsettimeoriginal
otherwise use the nikon makernotes values
otherwise use the default value from the adjustment file

I then insert xmp:datetimeoriginal which allows for an offset and use that when matching against my gps logs.







b193709

Ok thanks for all your responses.

I end of creating a script that recognizes on each case what to do. I dump all exiftool output on an array and then I create many cases for each kind of photo/video case.


Martin Barta

I created a PowerShell script to help resolve the issue. I have a DSLR Camera, a Nikon 7200, and even with the same time zone settings as I have on my Samsung Galaxy S24 FE, the EXIF data is different. Once I uploaded images to Google Photos, I have to change/move the timestamp with _tra link for all the latest uploaded images from Nikon. However, if there are edited images or generated panoramas, they have an additional time zone offset, and I must manually adjust the timestamp or time zone. This script will add two new EXIF attributes if they are missing, and it resolves upload issues, eliminating the need for manual work and checks in the Google Photos Album.

<#
.SYNOPSIS
Adds OffsetTime and OffsetTimeOriginal EXIF tags to images where they're missing.

.DESCRIPTION
This script scans a folder for images and adds standard timezone EXIF tags to files
that don't have them, using the specified timezone offset.

.PARAMETER Path
Path to the folder containing images

.PARAMETER TimeZoneOffset
Timezone offset in ±HH:MM format (e.g., "+02:00")

.PARAMETER ExifToolPath
Full path to exiftool.exe (default: looks in PATH)

.EXAMPLE
.\Add-ExifTimezone.ps1 -Path "C:\Photos" -TimeZoneOffset "+02:00" -ExifToolPath "D:\Tools\exiftool.exe"

#>

param(
    [Parameter(Mandatory=$true)]
    [string]$Path,
   
    [Parameter(Mandatory=$true)]
    [string]$TimeZoneOffset,
   
    [string]$ExifToolPath = "exiftool"
)

# Validate timezone format
if (-not ($TimeZoneOffset -match "^[+-]\d{2}:\d{2}$")) {
    Write-Error "TimezoneOffset must be in ±HH:MM format (e.g., '+02:00')"
    exit 1
}

# Verify exiftool exists at specified path
if (-not (Test-Path $ExifToolPath)) {
    # Try to find in PATH if full path wasn't specified
    if ($ExifToolPath -eq "exiftool") {
        try {
            $exifTool = Get-Command exiftool -ErrorAction Stop
            $ExifToolPath = $exifTool.Source
        } catch {
            Write-Error "ExifTool not found at '$ExifToolPath' and not in PATH. Download from https://exiftool.org/ or specify full path with -ExifToolPath"
            exit 1
        }
    } else {
        Write-Error "ExifTool not found at '$ExifToolPath'"
        exit 1
    }
}

Write-Host "Using ExifTool at: $ExifToolPath" -ForegroundColor Cyan

# Get all image files
$files = Get-ChildItem -Path $Path -File |
    Where-Object { $_.Extension -match '\.(jpg|jpeg|nef|cr2|arw)$' }

if ($files.Count -eq 0) {
    Write-Host "No image files found in the specified directory." -ForegroundColor Yellow
    exit
}

Write-Host "Processing $($files.Count) files..." -ForegroundColor Cyan

foreach ($file in $files) {
    # Check if the file already has OffsetTimeOriginal
    $existingOffset = & $ExifToolPath -T -OffsetTimeOriginal $file.FullName
   
    if ($existingOffset -eq "-") {
        # File needs the timezone tags
        Write-Host "Adding timezone to $($file.Name)" -ForegroundColor Yellow
       
        # Use exiftool to add both tags
        & $ExifToolPath -overwrite_original `
            -OffsetTime="$TimeZoneOffset" `
            -OffsetTimeOriginal="$TimeZoneOffset" `
            $file.FullName
       
        if ($LASTEXITCODE -eq 0) {
            Write-Host "Successfully added timezone $TimeZoneOffset" -ForegroundColor Green
        } else {
            Write-Host "Failed to update $($file.Name)" -ForegroundColor Red
        }
    } else {
        Write-Host "$($file.Name) already has timezone: $existingOffset" -ForegroundColor Gray
    }
}

Write-Host "`nProcessing complete!" -ForegroundColor Cyan

StarGeek

Not to belittle your hard work, but you are looping exiftool, running it once for every file, and a second time if the file needs to be updated. This is Common Mistake #3, "Over-scripting". Exiftool's biggest performance hit is the startup time and running it once for every file will increase processing time substantially.

This can all be done with a single command.
exiftool -ext jpg -ext jpeg -ext nef -ext cr2 -ext arw -if "not $OffsetTimeOriginal" -OffsetTime*=±00:00 /path/to/files/

Here I'm using a wildcard to write OffsetTime, OffsetTimeOriginal, and OffsetTimeDigitized at the same time. Your original command wrote OffsetTime and OffsetTimeOriginal, but left out OffsetTimeDigitized, which is more important than OffsetTime.

I'm using the -ext (-extension) option to limit processing to specific file types.

You can use the -efile option to create a list of files that could not be edited
-efile /path/to/FailedFiles.txt

Additional information. The breakdown of these tags is
DateTimeOriginal, OffsetTimeOriginal: This is the time that the image was made.
CreateDate, OffsetTimeDigitized: This is the time that the image was turned into a digital file.
ModifyDate, OffsetTime: This is the time that the image itself has been changed or edited.

For digital cameras, the first two should be the same value. The difference only comes into effect if the original image was analog (i.e. a picture developed from film). DateTimeOriginal is when the analog image was originally created. CreateDate is the time that the image was digitized.
"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