Last active
May 10, 2020 11:57
-
-
Save akx/f10d4d7ac15372105b05d375a381ae88 to your computer and use it in GitHub Desktop.
Rename MP4 files based on embedded creation time tag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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