-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathtestSetFrame.py
More file actions
105 lines (85 loc) · 3.49 KB
/
Copy pathtestSetFrame.py
File metadata and controls
105 lines (85 loc) · 3.49 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
from nose.tools import *
from pyAvTranscoder import avtranscoder as av
def testSetVideoFrame():
"""
Generate a video stream, and set its frame during process.
"""
# create output
outputFileName = "testSetVideoFrame.mov"
ouputFile = av.OutputFile( outputFileName )
# create custom profile
encodingProfile = av.ProfileMap()
encodingProfile[av.avProfileIdentificator] = "encodingProfile"
encodingProfile[av.avProfileIdentificatorHuman] = "custom profile"
encodingProfile[av.avProfileType] = av.avProfileTypeVideo
encodingProfile[av.avProfileCodec] = "mpeg2video"
encodingProfile[av.avProfilePixelFormat] = "yuv422p"
encodingProfile[av.avProfileWidth] = "1920"
encodingProfile[av.avProfileHeight] = "1080"
# create transcoder and add a video stream
transcoder = av.Transcoder( ouputFile )
transcoder.addGenerateStream( encodingProfile )
videoDecoder = transcoder.getStreamTranscoder( 0 ).getCurrentDecoder()
# start process
ouputFile.beginWrap()
transcoder.preProcessCodecLatency()
p = av.ConsoleProgress()
# process 51 frames
nbFrames = 255
for i in range(0, nbFrames, 5):
transcoder.processFrame()
p.progress( i, nbFrames )
# set video frame
frame = av.VideoFrame(av.VideoFrameDesc(1920, 1080, "rgb24"))
frame.assignValue(i)
videoDecoder.setNextFrame( frame )
# end process
ouputFile.endWrap()
# get dst file of transcode
dst_inputFile = av.InputFile( outputFileName )
progress = av.NoDisplayProgress()
dst_inputFile.analyse( progress, av.eAnalyseLevelHeader )
dst_properties = dst_inputFile.getProperties()
dst_videoStream = dst_properties.getVideoProperties()[0]
assert_equals( "mpeg2video", dst_videoStream.getCodecName() )
assert_equals( 1920, dst_videoStream.getWidth() )
assert_equals( 1080, dst_videoStream.getHeight() )
assert_equals( 16, dst_videoStream.getDar().num )
assert_equals( 9, dst_videoStream.getDar().den )
def testSetAudioFrame():
"""
Generate a audio stream, and set its frame during process.
"""
# create output
outputFileName = "testSetAudioFrame.wav"
ouputFile = av.OutputFile( outputFileName )
# create transcoder and add a video stream
transcoder = av.Transcoder( ouputFile )
transcoder.addGenerateStream( "wave24b48kmono" )
audioDecoder = transcoder.getStreamTranscoder( 0 ).getCurrentDecoder()
# start process
ouputFile.beginWrap()
transcoder.preProcessCodecLatency()
p = av.ConsoleProgress()
# process 51 frames
nbFrames = 255
for i in range(0, nbFrames):
transcoder.processFrame()
p.progress( i, nbFrames )
# set video frame
frame = av.AudioFrame(av.AudioFrameDesc(44100, 1, "s16"))
frame.assignValue(i)
audioDecoder.setNextFrame( frame )
# end process
ouputFile.endWrap()
# get dst file of transcode
dst_inputFile = av.InputFile( outputFileName )
progress = av.NoDisplayProgress()
dst_inputFile.analyse( progress, av.eAnalyseLevelHeader )
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() )