Skip to content

Commit 6371c40

Browse files
author
Clement Champetier
committed
pyTest: added testFilter to check filter classes
1 parent 1dc1f09 commit 6371c40

File tree

1 file changed

+130
-0
lines changed

1 file changed

+130
-0
lines changed

test/pyTest/testFilter.py

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
import os
2+
3+
# Check if environment is setup to run the tests
4+
if os.environ.get('AVTRANSCODER_TEST_VIDEO_AVI_FILE') is None or os.environ.get('AVTRANSCODER_TEST_AUDIO_WAVE_FILE') is None:
5+
from nose.plugins.skip import SkipTest
6+
raise SkipTest("Need to define environment variables "
7+
"AVTRANSCODER_TEST_VIDEO_AVI_FILE and "
8+
"AVTRANSCODER_TEST_AUDIO_WAVE_FILE")
9+
10+
from nose.tools import *
11+
12+
from pyAvTranscoder import avtranscoder as av
13+
14+
15+
@raises(RuntimeError)
16+
def testUnknwonFilter():
17+
"""
18+
Try to create an unknown filter.
19+
"""
20+
unknwonFilter = av.Filter("unknwonFilter")
21+
22+
23+
def testFilterAttributes():
24+
"""
25+
Check the attributes of an exiting filter.
26+
"""
27+
# video filter
28+
options = "75:52";
29+
name = "scale"
30+
scale = av.Filter(name, options)
31+
32+
assert_equals(scale.getName(), name)
33+
assert_equals(scale.getOptions(), options)
34+
assert_equals(scale.getInstanceName(), name)
35+
36+
# audio filter
37+
options = "";
38+
name = "volume"
39+
instanceName = "vol1"
40+
volume = av.Filter(name, options, instanceName)
41+
42+
# same instance name
43+
assert_equals(volume.getName(), name)
44+
assert_equals(volume.getOptions(), options)
45+
assert_equals(volume.getInstanceName(), instanceName)
46+
47+
def testVideoTranscodeWithFilter():
48+
"""
49+
A video transcode with a yadif filter.
50+
"""
51+
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE']
52+
outputFileName = "testVideoTranscodeWithFilter.avi"
53+
54+
ouputFile = av.OutputFile( outputFileName )
55+
transcoder = av.Transcoder( ouputFile )
56+
57+
inputFile = av.InputFile( inputFileName )
58+
src_videoStream = inputFile.getProperties().getVideoProperties()[0]
59+
60+
# transcode the video stream
61+
videoStreamIndex = src_videoStream.getStreamIndex()
62+
customProfile = av.ProfileMap()
63+
customProfile[av.avProfileIdentificator] = "customProfile"
64+
customProfile[av.avProfileIdentificatorHuman] = "custom profile"
65+
customProfile[av.avProfileType] = av.avProfileTypeVideo
66+
customProfile[av.avProfileCodec] = "mpeg2video"
67+
customProfile[av.avProfilePixelFormat] = "yuv420p"
68+
transcoder.add( inputFileName, videoStreamIndex, customProfile )
69+
70+
# add yadif filter
71+
streamTranscoder = transcoder.getStreamTranscoder(0)
72+
filterGraph = streamTranscoder.getFilterGraph()
73+
filterGraph.addFilter("yadif")
74+
75+
progress = av.ConsoleProgress()
76+
processStat = transcoder.process( progress )
77+
78+
# check process stat returned
79+
videoStat = processStat.getVideoStat(0)
80+
assert_equals(src_videoStream.getDuration(), videoStat.getDuration())
81+
assert_equals(int(src_videoStream.getDuration() * src_videoStream.getFps()), videoStat.getNbFrames())
82+
83+
# get dst file of transcode
84+
dst_inputFile = av.InputFile( outputFileName )
85+
dst_properties = dst_inputFile.getProperties()
86+
dst_videoStream = dst_properties.getVideoProperties()[0]
87+
88+
assert_equals( "mpeg2video", dst_videoStream.getCodecName() )
89+
assert_equals( "yuv420p", dst_videoStream.getPixelProperties().getPixelName() )
90+
91+
92+
def testAudioTranscodeWithFilter():
93+
"""
94+
An audio transcode with a volume filter.
95+
"""
96+
inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE']
97+
outputFileName = "testAudioTranscodeWithFilter.wav"
98+
99+
ouputFile = av.OutputFile( outputFileName )
100+
transcoder = av.Transcoder( ouputFile )
101+
102+
inputFile = av.InputFile( inputFileName )
103+
src_audioStream = inputFile.getProperties().getAudioProperties()[0]
104+
105+
# transcode the video stream
106+
audioStreamIndex = src_audioStream.getStreamIndex()
107+
transcoder.add( inputFileName, audioStreamIndex, "wave24b48kmono" )
108+
109+
# add volume filter (here +150% of current volume)
110+
streamTranscoder = transcoder.getStreamTranscoder(0)
111+
filterGraph = streamTranscoder.getFilterGraph()
112+
filterGraph.addFilter("volume", "1.5")
113+
114+
progress = av.ConsoleProgress()
115+
processStat = transcoder.process( progress )
116+
117+
# check process stat returned
118+
audioStat = processStat.getAudioStat(0)
119+
assert_equals(src_audioStream.getDuration(), audioStat.getDuration())
120+
121+
# get dst file of transcode
122+
dst_inputFile = av.InputFile( outputFileName )
123+
dst_properties = dst_inputFile.getProperties()
124+
dst_audioStream = dst_properties.getAudioProperties()[0]
125+
126+
assert_equals( "pcm_s24le", dst_audioStream.getCodecName() )
127+
assert_equals( "s32", dst_audioStream.getSampleFormatName() )
128+
assert_equals( "signed 32 bits", dst_audioStream.getSampleFormatLongName() )
129+
assert_equals( 48000, dst_audioStream.getSampleRate() )
130+
assert_equals( 1, dst_audioStream.getNbChannels() )

0 commit comments

Comments
 (0)