@@ -52,20 +52,19 @@ def temp_video(num_frames, height, width, fps, lossless=False, video_codec=None,
52
52
yield f .name , data
53
53
54
54
55
+ @unittest .skipIf (av is None , "PyAV unavailable" )
55
56
class Tester (unittest .TestCase ):
56
57
# compression adds artifacts, thus we add a tolerance of
57
58
# 6 in 0-255 range
58
59
TOLERANCE = 6
59
60
60
- @unittest .skipIf (av is None , "PyAV unavailable" )
61
61
def test_write_read_video (self ):
62
62
with temp_video (10 , 300 , 300 , 5 , lossless = True ) as (f_name , data ):
63
63
lv , _ , info = io .read_video (f_name )
64
64
65
65
self .assertTrue (data .equal (lv ))
66
66
self .assertEqual (info ["video_fps" ], 5 )
67
67
68
- @unittest .skipIf (av is None , "PyAV unavailable" )
69
68
def test_read_timestamps (self ):
70
69
with temp_video (10 , 300 , 300 , 5 ) as (f_name , data ):
71
70
pts , _ = io .read_video_timestamps (f_name )
@@ -81,7 +80,6 @@ def test_read_timestamps(self):
81
80
82
81
self .assertEqual (pts , expected_pts )
83
82
84
- @unittest .skipIf (av is None , "PyAV unavailable" )
85
83
def test_read_partial_video (self ):
86
84
with temp_video (10 , 300 , 300 , 5 , lossless = True ) as (f_name , data ):
87
85
pts , _ = io .read_video_timestamps (f_name )
@@ -96,7 +94,6 @@ def test_read_partial_video(self):
96
94
self .assertEqual (len (lv ), 4 )
97
95
self .assertTrue (data [4 :8 ].equal (lv ))
98
96
99
- @unittest .skipIf (av is None , "PyAV unavailable" )
100
97
def test_read_partial_video_bframes (self ):
101
98
# do not use lossless encoding, to test the presence of B-frames
102
99
options = {'bframes' : '16' , 'keyint' : '10' , 'min-keyint' : '4' }
@@ -113,7 +110,6 @@ def test_read_partial_video_bframes(self):
113
110
self .assertEqual (len (lv ), 4 )
114
111
self .assertTrue ((data [4 :8 ].float () - lv .float ()).abs ().max () < self .TOLERANCE )
115
112
116
- @unittest .skipIf (av is None , "PyAV unavailable" )
117
113
def test_read_packed_b_frames_divx_file (self ):
118
114
with get_tmp_dir () as temp_dir :
119
115
name = "hmdb51_Turnk_r_Pippi_Michel_cartwheel_f_cm_np2_le_med_6.avi"
@@ -129,6 +125,23 @@ def test_read_packed_b_frames_divx_file(self):
129
125
warnings .warn (msg , RuntimeWarning )
130
126
raise unittest .SkipTest (msg )
131
127
128
+ def test_read_timestamps_from_packet (self ):
129
+ with temp_video (10 , 300 , 300 , 5 , video_codec = 'mpeg4' ) as (f_name , data ):
130
+ pts , _ = io .read_video_timestamps (f_name )
131
+
132
+ # note: not all formats/codecs provide accurate information for computing the
133
+ # timestamps. For the format that we use here, this information is available,
134
+ # so we use it as a baseline
135
+ container = av .open (f_name )
136
+ stream = container .streams [0 ]
137
+ # make sure we went through the optimized codepath
138
+ self .assertIn (b'Lavc' , stream .codec_context .extradata )
139
+ pts_step = int (round (float (1 / (stream .average_rate * stream .time_base ))))
140
+ num_frames = int (round (float (stream .average_rate * stream .time_base * stream .duration )))
141
+ expected_pts = [i * pts_step for i in range (num_frames )]
142
+
143
+ self .assertEqual (pts , expected_pts )
144
+
132
145
# TODO add tests for audio
133
146
134
147
0 commit comments