Skip to content

Instantly share code, notes, and snippets.

@lsde
Last active May 23, 2023 08:20
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lsde/4e85dcde3f37e7ab8a986059be1921b2 to your computer and use it in GitHub Desktop.
Save lsde/4e85dcde3f37e7ab8a986059be1921b2 to your computer and use it in GitHub Desktop.
#!/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