From 20c5216afc3dc8fcb422517d92af10b722c72de5 Mon Sep 17 00:00:00 2001 From: ergosteur Date: Sun, 26 Jul 2026 12:58:34 -0400 Subject: [PATCH] Set output file mtime to match embedded capture time Some tools (Synology Photos, for videos) key off filesystem mtime rather than parsing QuickTime metadata for the capture date, so an otherwise-correct output file would sort/date wrong there. Stamp the output's mtime from the same clip whose metadata got embedded (--metadata-from) after encoding. --- README.md | 3 +++ concat_live_clips.py | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/README.md b/README.md index d9db369..be6173d 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,9 @@ This script: with a plain stream copy) and concatenates everything into one file. 5. Carries over the original container metadata (GPS, device info, creation time, Live Photo identifiers) from one of the source clips. +6. Sets the output file's filesystem modification time to match that same + capture time — some tools (e.g. Synology Photos, for videos) sort/date + by file mtime instead of parsing embedded metadata. Audio stays uncompressed PCM throughout, so it never loses quality. Video quality defaults to a bitrate slightly above the source clips' own bitrate diff --git a/concat_live_clips.py b/concat_live_clips.py index 1cc481b..92374a4 100755 --- a/concat_live_clips.py +++ b/concat_live_clips.py @@ -28,6 +28,7 @@ Requirements: detects clip overlap): pip install --user numpy """ import argparse +import os import re import subprocess import sys @@ -365,6 +366,17 @@ def main(): print(f"Encoding seamless, deduplicated output -> {output}", file=sys.stderr) subprocess.run(cmd, check=True) + + creation_dt = fetch_creation_time(clips[args.metadata_from]) + if creation_dt is not None: + ts = creation_dt.timestamp() + os.utime(output, (ts, ts)) + print(f"Set file mtime to {creation_dt.isoformat()} (matches embedded metadata, " + f"so apps that key off filesystem time instead of parsing video metadata " + f"still sort/date it correctly)", file=sys.stderr) + else: + print("warning: couldn't determine source creation time; leaving file mtime as-is", file=sys.stderr) + print(f"Done: {output}", file=sys.stderr)