Automatically Correct Insta360 Studio Snapshot Dates

A simple script to fix the creation date of exported snapshots from Insta360 One X Studio

Insta360 Studio 2019 for the Insta360 One X

When you import a 360º photo into the desktop Insta360 Studio software, one of the export options is to take a "normal" photo (called "FreeCapture" in Insta360's software, or "Overcapture" in the GoPro Fusion software) from the original 360º media, saving this as a snapshot.

Unfortunately these snapshots are just that, exported snapshots of the preview area with no camera metadata.
Lack of metadata is especially annoying when sorting by date (as all phones do), as re-framed photos will not appear next to the 360º photos themselves, but next will appear as being from the day you processed it.

Fortunately, the name includes all the date and time information needed.

Image file save name suggestion IMG_20191230_120453_00_105_2020-02-14_17-17-37_screenshot.jpg

IMG_20191230_120453_00_105_2020-02-14_17-17-37_screenshot.jpg

Pattern
IMG_|yr|mon|day|_|hr|min|sec|_00_#_[date screenshot saved]_screenshot.jpg

This means it is easy to create a simple script to fix the files after the fact, allowing you to use Insta360 Studio to snapshot lots of different angles of photos and video and then run a script to clean things up afterwards (instead of manually fixing each image file as you go).

Date Correction Script

The script needs to follow these simple instructions:

  1. Find all jpg's with screenshot in the name.
  2. Extract the date from the file name.
  3. Modify the exif date taken data to match.
  4. Save the new metadata.

(Though there are other steps, like merging in some metadata from the original 360 file, which could be taken to improve it.)

The script

The only external library used is one to extract the metadata and modify it, Piexif.

import os
import re
import datetime
import piexif

filepath = os.path.abspath(".")

# Find files with `screenshot` in the name.
files = [f for f in os.listdir(filepath) if "screenshot" in f and f.endswith(".jpg")]
print(files)

for filename in files:
    print(filename)
    # Extract datetime
    date_rex = r"(20\d\d)(\d\d)(\d\d)_(\d\d)(\d\d)(\d\d)"
    date_ranges = re.search(date_rex, filename)
    # Date
    year = date_ranges.group(1)
    month = date_ranges.group(2)
    day = date_ranges.group(3)
    # Time
    hour = date_ranges.group(4)
    minute = date_ranges.group(5)
    second = date_ranges.group(6)
    # date text
    dt_text = f"{year}:{month}:{day} {hour}:{month}:{second}"
    print(dt_text)
    # Image file path
    image_filepath = os.path.join(filepath, filename)
    print(image_filepath)
    exif_dict = piexif.load(image_filepath)
    print(exif_dict) # Before
    exif_dict["0th"][piexif.ImageIFD.DateTime] = dt_text
    exif_dict["Exif"][piexif.ExifIFD.DateTimeOriginal] = dt_text
    print(exif_dict) # After
    # Save new metadata
    exif_bytes = piexif.dump(exif_dict)
    piexif.insert(exif_bytes, image_filepath)

This python script should be safe to re-run multiple times on the same directory (although it could cut down on fileIO by comparing the existing date metadata to see if it is correct before overriding it).

Example output from piexif.load(img) before and after:

Before:
{'0th': {}, 'Exif': {}, 'GPS': {}, 'Interop': {}, '1st': {}, 'thumbnail': None}

After:
{'0th': {306: '2019:12:30 12:04:53'}, 'Exif': {36867: '2019:12:30 12:04:53'}, 'GPS': {}, 'Interop': {}, '1st': {}, 'thumbnail': None}

The script is also saved as a gist on Github.