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.
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user