-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathtestTranscoderRewrap.py
More file actions
99 lines (82 loc) · 3.84 KB
/
Copy pathtestTranscoderRewrap.py
File metadata and controls
99 lines (82 loc) · 3.84 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
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_FILE') is None:
from nose.plugins.skip import SkipTest
raise SkipTest("Need to define environment variables AVTRANSCODER_TEST_VIDEO_FILE and AVTRANSCODER_TEST_AUDIO_WAVE_FILE")
from nose.tools import *
from pyAvTranscoder import avtranscoder as av
av.preloadCodecsAndFormats()
av.Logger.setLogLevel(av.AV_LOG_QUIET)
def testRewrapAudioStream():
"""
Rewrap one audio stream.
"""
# get src file of wrap
inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE']
src_inputFile = av.InputFile( inputFileName )
progress = av.NoDisplayProgress()
src_inputFile.analyse( progress )
src_properties = src_inputFile.getProperties()
src_audioStream = src_properties.getAudioProperties()[0]
formatList = src_properties.getFormatName().split(",")
outputFileName = "testRewrapAudioStream." + formatList[0]
ouputFile = av.OutputFile( outputFileName )
transcoder = av.Transcoder( ouputFile )
transcoder.add( inputFileName, 0, "" )
transcoder.process( progress )
# get dst file of wrap
dst_inputFile = av.InputFile( outputFileName )
dst_inputFile.analyse( progress, av.eAnalyseLevelHeader )
dst_properties = dst_inputFile.getProperties()
dst_audioStream = dst_properties.getAudioProperties()[0]
# check format
assert_equals( src_properties.getFormatName(), dst_properties.getFormatName() )
assert_equals( src_properties.getFormatLongName(), dst_properties.getFormatLongName() )
assert_equals( src_properties.getStartTime(), dst_properties.getStartTime() )
assert_equals( src_properties.getDuration(), dst_properties.getDuration() )
deltaBitRateAudio = 10
assert_almost_equals( src_properties.getBitRate(), dst_properties.getBitRate(), delta=deltaBitRateAudio )
assert_equals( src_properties.getPacketSize(), dst_properties.getPacketSize() )
# check audio properties
src_propertiesMap = src_audioStream.getPropertiesAsMap()
dst_propertiesMap = dst_audioStream.getPropertiesAsMap()
for key in src_propertiesMap:
# @todo: don't skip channel layout
if key == "channelLayout":
continue
assert_equals( src_propertiesMap[key], dst_propertiesMap[key] )
def testRewrapVideoStream():
"""
Rewrap one video stream.
"""
# get src file of wrap
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_FILE']
src_inputFile = av.InputFile( inputFileName )
progress = av.NoDisplayProgress()
src_inputFile.analyse( progress )
src_properties = src_inputFile.getProperties()
src_videoStream = src_properties.getVideoProperties()[0]
formatList = src_properties.getFormatName().split(",")
outputFileName = "testRewrapVideoStream." + formatList[0]
ouputFile = av.OutputFile( outputFileName )
transcoder = av.Transcoder( ouputFile )
transcoder.add( inputFileName, 0, "" )
transcoder.process( progress )
# get dst file of wrap
dst_inputFile = av.InputFile( outputFileName )
dst_inputFile.analyse( progress )
dst_properties = dst_inputFile.getProperties()
dst_videoStream = dst_properties.getVideoProperties()[0]
# check format
assert_equals( src_properties.getFormatName(), dst_properties.getFormatName() )
assert_equals( src_properties.getFormatLongName(), dst_properties.getFormatLongName() )
assert_equals( src_properties.getStartTime(), dst_properties.getStartTime() )
assert_equals( src_properties.getDuration(), dst_properties.getDuration() )
deltaBitRateVideo = 500000
assert_almost_equals( src_properties.getBitRate(), dst_properties.getBitRate(), delta=deltaBitRateVideo )
assert_equals( src_properties.getPacketSize(), dst_properties.getPacketSize() )
# check audio properties
src_propertiesMap = src_videoStream.getPropertiesAsMap()
dst_propertiesMap = dst_videoStream.getPropertiesAsMap()
for key in src_propertiesMap:
assert_equals( src_propertiesMap[key], dst_propertiesMap[key] )