Skip to content

Commit 90bcf03

Browse files
author
Clement Champetier
committed
pyTest: added tests to check Video/Audio readers with a generator
1 parent 571ec23 commit 90bcf03

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

test/pyTest/testReader.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,59 @@ def testAudioReaderChannelsExtraction():
7575
sizeOfFrameWithOneChannels = frame.getSize()
7676

7777
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

Comments
 (0)