Skip to content

Commit f2cc0ca

Browse files
author
Clement Champetier
committed
pyTest: added pyTest to check readers
1 parent 0c3bf14 commit f2cc0ca

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

test/pyTest/testReader.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import os
2+
3+
# Check if environment is setup to run the tests
4+
if os.environ.get('AVTRANSCODER_TEST_VIDEO_AVI_FILE') is None or \
5+
os.environ.get('AVTRANSCODER_TEST_AUDIO_WAVE_FILE') is None:
6+
from nose.plugins.skip import SkipTest
7+
raise SkipTest("Need to define environment variables "
8+
"AVTRANSCODER_TEST_VIDEO_AVI_FILE and "
9+
"AVTRANSCODER_TEST_AUDIO_WAVE_FILE")
10+
11+
from nose.tools import *
12+
13+
from pyAvTranscoder import avtranscoder as av
14+
15+
16+
def testVideoReaderCreateNewInputFile():
17+
"""
18+
Read a video stream with the VideoReader.
19+
The InputFile is created inside the reader.
20+
"""
21+
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE']
22+
reader = av.VideoReader(inputFileName)
23+
24+
# read all frames and check their size
25+
for i in xrange(0, reader.getSourceVideoProperties().getNbFrames()):
26+
frame = reader.readNextFrame()
27+
assert_equals( frame.getSize(), reader.getOutputWidth() * reader.getOutputHeight() * reader.getOutputNbComponents() )
28+
29+
# check if the next frame is empty
30+
frame = reader.readNextFrame()
31+
assert_equals( frame.getSize(), 0 )
32+
33+
34+
def testVideoReaderReferenceInputFile():
35+
"""
36+
Read a video stream with the VideoReader.
37+
The InputFile is a reference for the reader.
38+
"""
39+
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE']
40+
inputFile = av.InputFile(inputFileName)
41+
reader = av.VideoReader(inputFile)
42+
43+
# read all frames and check their size
44+
for i in xrange(0, reader.getSourceVideoProperties().getNbFrames()):
45+
frame = reader.readNextFrame()
46+
assert_equals( frame.getSize(), reader.getOutputWidth() * reader.getOutputHeight() * reader.getOutputNbComponents() )
47+
48+
# check if the next frame is empty
49+
frame = reader.readNextFrame()
50+
assert_equals( frame.getSize(), 0 )
51+
52+
53+
def testAudioReaderChannelsExtraction():
54+
"""
55+
Read the same audio stream with several AudioReaders.
56+
Compare decoded frames from reader of all channels, and of one channel.
57+
"""
58+
inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE']
59+
inputFile = av.InputFile(inputFileName)
60+
streamIndex = inputFile.getProperties().getAudioProperties()[0].getStreamIndex()
61+
channelIndex = 0
62+
63+
# create reader to read all channels of the audio stream
64+
readerOfAllChannels = av.AudioReader(inputFile, streamIndex)
65+
nbChannels = readerOfAllChannels.getOutputNbChannels()
66+
# read first frame
67+
frame = readerOfAllChannels.readNextFrame()
68+
sizeOfFrameWithAllChannels = frame.getSize()
69+
70+
# create reader to read one channel of the audio stream
71+
readerOfOneChannel = av.AudioReader(inputFile, streamIndex, channelIndex)
72+
# read first frame
73+
frame = readerOfOneChannel.readNextFrame()
74+
sizeOfFrameWithOneChannels = frame.getSize()
75+
76+
assert_equals( sizeOfFrameWithAllChannels / nbChannels, sizeOfFrameWithOneChannels )

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy