Last active
May 23, 2023 08:20
This file contains hidden or 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
#!/usr/bin/env python | |
import sys | |
import json | |
import datetime | |
# Feed me with output of: | |
# ffprobe -f lavfi -i movie=INPUT.mov,ocr -show_entries frame=pkt_dts_time:frame_tags=lavfi.ocr.text -of json | |
input= sys.argv[1] | |
id = 0 | |
old_time = '00:00:00,000' | |
with open(input) as f: | |
data = json.loads(f.read()) | |
for el in data['frames']: | |
ts = (datetime.datetime.min + datetime.timedelta(seconds=float(el['pkt_dts_time']))).time() | |
timestamp = '{:02}:{:02}:{:02},{:03}'.format(ts.hour, ts.minute, ts.second, ts.microsecond / 1000) | |
if not old_time: old_time = timestamp | |
text = unicode.strip(el['tags']['lavfi.ocr.text']) | |
if text: | |
id+=1 | |
print('{0}\n{1} --> {2}\n{3}\n'.format(id, old_time, timestamp, text)) | |
old_time = timestamp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment