Skip to content

Instantly share code, notes, and snippets.

@akx
Last active May 10, 2020 11:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akx/f10d4d7ac15372105b05d375a381ae88 to your computer and use it in GitHub Desktop.
Save akx/f10d4d7ac15372105b05d375a381ae88 to your computer and use it in GitHub Desktop.
Rename MP4 files based on embedded creation time tag
import os
import datetime
import glob
import subprocess
import json
def get_creation_time(f):
rinfo = subprocess.check_output('ffprobe -print_format json -hide_banner -show_format -i "%s"' % f, shell=True, stderr=subprocess.DEVNULL)
info = json.loads(rinfo.decode())
ctime = info['format']['tags']['creation_time']
return datetime.datetime.fromisoformat(ctime[:19])
for f in glob.glob('*.mp4'):
t = get_creation_time(f)
new_name = f'{t.isoformat(" ").replace(":", ".")}.mp4'
print(f, new_name, t)
if f != new_name:
os.rename(f, new_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment