Skip to content

Commit 6817680

Browse files
author
Clement Champetier
committed
pyTest: add script to test setFrame during process
* 2 tests in the python file: * Generate a video stream, and set its frame during process. * Generate a audio stream, and set its frame during process. * Swig: add template to have access to DataBuffer methods in bindings. * IInputEssence: add virtual method setFrame. Reasons: * avoid cast when setFrame. * can access this feature whithout issue in bindings. * it could be a case to set some frames of a stream which is from an input file (still not implemented).
1 parent 6946e6c commit 6817680

File tree

3 files changed

+119
-0
lines changed

3 files changed

+119
-0
lines changed

src/AvTranscoder/avTranscoder.i

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ namespace std {
6161
%template(ChannelVector) vector< avtranscoder::Channel >;
6262
%template(ProfileMap) map< string, string >;
6363
%template(ProfilesVector) vector< map< string, string > >;
64+
%template(DataBuffer) std::vector< unsigned char >;
6465
}
6566

6667
%include "AvTranscoder/progress/progress.i"

src/AvTranscoder/essenceStream/IInputEssence.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class AvExport IInputEssence
3131
* @return status of decoding
3232
*/
3333
virtual bool readNextFrame( Frame& frameBuffer, const size_t subStreamIndex ) = 0;
34+
35+
virtual void setFrame( Frame& inputFrame ) {}
3436
};
3537

3638
}

test/pyTest/testSetFrame.py

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import os
2+
3+
from nose.tools import *
4+
5+
from pyAvTranscoder import avtranscoder as av
6+
7+
8+
def testSetVideoFrame():
9+
"""
10+
Generate a video stream, and set its frame during process.
11+
"""
12+
13+
# create output
14+
outputFileName = "testSetVideoFrame.mov"
15+
ouputFile = av.OutputFile( outputFileName )
16+
17+
# create video frame and codec
18+
imageDesc = av.VideoFrameDesc()
19+
imageDesc.setWidth( 1920 )
20+
imageDesc.setHeight( 1080 )
21+
imageDesc.setDar( 1920, 1080 )
22+
23+
inputPixel = av.Pixel()
24+
inputPixel.setColorComponents( av.eComponentRgb );
25+
inputPixel.setPlanar( False );
26+
27+
imageDesc.setPixel( inputPixel );
28+
29+
inputVideoCodec = av.VideoCodec( av.eCodecTypeEncoder, "mpeg2video" );
30+
inputVideoCodec.setImageParameters( imageDesc );
31+
32+
# create transcoder and add a video stream
33+
transcoder = av.Transcoder( ouputFile )
34+
transcoder.add( "", 0, "xdcamhd422", inputVideoCodec )
35+
videoEssence = transcoder.getStream( 0 ).getCurrentEssence()
36+
37+
# start process
38+
transcoder.init()
39+
ouputFile.beginWrap()
40+
41+
# process 255 frames
42+
for i in range(0,255):
43+
transcoder.processFrame()
44+
# set video frame
45+
frame = av.VideoFrame( imageDesc )
46+
frame.getBuffer().assign(frame.getBuffer().size(), i)
47+
videoEssence.setFrame( frame )
48+
49+
# end process
50+
ouputFile.endWrap()
51+
52+
# get dst file of transcode
53+
dst_inputFile = av.InputFile( outputFileName )
54+
progress = av.NoDisplayProgress()
55+
dst_inputFile.analyse( progress, av.InputFile.eAnalyseLevelFast )
56+
dst_properties = dst_inputFile.getProperties()
57+
dst_videoStream = dst_properties.videoStreams[0]
58+
59+
assert_equals( "mpeg2video", dst_videoStream.codecName )
60+
assert_equals( "MPEG-2 video", dst_videoStream.codecLongName )
61+
assert_equals( 1920, dst_videoStream.width )
62+
assert_equals( 1080, dst_videoStream.height )
63+
assert_equals( 16, dst_videoStream.dar.num )
64+
assert_equals( 9, dst_videoStream.dar.den )
65+
66+
67+
def testSetAudioFrame():
68+
"""
69+
Generate a audio stream, and set its frame during process.
70+
"""
71+
72+
# create output
73+
outputFileName = "testSetAudioFrame.wav"
74+
ouputFile = av.OutputFile( outputFileName )
75+
76+
# create video frame and codec
77+
audioDesc = av.AudioFrameDesc()
78+
audioDesc.setSampleRate( 48000 )
79+
audioDesc.setChannels( 1 )
80+
audioDesc.setSampleFormat( "s32" )
81+
82+
inputAudioCodec = av.AudioCodec( av.eCodecTypeEncoder, "pcm_s24le" );
83+
inputAudioCodec.setAudioParameters( audioDesc );
84+
85+
# create transcoder and add a video stream
86+
transcoder = av.Transcoder( ouputFile )
87+
transcoder.add( "", 0, "wave24b48kmono", inputAudioCodec )
88+
audioEssence = transcoder.getStream( 0 ).getCurrentEssence()
89+
90+
# start process
91+
transcoder.init()
92+
ouputFile.beginWrap()
93+
94+
# process 255 frames
95+
for i in range(0,255):
96+
transcoder.processFrame()
97+
# set video frame
98+
frame = av.AudioFrame( audioDesc )
99+
frame.getBuffer().assign(frame.getBuffer().size(), i)
100+
audioEssence.setFrame( frame )
101+
102+
# end process
103+
ouputFile.endWrap()
104+
105+
# get dst file of transcode
106+
dst_inputFile = av.InputFile( outputFileName )
107+
progress = av.NoDisplayProgress()
108+
dst_inputFile.analyse( progress, av.InputFile.eAnalyseLevelFast )
109+
dst_properties = dst_inputFile.getProperties()
110+
dst_audioStream = dst_properties.audioStreams[0]
111+
112+
assert_equals( "pcm_s24le", dst_audioStream.codecName )
113+
assert_equals( "PCM signed 24-bit little-endian", dst_audioStream.codecLongName )
114+
assert_equals( "signed 32 bits", dst_audioStream.sampleFormat )
115+
assert_equals( 48000, dst_audioStream.sampleRate )
116+
assert_equals( 1, dst_audioStream.channels )

0 commit comments

Comments
 (0)