-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathtestProperties.py
More file actions
181 lines (142 loc) · 6.33 KB
/
Copy pathtestProperties.py
File metadata and controls
181 lines (142 loc) · 6.33 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import os
# Check if environment is setup to run the tests
if os.environ.get('AVTRANSCODER_TEST_AUDIO_WAVE_FILE') is None or \
os.environ.get('AVTRANSCODER_TEST_VIDEO_MP4_FILE') is None or \
os.environ.get('AVTRANSCODER_TEST_VIDEO_MOV_FILE') is None or \
os.environ.get('AVTRANSCODER_TEST_VIDEO_RAW_FILE') is None:
from nose.plugins.skip import SkipTest
raise SkipTest("Need to define environment variables "
"AVTRANSCODER_TEST_AUDIO_WAVE_FILE and "
"AVTRANSCODER_TEST_VIDEO_MP4_FILE and "
"AVTRANSCODER_TEST_VIDEO_MOV_FILE and "
"AVTRANSCODER_TEST_VIDEO_RAW_FILE")
from nose.tools import *
from pyAvTranscoder import avtranscoder as av
def testAddPossibleMetadata():
"""
Add metadata 'date' to the outputFile.
"""
inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE']
outputFileName = "testAddMetadataDate.wav"
ouputFile = av.OutputFile( outputFileName )
transcoder = av.Transcoder( ouputFile )
# rewrap a stream
transcoder.addStream( av.InputStreamDesc(inputFileName) )
# add a set of metadata
metadata_to_check = av.PropertyVector()
metadata_to_check.append(("date", "value"))
ouputFile.addMetadata(metadata_to_check)
progress = av.NoDisplayProgress()
transcoder.process( progress )
inputFile = av.InputFile( outputFileName )
inputFile.analyse( progress, av.eAnalyseLevelHeader )
properties = inputFile.getProperties()
for metadata in metadata_to_check:
assert_in( metadata, properties.getMetadatas() )
def testAddImpossibleMetadata():
"""
Can't add an impossible metadata to the outputFile.
"""
inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE']
outputFileName = "testAddMetadataPlop.wav"
ouputFile = av.OutputFile( outputFileName )
transcoder = av.Transcoder( ouputFile )
# rewrap a stream
transcoder.addStream( av.InputStreamDesc(inputFileName) )
# add one metadata
metadata_to_check = ("undefinedMetadataKey", "undefinedMetadataValue")
ouputFile.addMetadata( metadata_to_check[0], metadata_to_check[1] )
progress = av.NoDisplayProgress()
transcoder.process( progress )
inputFile = av.InputFile( outputFileName )
inputFile.analyse( progress, av.eAnalyseLevelHeader )
properties = inputFile.getProperties()
assert_not_in( metadata_to_check, properties.getMetadatas() )
def testCheckVideoProperties():
"""
Check properties of a video stream.
"""
# get src file
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_MP4_FILE']
inputFile = av.InputFile( inputFileName )
properties = inputFile.getProperties()
videoStream = properties.getVideoProperties()[0]
expectedTotalBitRate = 3249739
expectedVideoBitRate = 3247981
expectedCodecName = 'h264'
expectedWidth = 1920
expectedHeight = 1080
expectedNbFrames = 241
expectedDuration = 10.04
expectedFps = 24
assert_equals( properties.getBitRate(), expectedTotalBitRate )
assert_equals( videoStream.getBitRate(), expectedVideoBitRate )
assert_equals( videoStream.getCodecName(), expectedCodecName )
assert_equals( videoStream.getWidth(), expectedWidth )
assert_equals( videoStream.getHeight(), expectedHeight )
assert_equals( videoStream.getNbFrames(), expectedNbFrames )
assert_equals( round(videoStream.getDuration(), 2), expectedDuration )
assert_equals( videoStream.getFps(), expectedFps )
def testCheckRawVideoProperties():
"""
Check properties of a raw video stream.
A raw stream does not contain header (so the duration, number of frames... needs to be computed).
"""
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_RAW_FILE']
inputFile = av.InputFile(inputFileName)
properties = inputFile.getProperties()
# Check format
assert_true(properties.isRawFormat())
assert_equals(properties.getNbStreams(), 1)
assert_equals(properties.getNbVideoStreams(), 1)
assert_equals(properties.getDuration(), 0) # file duration is unknown
assert_equals(properties.getBitRate(), 0) # file bitrate is unknown
assert_equals(properties.getFileSize(), 256293)
# Check video stream when analyse the header
videoStream = properties.getVideoProperties()[0]
assert_equals(videoStream.getFps(), 25)
assert_equals(videoStream.getNbFrames(), 0) # stream nbFrames is unknown
assert_equals(videoStream.getDuration(), 0) # stream duration is unknown
assert_equals(videoStream.getBitRate(), 0) # stream bitrate is unknown
# Check video stream when analyse the first GOP
inputFile.analyse(av.NoDisplayProgress(), av.eAnalyseLevelFirstGop)
videoStream = properties.getVideoProperties()[0]
assert_equals(videoStream.getNbFrames(), 200)
assert_equals(videoStream.getDuration(), 8)
assert_equals(videoStream.getBitRate(), 177200)
def testCheckAudioProperties():
"""
Check properties of an audio stream.
"""
# get src file
inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE']
inputFile = av.InputFile( inputFileName )
properties = inputFile.getProperties()
audioStream = properties.getAudioProperties()[0]
expectedTotalBitRate = 4608040
expectedAudioBitRate = 4608000
expectedCodecName = 'pcm_s16le'
expectedDuration = 20
expectedChannels = 6
expectedChannelLayout = '5.1'
expectedSampleRate = 48000
expectedSamples = expectedSampleRate * expectedDuration;
assert_equals( properties.getBitRate(), expectedTotalBitRate )
assert_equals( audioStream.getBitRate(), expectedAudioBitRate )
assert_equals( audioStream.getCodecName(), expectedCodecName )
assert_equals( audioStream.getNbSamples(), expectedSamples )
assert_equals( round(audioStream.getDuration(), 2), expectedDuration )
assert_equals( audioStream.getNbChannels(), expectedChannels )
assert_equals( audioStream.getChannelLayout(), expectedChannelLayout )
assert_equals( audioStream.getSampleRate(), expectedSampleRate )
def testCheckFilePropertiesAsJson():
"""
Check file properties as json.
"""
# get src file
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_MOV_FILE']
inputFile = av.InputFile( inputFileName )
import json
# json.loads method throws a ValueError if it is not a valid JSON.
jsonProps = json.loads(inputFile.getProperties().allPropertiesAsJson())
print(jsonProps)