forked from avTranscoder/avTranscoder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestTranscoderTranscodeAudioWave.py
More file actions
219 lines (168 loc) · 8.66 KB
/
Copy pathtestTranscoderTranscodeAudioWave.py
File metadata and controls
219 lines (168 loc) · 8.66 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
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_AUDIO_WAVE_MONO_FILE') is None:
from nose.plugins.skip import SkipTest
raise SkipTest("Need to define environment variables "
"AVTRANSCODER_TEST_AUDIO_WAVE_FILE and"
"AVTRANSCODER_TEST_AUDIO_WAVE_MONO_FILE")
from nose.tools import *
from pyAvTranscoder import avtranscoder as av
def testTranscodeExtractOneChannelFromMono():
"""
Extract one audio channel from a stream of one channel.
"""
inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_MONO_FILE']
outputFileName = "testTranscodeExtractOneChannelFromMono.wav"
ouputFile = av.OutputFile(outputFileName)
transcoder = av.Transcoder(ouputFile)
inputFile = av.InputFile(inputFileName)
src_audioStream = inputFile.getProperties().getAudioProperties()[0]
audioStreamIndex = src_audioStream.getStreamIndex()
transcoder.addStream(av.InputStreamDesc(inputFileName, audioStreamIndex, 0))
processStat = transcoder.process()
# check process stat returned
audioStat = processStat.getAudioStat(0)
assert_equals(src_audioStream.getDuration(), audioStat.getDuration())
# get dst file of transcode
dst_inputFile = av.InputFile(outputFileName)
dst_properties = dst_inputFile.getProperties()
dst_audioStream = dst_properties.getAudioProperties()[0]
assert_equals(dst_audioStream.getCodecName(), src_audioStream.getCodecName())
assert_equals(dst_audioStream.getSampleFormatName(), src_audioStream.getSampleFormatName())
assert_equals(dst_audioStream.getSampleFormatLongName(), src_audioStream.getSampleFormatLongName())
assert_equals(dst_audioStream.getSampleRate(), src_audioStream.getSampleRate())
assert_equals(dst_audioStream.getNbChannels(), 1)
def testTranscodeWave24b48k5_1():
"""
Transcode one audio stream (profile wave24b48k5_1).
"""
inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE']
outputFileName = "testTranscodeWave24b48k5_1.wav"
ouputFile = av.OutputFile( outputFileName )
transcoder = av.Transcoder( ouputFile )
inputFile = av.InputFile( inputFileName )
src_audioStream = inputFile.getProperties().getAudioProperties()[0]
audioStreamIndex = src_audioStream.getStreamIndex()
transcoder.addStream( av.InputStreamDesc(inputFileName, audioStreamIndex), "wave24b48k5_1" )
progress = av.ConsoleProgress()
processStat = transcoder.process( progress )
# check process stat returned
audioStat = processStat.getAudioStat(0)
assert_equals(src_audioStream.getDuration(), audioStat.getDuration())
# get dst file of transcode
dst_inputFile = av.InputFile( outputFileName )
dst_properties = dst_inputFile.getProperties()
dst_audioStream = dst_properties.getAudioProperties()[0]
assert_equals( "pcm_s24le", dst_audioStream.getCodecName() )
assert_equals( "s32", dst_audioStream.getSampleFormatName() )
assert_equals( "signed 32 bits", dst_audioStream.getSampleFormatLongName() )
assert_equals( 48000, dst_audioStream.getSampleRate() )
assert_equals( 6, dst_audioStream.getNbChannels() )
def testTranscodeWave24b48kstereo():
"""
Transcode one audio stream (profile wave24b48kstereo).
"""
inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE']
outputFileName = "testTranscodeWave24b48kstereo.wav"
ouputFile = av.OutputFile( outputFileName )
transcoder = av.Transcoder( ouputFile )
inputFile = av.InputFile( inputFileName )
src_audioStream = inputFile.getProperties().getAudioProperties()[0]
audioStreamIndex = src_audioStream.getStreamIndex()
transcoder.addStream( av.InputStreamDesc(inputFileName, audioStreamIndex), "wave24b48kstereo" )
progress = av.ConsoleProgress()
processStat = transcoder.process( progress )
# check process stat returned
audioStat = processStat.getAudioStat(0)
assert_equals(src_audioStream.getDuration(), audioStat.getDuration())
# get dst file of transcode
dst_inputFile = av.InputFile( outputFileName )
dst_properties = dst_inputFile.getProperties()
dst_audioStream = dst_properties.getAudioProperties()[0]
assert_equals( "pcm_s24le", dst_audioStream.getCodecName() )
assert_equals( "s32", dst_audioStream.getSampleFormatName() )
assert_equals( "signed 32 bits", dst_audioStream.getSampleFormatLongName() )
assert_equals( 48000, dst_audioStream.getSampleRate() )
assert_equals( 2, dst_audioStream.getNbChannels() )
def testTranscodeWave24b48kmono():
"""
Transcode one audio stream (profile wave24b48kmono).
"""
inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE']
outputFileName = "testTranscodeWave24b48kmono.wav"
ouputFile = av.OutputFile( outputFileName )
transcoder = av.Transcoder( ouputFile )
inputFile = av.InputFile( inputFileName )
src_audioStream = inputFile.getProperties().getAudioProperties()[0]
audioStreamIndex = src_audioStream.getStreamIndex()
transcoder.addStream( av.InputStreamDesc(inputFileName, audioStreamIndex), "wave24b48kmono" )
progress = av.ConsoleProgress()
processStat = transcoder.process( progress )
# check process stat returned
audioStat = processStat.getAudioStat(0)
assert_equals(src_audioStream.getDuration(), audioStat.getDuration())
# get dst file of transcode
dst_inputFile = av.InputFile( outputFileName )
dst_properties = dst_inputFile.getProperties()
dst_audioStream = dst_properties.getAudioProperties()[0]
assert_equals( "pcm_s24le", dst_audioStream.getCodecName() )
assert_equals( "s32", dst_audioStream.getSampleFormatName() )
assert_equals( "signed 32 bits", dst_audioStream.getSampleFormatLongName() )
assert_equals( 48000, dst_audioStream.getSampleRate() )
assert_equals( 1, dst_audioStream.getNbChannels() )
def testTranscodeWave16b48kmono():
"""
Transcode one audio stream (profile wave16b48kmono).
"""
inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE']
outputFileName = "testTranscodeWave16b48kmono.wav"
ouputFile = av.OutputFile( outputFileName )
transcoder = av.Transcoder( ouputFile )
inputFile = av.InputFile( inputFileName )
src_audioStream = inputFile.getProperties().getAudioProperties()[0]
audioStreamIndex = src_audioStream.getStreamIndex()
transcoder.addStream( av.InputStreamDesc(inputFileName, audioStreamIndex), "wave16b48kmono" )
progress = av.ConsoleProgress()
processStat = transcoder.process( progress )
# check process stat returned
audioStat = processStat.getAudioStat(0)
assert_equals(src_audioStream.getDuration(), audioStat.getDuration())
# get dst file of transcode
dst_inputFile = av.InputFile( outputFileName )
dst_properties = dst_inputFile.getProperties()
dst_audioStream = dst_properties.getAudioProperties()[0]
assert_equals( "pcm_s16le", dst_audioStream.getCodecName() )
assert_equals( "s16", dst_audioStream.getSampleFormatName() )
assert_equals( "signed 16 bits", dst_audioStream.getSampleFormatLongName() )
assert_equals( 48000, dst_audioStream.getSampleRate() )
assert_equals( 1, dst_audioStream.getNbChannels() )
def testTranscodeWave16b48kmonoWithSilence():
"""
Transcode one audio stream (profile wave16b48kmono).
Complete with silence.
"""
inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE']
outputFileName = "testTranscodeWave16b48kmonoWithSilence.wav"
outputDuration = 50
ouputFile = av.OutputFile( outputFileName )
transcoder = av.Transcoder( ouputFile )
transcoder.setProcessMethod( av.eProcessMethodBasedOnDuration, 0, outputDuration )
inputFile = av.InputFile( inputFileName )
src_audioStream = inputFile.getProperties().getAudioProperties()[0]
audioStreamIndex = src_audioStream.getStreamIndex()
transcoder.addStream( av.InputStreamDesc(inputFileName, audioStreamIndex), "wave16b48kmono" )
progress = av.ConsoleProgress()
processStat = transcoder.process( progress )
# check process stat returned
audioStat = processStat.getAudioStat(0)
assert_almost_equals( audioStat.getDuration(), outputDuration, delta=0.01 )
# get dst file of transcode
dst_inputFile = av.InputFile( outputFileName )
dst_properties = dst_inputFile.getProperties()
dst_audioStream = dst_properties.getAudioProperties()[0]
assert_equals( "pcm_s16le", dst_audioStream.getCodecName() )
assert_equals( "s16", dst_audioStream.getSampleFormatName() )
assert_equals( "signed 16 bits", dst_audioStream.getSampleFormatLongName() )
assert_equals( 48000, dst_audioStream.getSampleRate() )
assert_equals( 1, dst_audioStream.getNbChannels() )