Fix photo/video timestamps using a date/time prefix embedded in filenames.
This is mainly useful when media has lost metadata but filenames still contain the capture time (e.g. for Immich imports).
The tool extracts a datetime from the start of each filename and then:
- JPEG / WebP (
.jpg,.jpeg,.webp): writes EXIFDateTimeOriginalin-place (no recompression). - HEIC / HEIF (
.heic,.heif): writesDateTimeOriginalviaexiftool, and aligns filesystemmtime/atime. - Timestamp-only formats (
.mov,.mp4,.avi,.mpg,.tiff,.png): aligns filesystemmtime/atime.
Live Photo pairing (MOV-only): when processing a still image with a parsable datetime, if a same-stem .mov exists in the same directory and the .mov filename does not contain a parsable datetime prefix, the tool sets that .mov file's mtime/atime to match the still.
The date prefix must appear at the beginning of the filename.
Supported prefixes:
- Full datetime:
YYYY-MM-DD<sep>HH<sep>MM<sep>SS<sep>is any single non-digit character (e.g._,-,., space)- Examples:
2025-11-29 18.52.49.mov2025-09-28_18-04-17_IMG_5641.heic
- Date only:
YYYY-MM-DD(time defaults to12:00:00) - Year-month:
YYYY-MM(day defaults to01, time defaults to12:00:00)
If month or day is 00, it is normalized to 01.
Times are interpreted as local time when converting to filesystem timestamps.
- Python 3.x
piexif(required for JPEG/WebP EXIF updates)exiftool(required for HEIC/HEIF metadata updates)
Install Python deps:
python -m pip install piexifInstall exiftool (macOS via Homebrew):
brew install exiftoolProcess current directory (non-recursive):
python exiffromfilename.pyProcess a directory:
python exiffromfilename.py -d /path/to/mediaRecursive:
python exiffromfilename.py -d /path/to/media -rForce updates even if existing metadata/timestamps already exist:
python exiffromfilename.py -d /path/to/media -r -fProcess specific file(s) (repeat --path):
python exiffromfilename.py --path /path/to/a.heic --path /path/to/b.jpg
python exiffromfilename.py --path /path/to/a.png --path /path/to/b.webp -fNotes:
- When
--pathis provided,--recursiveis not allowed and--directoryis ignored. - The tool edits files in place. Test on a small copy first and keep backups.
Print a timestamp for one or more files:
python showexif.py /path/to/file.jpg /path/to/file.heic /path/to/file.pngDefault behavior:
- Try EXIF
DateTimeOriginalviapiexif. - If missing/unreadable, try
exiftool(useful for HEIC/HEIF). - If still missing, fall back to filesystem
mtime.
Flags:
python showexif.py --exif-only /path/to/file.jpg
python showexif.py --mtime-only /path/to/file.png