@@ -24,11 +24,12 @@ def testVideoReaderCreateNewInputFile():
24
24
# read all frames and check their size
25
25
for i in xrange (0 , reader .getSourceVideoProperties ().getNbFrames ()):
26
26
frame = av .VideoFrame (reader .readNextFrame ())
27
- assert_equals ( frame .getSize (), reader .getOutputWidth () * reader .getOutputHeight () * reader .getOutputNbComponents () )
27
+ bytesPerPixel = reader .getOutputBitDepth () / 8
28
+ assert_equals ( frame .getSize (), reader .getOutputWidth () * reader .getOutputHeight () * bytesPerPixel )
28
29
29
- # check if the next frame is empty
30
- frame = av . VideoFrame ( reader .readNextFrame () )
31
- assert_equals ( frame . getSize (), 0 )
30
+ # check if there is no next frame
31
+ frame = reader .readNextFrame ()
32
+ assert_equals ( reader . readNextFrame (), None )
32
33
33
34
34
35
def testVideoReaderReferenceInputFile ():
@@ -43,11 +44,11 @@ def testVideoReaderReferenceInputFile():
43
44
# read all frames and check their size
44
45
for i in xrange (0 , reader .getSourceVideoProperties ().getNbFrames ()):
45
46
frame = av .VideoFrame (reader .readNextFrame ())
46
- assert_equals ( frame .getSize (), reader .getOutputWidth () * reader .getOutputHeight () * reader .getOutputNbComponents () )
47
+ bytesPerPixel = reader .getOutputBitDepth () / 8
48
+ assert_equals ( frame .getSize (), reader .getOutputWidth () * reader .getOutputHeight () * bytesPerPixel )
47
49
48
- # check if the next frame is empty
49
- frame = av .VideoFrame (reader .readNextFrame ())
50
- assert_equals ( frame .getSize (), 0 )
50
+ # check if there is no next frame
51
+ assert_equals ( reader .readNextFrame (), None )
51
52
52
53
53
54
def testAudioReaderChannelsExtraction ():
@@ -74,3 +75,59 @@ def testAudioReaderChannelsExtraction():
74
75
sizeOfFrameWithOneChannels = frame .getSize ()
75
76
76
77
assert_equals ( sizeOfFrameWithAllChannels / nbChannels , sizeOfFrameWithOneChannels )
78
+
79
+
80
+ def testVideoReaderWithGenerator ():
81
+ """
82
+ Read a video stream with the VideoReader.
83
+ When there is no more data to decode, switch to a generator and process some frames.
84
+ """
85
+ inputFileName = os .environ ['AVTRANSCODER_TEST_VIDEO_AVI_FILE' ]
86
+ reader = av .VideoReader (inputFileName )
87
+
88
+ # read all frames and check their size
89
+ for i in xrange (0 , reader .getSourceVideoProperties ().getNbFrames ()):
90
+ frame = av .VideoFrame (reader .readNextFrame ())
91
+ bytesPerPixel = reader .getOutputBitDepth () / 8
92
+ assert_equals ( frame .getSize (), reader .getOutputWidth () * reader .getOutputHeight () * bytesPerPixel )
93
+
94
+ # check if there is no next frame
95
+ assert_equals ( reader .readNextFrame (), None )
96
+
97
+ # generate 10 frames of black
98
+ reader .continueWithGenerator ()
99
+ for i in xrange (0 , 9 ):
100
+ frame = av .VideoFrame (reader .readNextFrame ())
101
+ bytesPerPixel = reader .getOutputBitDepth () / 8
102
+ assert_equals ( frame .getSize (), reader .getOutputWidth () * reader .getOutputHeight () * bytesPerPixel )
103
+
104
+
105
+ def testAudioReaderWithGenerator ():
106
+ """
107
+ Read an audio stream with the AudioReader.
108
+ When there is no more data to decode, switch to a generator and process some frames.
109
+ """
110
+ inputFileName = os .environ ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE' ]
111
+ inputFile = av .InputFile (inputFileName )
112
+ reader = av .AudioReader (inputFile )
113
+
114
+ # read all frames and check their size
115
+ while True :
116
+ frame = reader .readNextFrame ()
117
+ if not frame :
118
+ break
119
+ frame = av .AudioFrame (frame )
120
+ nbSamplesPerChannel = frame .getNbSamplesPerChannel ()
121
+ bytesPerSample = 2
122
+ assert_equals ( frame .getSize (), reader .getOutputNbChannels () * nbSamplesPerChannel * bytesPerSample )
123
+
124
+ # check if there is no next frame
125
+ assert_equals ( reader .readNextFrame (), None )
126
+
127
+ # generate 10 frames of silence
128
+ reader .continueWithGenerator ()
129
+ for i in xrange (0 , 9 ):
130
+ frame = av .AudioFrame (reader .readNextFrame ())
131
+ nbSamplesPerChannel = frame .getNbSamplesPerChannel ()
132
+ bytesPerSample = 2
133
+ assert_equals ( frame .getSize (), reader .getOutputNbChannels () * nbSamplesPerChannel * bytesPerSample )
0 commit comments