17 video_frame_rates = []
21 def check_pts_dts(frame):
22 if 'pkt_dts_time' in frame:
23 diff = frame['pkt_pts_time'] - frame['pkt_dts_time']
25 print("\tPTS != DTS: %f" % diff)
31 global video_frame_count
32 global video_frame_rates
33 if frame['media_type'] == 'video' and 'video' in types:
34 if last_video_pts is not None and frame['pkt_pts_time'] <= last_video_pts:
35 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))
36 elif last_video_pts is not None:
37 pkt_dts_time = frame['pkt_dts_time'] if 'pkt_dts_time' in frame else 0.0
38 rate = 1 / (frame['pkt_pts_time'] - last_video_pts)
39 print(f'OK V frame %f %f %f %f %d indices %d/%d' % (frame['pkt_pts_time'], pkt_dts_time, frame['pkt_pts_time'] - last_video_pts, rate, frame['pkt_size'], video_frame_count, frame['pkt_pts_time'] * VIDEO_RATE))
41 video_frame_rates.append(rate)
43 print('OK V frame %f counted %d' % (frame['pkt_pts_time'], video_frame_count))
44 last_video = frame['pkt_pts']
45 last_video_pts = frame['pkt_pts_time']
46 video_frame_count += 1
47 elif frame['media_type'] == 'audio' and 'audio' in types:
48 stream_index = frame['stream_index']
49 if stream_index in last_audio_pts and (stream_index == AUDIO_STREAM or AUDIO_STREAM is None):
50 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']))
52 if stream_index in last_channels and frame['channels'] != last_channels[stream_index]:
53 print("\t*** unusual channel count")
54 last_audio_pts[stream_index] = frame['pkt_pts_time']
55 last_channels[stream_index] = frame['channels']
58 p = subprocess.Popen(shlex.split('ffprobe -show_frames "%s"' % sys.argv[1]), stdin=None, stdout=subprocess.PIPE)
61 l = p.stdout.readline()
65 l = l.strip().decode('UTF-8')
70 elif l != '[FRAME]' and l != '[SIDE_DATA]' and l != '[/SIDE_DATA]':
72 if s[0] in ['pkt_pts_time', 'pkt_dts_time', 'pkt_pts', 'pkt_dts']:
74 frame[s[0]] = float(s[1])
75 elif s[0] in ['channels', 'pkt_size', 'nb_samples']:
76 frame[s[0]] = int(s[1])
81 print(f'Average frame rate: {sum(video_frame_rates) / float(len(video_frame_rates))}')