forked from avTranscoder/avTranscoder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestTranscoderTranscodeVideo.py
More file actions
164 lines (131 loc) · 6.81 KB
/
Copy pathtestTranscoderTranscodeVideo.py
File metadata and controls
164 lines (131 loc) · 6.81 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
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 variable AVTRANSCODER_TEST_VIDEO_AVI_FILE")
from nose.tools import *
from pyAvTranscoder import avtranscoder as av
def testTranscodeDnxhd120():
"""
Transcode one video stream (profile dnxhd120).
"""
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE']
outputFileName = "testTranscodeDnxhd120.mxf"
ouputFile = av.OutputFile( outputFileName )
transcoder = av.Transcoder( ouputFile )
inputFile = av.InputFile( inputFileName )
src_videoStream = inputFile.getProperties().getVideoProperties()[0]
videoStreamIndex = src_videoStream.getStreamIndex()
transcoder.addStream( av.InputStreamDesc(inputFileName, videoStreamIndex), "dnxhd120" )
progress = av.ConsoleProgress()
processStat = transcoder.process( progress )
# check process stat returned
videoStat = processStat.getVideoStat(0)
# do not test duration because the profile "dnxhd120" forces the fps to 25
assert_equals(int(src_videoStream.getDuration() * src_videoStream.getFps()), videoStat.getNbFrames())
# get dst file of transcode
dst_inputFile = av.InputFile( outputFileName )
dst_inputFile.analyse(progress, av.eAnalyseLevelFirstGop)
dst_properties = dst_inputFile.getProperties()
dst_videoStream = dst_properties.getVideoProperties()[0]
assert_equals( "dnxhd", dst_videoStream.getCodecName() )
expectedBitRate = 120000000
deltaBitRate = expectedBitRate * 0.05
assert_almost_equals( expectedBitRate, dst_videoStream.getBitRate(), delta=deltaBitRate )
assert_equals( "yuv422p", dst_videoStream.getPixelProperties().getPixelName() )
assert_equals( 1920, dst_videoStream.getWidth() )
assert_equals( 1080, dst_videoStream.getHeight() )
assert_equals( 1, dst_videoStream.getGopSize() )
def testTranscodeDnxhd185():
"""
Transcode one video stream (profile dnxhd185).
"""
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE']
outputFileName = "testTranscodeDnxhd185.mxf"
ouputFile = av.OutputFile( outputFileName )
transcoder = av.Transcoder( ouputFile )
inputFile = av.InputFile( inputFileName )
src_videoStream = inputFile.getProperties().getVideoProperties()[0]
videoStreamIndex = src_videoStream.getStreamIndex()
transcoder.addStream( av.InputStreamDesc(inputFileName, videoStreamIndex), "dnxhd185" )
progress = av.ConsoleProgress()
processStat = transcoder.process( progress )
# check process stat returned
videoStat = processStat.getVideoStat(0)
# do not test duration because the profile "dnxhd185" forces the fps to 25
assert_equals(int(src_videoStream.getDuration() * src_videoStream.getFps()), videoStat.getNbFrames())
# get dst file of transcode
dst_inputFile = av.InputFile( outputFileName )
dst_inputFile.analyse(progress, av.eAnalyseLevelFirstGop)
dst_properties = dst_inputFile.getProperties()
dst_videoStream = dst_properties.getVideoProperties()[0]
assert_equals( "dnxhd", dst_videoStream.getCodecName() )
expectedBitRate = 185000000
deltaBitRate = expectedBitRate * 0.05
assert_almost_equals( expectedBitRate, dst_videoStream.getBitRate(), delta=deltaBitRate )
assert_equals( "yuv422p", dst_videoStream.getPixelProperties().getPixelName() )
assert_equals( 1920, dst_videoStream.getWidth() )
assert_equals( 1080, dst_videoStream.getHeight() )
assert_equals( 1, dst_videoStream.getGopSize() )
def testTranscodeDnxhd185x():
"""
Transcode one video stream (profile dnxhd185x).
"""
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE']
outputFileName = "testTranscodeDnxhd185x.mxf"
ouputFile = av.OutputFile( outputFileName )
transcoder = av.Transcoder( ouputFile )
inputFile = av.InputFile( inputFileName )
src_videoStream = inputFile.getProperties().getVideoProperties()[0]
videoStreamIndex = src_videoStream.getStreamIndex()
transcoder.addStream( av.InputStreamDesc(inputFileName, videoStreamIndex), "dnxhd185x" )
progress = av.ConsoleProgress()
processStat = transcoder.process( progress )
# check process stat returned
videoStat = processStat.getVideoStat(0)
# do not test duration because the profile "dnxhd185x" forces the fps to 25
assert_equals(int(src_videoStream.getDuration() * src_videoStream.getFps()), videoStat.getNbFrames())
# get dst file of transcode
dst_inputFile = av.InputFile( outputFileName )
dst_inputFile.analyse(progress, av.eAnalyseLevelFirstGop)
dst_properties = dst_inputFile.getProperties()
dst_videoStream = dst_properties.getVideoProperties()[0]
assert_equals( "dnxhd", dst_videoStream.getCodecName() )
expectedBitRate = 185000000
deltaBitRate = expectedBitRate * 0.05
assert_almost_equals( expectedBitRate, dst_videoStream.getBitRate(), delta=deltaBitRate )
assert_equals( "yuv422p10le", dst_videoStream.getPixelProperties().getPixelName() )
assert_equals( 1920, dst_videoStream.getWidth() )
assert_equals( 1080, dst_videoStream.getHeight() )
assert_equals( 1, dst_videoStream.getGopSize() )
def testTranscodeYUV420():
"""
Process one video stream (custom profile of encoding, with pixel format YUV420).
"""
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE']
outputFileName = "testTranscodeYUV420.avi"
ouputFile = av.OutputFile( outputFileName )
transcoder = av.Transcoder( ouputFile )
# create custom profile
customProfile = av.ProfileMap()
customProfile[av.avProfileIdentificator] = "customProfile"
customProfile[av.avProfileIdentificatorHuman] = "custom profile"
customProfile[av.avProfileType] = av.avProfileTypeVideo
customProfile[av.avProfileCodec] = "mpeg2video"
customProfile[av.avProfilePixelFormat] = "yuv420p"
inputFile = av.InputFile( inputFileName )
src_videoStream = inputFile.getProperties().getVideoProperties()[0]
videoStreamIndex = src_videoStream.getStreamIndex()
transcoder.addStream( av.InputStreamDesc(inputFileName, videoStreamIndex), customProfile )
progress = av.ConsoleProgress()
processStat = transcoder.process( progress )
# check process stat returned
videoStat = processStat.getVideoStat(0)
assert_equals(src_videoStream.getDuration(), videoStat.getDuration())
assert_equals(int(src_videoStream.getDuration() * src_videoStream.getFps()), videoStat.getNbFrames())
# get dst file of transcode
dst_inputFile = av.InputFile( outputFileName )
dst_properties = dst_inputFile.getProperties()
dst_videoStream = dst_properties.getVideoProperties()[0]
assert_equals( "mpeg2video", dst_videoStream.getCodecName() )
assert_equals( "yuv420p", dst_videoStream.getPixelProperties().getPixelName() )