How to convert UNIX timestamps in millisecond from filename to EXIF

Started by candura, May 05, 2024, 05:00:06 AM

Previous topic - Next topic

candura

Hello guys,

I got some image filenames look like this:
1659149646663.jpg
1659872441525_uri_mr1659872605760.jpg
img_recovered_mh1662796673522.jpg
mmexport1660272922426_mh1660278339342.jpg
uri_mh1671600543809.jpg
...
The numeric part is the Unix timestamp in milliseconds.

When I use this command to write the EXIF information
exiftool -d "%s" "-DateTimeOriginal<fileName" 1659149646663.jpgThe DateTimeOriginal becomes 4546-05-12 05:51:03

I tried to pick the first 10 digits of the filename with a regular expression
exiftool -d "%s" "-DateTimeOriginal<$'{fileName;m/(\d{10})/;$_=$1}" 1659149646663.jpgBut I got this error
Warning: No writable tags set from 1659149646663.jpgI think it's because I didn't write the regular expression correctly.

What should I do?
Bty, I'm using Exiftool on Linux (Debian 12).

StarGeek

Your expression is fine, works correctly here.  Your quotes are not. You have a stray, unbalanced single quote.  Just use single quotes on Mac/Linux

exiftool -d %s '-DateTimeOriginal<${fileName;m/(\d{10})/;$_=$1}' 1659149646663.jpg

Example Windows output
C:\>exiftool -d "%s" "-DateTimeOriginal<${fileName;m/(\d{10})/;$_=$1}" Y:\!temp\x\y\1659149646663.jpg
    1 image files updated

C:\>exiftool -G1 -a -s -d %s -DateTimeOriginal -DateTimeOriginal# Y:\!temp\x\y\1659149646663.jpg
[ExifIFD]       DateTimeOriginal                : 1659149646
[ExifIFD]       DateTimeOriginal                : 2022:07:29 19:54:06
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

candura

Quote from: StarGeek on May 05, 2024, 09:53:44 AMYour expression is fine, works correctly here.  Your quotes are not. You have a stray, unbalanced single quote.  Just use single quotes on Mac/Linux

exiftool -d %s '-DateTimeOriginal<${fileName;m/(\d{10})/;$_=$1}' 1659149646663.jpg

It works! So thanks for your helping!  :)