Change video content scaling so that it either:
[dcpomatic.git] / hacks / examine.py
1 #!/usr/bin/python
2
3 import subprocess
4 import shlex
5 import sys
6
7 AUDIO_STREAM = "1"
8 types = ['audio']
9
10 last_video = None
11 last_video_pts = None
12
13 last_audio_pts = {}
14 last_channels = {}
15
16 def check_pts_dts(frame):
17     diff = frame['pkt_pts_time'] - frame['pkt_dts_time']
18     if abs(diff) > 1e-8:
19         print("\tPTS != DTS: %f" % diff)
20
21 def handle(frame):
22     global last_video
23     global last_video_pts
24     global last_audio_pts
25     if frame['media_type'] == 'video' and 'video' in types:
26         if last_video_pts is not None and frame['pkt_pts_time'] <= last_video_pts:
27             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)
28         elif last_video_pts is not None:
29             print 'OK V    frame %f %f %f %f %d' % (frame['pkt_pts_time'], frame['pkt_dts_time'], frame['pkt_pts_time'] - last_video_pts, 1 / (frame['pkt_pts_time'] - last_video_pts), frame['pkt_size'])
30             check_pts_dts(frame)
31         else:
32             print 'OK V    frame %f' % (frame['pkt_pts_time'])
33         last_video = frame['pkt_pts']
34         last_video_pts = frame['pkt_pts_time']
35     elif frame['media_type'] == 'audio' and 'audio' in types:
36         stream_index = frame['stream_index']
37         if stream_index in last_audio_pts and (stream_index == AUDIO_STREAM or AUDIO_STREAM is None):
38             print 'OK A[%s] frame %4.8f %4.8f %4.8f %4.8f %d' % (stream_index, frame['pkt_pts_time'], frame['pkt_dts_time'], frame['pkt_pts_time'] - last_audio_pts[stream_index], 1 / (frame['pkt_pts_time'] - last_audio_pts[stream_index]), frame['pkt_size'])
39             check_pts_dts(frame)
40         if stream_index in last_channels and frame['channels'] != last_channels[stream_index]:
41             print "\t*** unusual channel count"
42         last_audio_pts[stream_index] = frame['pkt_pts_time']
43         last_channels[stream_index] = frame['channels']
44
45
46 p = subprocess.Popen(shlex.split('ffprobe -show_frames "%s"' % sys.argv[1]), stdin=None, stdout=subprocess.PIPE)
47 frame = dict()
48 while True:
49     l = p.stdout.readline()
50     if l == '':
51         break
52
53     l = l.strip()
54
55     if l == '[/FRAME]':
56         handle(frame)
57         frame = dict()
58     elif l != '[FRAME]' and l != '[SIDE_DATA]' and l != '[/SIDE_DATA]':
59         s = l.split('=')
60         if s[0] in ['pkt_pts_time', 'pkt_dts_time', 'pkt_pts', 'pkt_dts']:
61             frame[s[0]] = float(s[1])
62         elif s[0] in ['channels', 'pkt_size', 'nb_samples']:
63             frame[s[0]] = int(s[1])
64         elif len(s) > 1:
65             frame[s[0]] = s[1]