-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathtestVideoReader.py
More file actions
53 lines (41 loc) · 1.99 KB
/
Copy pathtestVideoReader.py
File metadata and controls
53 lines (41 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import os
# Check if environment is setup to run the tests
if os.environ.get('AVTRANSCODER_TEST_VIDEO_AVI_FILE') is None:
from nose.plugins.skip import SkipTest
raise SkipTest("Need to define environment variables AVTRANSCODER_TEST_VIDEO_AVI_FILE")
from nose.tools import *
from pyAvTranscoder import avtranscoder as av
def testVideoReader():
"""
Read a video stream with the VideoReader.
The InputFile is created inside the reader.
"""
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE']
reader = av.VideoReader(av.InputStreamDesc(inputFileName))
# read all frames and check their size
for i in range(0, reader.getSourceVideoProperties().getNbFrames()):
frame = reader.readNextFrame()
bytesPerPixel = reader.getOutputBitDepth() / 8
assert_equals( frame.getDataSize(), reader.getOutputWidth() * reader.getOutputHeight() * bytesPerPixel )
# check if there is no next frame
assert_equals( reader.readNextFrame(), None )
def testVideoReaderWithGenerator():
"""
Read a video stream with the VideoReader.
When there is no more data to decode, switch to a generator and process some frames.
"""
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE']
reader = av.VideoReader(av.InputStreamDesc(inputFileName))
# read all frames and check their size
for i in range(0, reader.getSourceVideoProperties().getNbFrames()):
frame = reader.readNextFrame()
bytesPerPixel = reader.getOutputBitDepth() / 8
assert_equals( frame.getDataSize(), reader.getOutputWidth() * reader.getOutputHeight() * bytesPerPixel )
# check if there is no next frame
assert_equals( reader.readNextFrame(), None )
# generate 10 frames of black
reader.continueWithGenerator()
for i in range(0, 9):
frame = reader.readNextFrame()
bytesPerPixel = reader.getOutputBitDepth() / 8
assert_equals( frame.getDataSize(), reader.getOutputWidth() * reader.getOutputHeight() * bytesPerPixel )