Some more pts timing analysis.
[dcpomatic.git] / hacks / check_packets.py
1 #!/usr/bin/python
2
3 import subprocess
4 import shlex
5 import sys
6
7 last_video = None
8 last_video_pts = None
9
10 def handle(frame):
11     global last_video
12     global last_video_pts
13     if frame['media_type'] == 'video':
14         if last_video_pts is not None and frame['pkt_pts_time'] <= last_video_pts:
15             print 'Out of order video frame %f (%d) is same as or behind %f (%d)' % (frame['pkt_pts_time'], frame['pkt_pts'], last_video_pts, last_video)
16         elif last_video_pts is not None:
17             print 'OK frame %f %f %f' % (frame['pkt_pts_time'], frame['pkt_pts_time'] - last_video_pts, 1 / (frame['pkt_pts_time'] - last_video_pts))
18         else:
19             print 'OK frame %f' % (frame['pkt_pts_time'])
20         last_video = frame['pkt_pts']
21         last_video_pts = frame['pkt_pts_time']
22
23 p = subprocess.Popen(shlex.split('ffprobe -show_frames %s' % sys.argv[1]), stdin=None, stdout=subprocess.PIPE)
24 frame = dict()
25 while True:
26     l = p.stdout.readline()
27     if l == '':
28         break
29
30     l = l.strip()
31
32     if l == '[/FRAME]':
33         handle(frame)
34         frame = dict()
35     elif l != '[FRAME]' and l != '[SIDE_DATA]' and l != '[/SIDE_DATA]':
36         s = l.split('=')
37         if s[0] == 'pkt_pts_time':
38             frame[s[0]] = float(s[1])
39         elif s[0] == 'pkt_pts':
40             frame[s[0]] = float(s[1]) 
41         elif len(s) > 1:
42             frame[s[0]] = s[1]