Skip to content

Commit 5f06065

Browse files
committed
Merge pull request #131 from cchampet/dev_pyTestsMovNbFramesAndSamples
PyTest: transcode MOV + check nb samples/frames
2 parents eeb101a + b817eda commit 5f06065

15 files changed

+398
-81
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,18 @@ codec=codecName
6565

6666
###### nosetests
6767
Python tests using nosetests.
68+
```
69+
cd test/pyTest
70+
nosetests
71+
```
6872

69-
Create environment variables to use your files in tests.
70-
* ```AVTRANSCODER_TEST_AUDIO_FILE```
73+
Some tests need environment variables to be executed (otherwise they will be skipped):
7174
* ```AVTRANSCODER_TEST_VIDEO_FILE```
75+
* ```AVTRANSCODER_TEST_AUDIO_WAVE_FILE```
76+
* ```AVTRANSCODER_TEST_AUDIO_MOV_FILE```
7277

7378
Note: for continuous integration, we launch tests with media files contained in ```avTranscoder-data``` repository.
7479

75-
Launch the tests:
76-
```
77-
cd test/pyTest
78-
nosetests
79-
```
8080

8181
#### Packaging
8282

src/AvTranscoder/codec/ICodec.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,17 @@ void ICodec::open()
6060
if( ret < 0 )
6161
{
6262
std::string msg = "unable open codec: ";
63-
msg += _avCodec->long_name;
64-
msg += " (";
65-
msg += _avCodec->name;
66-
msg += ") ";
63+
64+
if( _avCodec && _avCodec->long_name )
65+
msg += _avCodec->long_name;
66+
67+
if( _avCodec && _avCodec->name )
68+
{
69+
msg += " (";
70+
msg += _avCodec->name;
71+
msg += ") ";
72+
}
73+
6774
avcodec_close( _avCodecContext );
6875

6976
msg += getDescriptionFromErrorCode( ret );

src/AvTranscoder/transcoder/StreamTranscoder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ bool StreamTranscoder::processRewrap()
342342
assert( _inputStream != NULL );
343343
assert( _outputStream != NULL );
344344

345-
LOG_INFO( "Rewrap a frame" )
345+
LOG_DEBUG( "Rewrap a frame" )
346346

347347
CodedData data;
348348
if( ! _inputStream->readNextPacket( data ) )
@@ -380,7 +380,7 @@ bool StreamTranscoder::processTranscode( const int subStreamIndex )
380380
assert( _frameBuffer != NULL );
381381
assert( _transform != NULL );
382382

383-
LOG_INFO( "Transcode a frame" )
383+
LOG_DEBUG( "Transcode a frame" )
384384

385385
// check offset
386386
if( _offset )

test/pyTest/testProperties.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import os
22

3+
# Check if environment is setup to run the tests
4+
if os.environ.get('AVTRANSCODER_TEST_AUDIO_WAVE_FILE') is None:
5+
from nose.plugins.skip import SkipTest
6+
raise SkipTest("Need to define environment variable AVTRANSCODER_TEST_AUDIO_WAVE_FILE")
7+
38
from nose.tools import *
49

510
from pyAvTranscoder import avtranscoder as av
611

712
av.preloadCodecsAndFormats()
13+
av.Logger.setLogLevel(av.AV_LOG_QUIET)
814

915

1016
def testAddMetadataDate():
@@ -17,7 +23,7 @@ def testAddMetadataDate():
1723
transcoder = av.Transcoder( ouputFile )
1824

1925
# rewrap a stream
20-
transcoder.add( os.environ['AVTRANSCODER_TEST_AUDIO_FILE'], 0, "")
26+
transcoder.add( os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE'], 0, "")
2127

2228
# add one metadata
2329
metadata_to_check = ("date", "value")
@@ -42,7 +48,7 @@ def testAddImpossibleMetadata():
4248
transcoder = av.Transcoder( ouputFile )
4349

4450
# rewrap a stream
45-
transcoder.add( os.environ['AVTRANSCODER_TEST_AUDIO_FILE'], 0, "")
51+
transcoder.add( os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE'], 0, "")
4652

4753
# add one metadata
4854
metadata_to_check = ("undefinedMetadataKey", "undefinedMetadataValue")

test/pyTest/testSetFrame.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import os
2-
31
from nose.tools import *
42

53
from pyAvTranscoder import avtranscoder as av
64

75
av.preloadCodecsAndFormats()
6+
av.Logger.setLogLevel(av.AV_LOG_QUIET)
87

98

109
def testSetVideoFrame():

test/pyTest/testTranscoderAdd.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
import os
22

3+
# Check if environment is setup to run the tests
4+
if os.environ.get('AVTRANSCODER_TEST_AUDIO_WAVE_FILE') is None:
5+
from nose.plugins.skip import SkipTest
6+
raise SkipTest("Need to define environment variable AVTRANSCODER_TEST_AUDIO_WAVE_FILE")
7+
38
from nose.tools import *
49

510
from pyAvTranscoder import avtranscoder as av
611

712
av.preloadCodecsAndFormats()
13+
av.Logger.setLogLevel(av.AV_LOG_QUIET)
814

915

1016
def testAddStreamTranscoder():
1117
"""
1218
Add a streamTranscoder to the Transcoder, and process rewrap of an audio stream.
1319
"""
1420
# input
15-
inputFile = av.InputFile( os.environ['AVTRANSCODER_TEST_AUDIO_FILE'] )
21+
inputFile = av.InputFile( os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE'] )
1622
inputIndex = 0
1723
inputFile.activateStream( inputIndex )
1824

test/pyTest/testTranscoderDummy.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from pyAvTranscoder import avtranscoder as av
44

55
av.preloadCodecsAndFormats()
6+
av.Logger.setLogLevel(av.AV_LOG_QUIET)
67

78

89
@raises(RuntimeError)

test/pyTest/testTranscoderNbFrames.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import os
2+
3+
# Check if environment is setup to run the tests
4+
if os.environ.get('AVTRANSCODER_TEST_VIDEO_FILE') is None:
5+
from nose.plugins.skip import SkipTest
6+
raise SkipTest("Need to define environment variable AVTRANSCODER_TEST_VIDEO_FILE")
7+
8+
from nose.tools import *
9+
10+
from pyAvTranscoder import avtranscoder as av
11+
12+
av.preloadCodecsAndFormats()
13+
av.Logger.setLogLevel(av.AV_LOG_QUIET)
14+
15+
16+
def testNbFramesVideoRewrap():
17+
"""
18+
Rewrap one video stream, check nb frames.
19+
"""
20+
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_FILE']
21+
outputFileName = "testNbFramesVideoRewrap.mov"
22+
23+
ouputFile = av.OutputFile( outputFileName )
24+
transcoder = av.Transcoder( ouputFile )
25+
26+
transcoder.add( inputFileName, 0, "" )
27+
28+
progress = av.ConsoleProgress()
29+
transcoder.process( progress )
30+
31+
# get src file of rewrap
32+
src_inputFile = av.InputFile( inputFileName )
33+
src_properties = src_inputFile.getProperties()
34+
src_videoStream = src_properties.getVideoProperties()[0]
35+
36+
# get dst file of rewrap
37+
dst_inputFile = av.InputFile( outputFileName )
38+
dst_properties = dst_inputFile.getProperties()
39+
dst_videoStream = dst_properties.getVideoProperties()[0]
40+
41+
assert_equals( src_videoStream.getNbFrames(), dst_videoStream.getNbFrames() )
42+
43+
def testNbFramesVideoTranscode():
44+
"""
45+
Transcode one video stream (to h264), check nb frames.
46+
"""
47+
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_FILE']
48+
outputFileName = "testNbFramesVideoTranscode.mov"
49+
50+
ouputFile = av.OutputFile( outputFileName )
51+
transcoder = av.Transcoder( ouputFile )
52+
53+
transcoder.add( inputFileName, 0, "mpeg2" )
54+
55+
progress = av.ConsoleProgress()
56+
transcoder.process( progress )
57+
58+
# get src file of transcode
59+
src_inputFile = av.InputFile( inputFileName )
60+
src_properties = src_inputFile.getProperties()
61+
src_videoStream = src_properties.getVideoProperties()[0]
62+
63+
# get dst file of transcode
64+
dst_inputFile = av.InputFile( outputFileName )
65+
dst_properties = dst_inputFile.getProperties()
66+
dst_videoStream = dst_properties.getVideoProperties()[0]
67+
68+
assert_equals( src_videoStream.getNbFrames(), dst_videoStream.getNbFrames() )
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import os
2+
3+
# Check if environment is setup to run the tests
4+
if os.environ.get('AVTRANSCODER_TEST_AUDIO_WAVE_FILE') is None:
5+
from nose.plugins.skip import SkipTest
6+
raise SkipTest("Need to define environment variable AVTRANSCODER_TEST_AUDIO_WAVE_FILE")
7+
8+
from nose.tools import *
9+
10+
from pyAvTranscoder import avtranscoder as av
11+
12+
av.preloadCodecsAndFormats()
13+
av.Logger.setLogLevel(av.AV_LOG_QUIET)
14+
15+
16+
def testNbSamplesAudioRewrap():
17+
"""
18+
Rewrap one audio stream, check nb samples.
19+
"""
20+
inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE']
21+
outputFileName = "testNbSamplesAudioRewrap.wav"
22+
23+
ouputFile = av.OutputFile( outputFileName )
24+
transcoder = av.Transcoder( ouputFile )
25+
26+
transcoder.add( inputFileName, 0, "" )
27+
28+
progress = av.ConsoleProgress()
29+
transcoder.process( progress )
30+
31+
# get src file of rewrap
32+
src_inputFile = av.InputFile( inputFileName )
33+
src_properties = src_inputFile.getProperties()
34+
src_audioStream = src_properties.getAudioProperties()[0]
35+
36+
# get dst file of rewrap
37+
dst_inputFile = av.InputFile( outputFileName )
38+
dst_properties = dst_inputFile.getProperties()
39+
dst_audioStream = dst_properties.getAudioProperties()[0]
40+
41+
assert_equals( src_audioStream.getNbSamples(), dst_audioStream.getNbSamples() )
42+
43+
def testNbSamplesAudioTranscode():
44+
"""
45+
Transcode one audio stream (to wave24b48kmono), check nb samples.
46+
"""
47+
inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE']
48+
outputFileName = "testNbSamplesAudioTranscode.wav"
49+
50+
ouputFile = av.OutputFile( outputFileName )
51+
transcoder = av.Transcoder( ouputFile )
52+
53+
transcoder.add( inputFileName, 0, "wave24b48kmono" )
54+
55+
progress = av.ConsoleProgress()
56+
transcoder.process( progress )
57+
58+
# get src file of transcode
59+
src_inputFile = av.InputFile( inputFileName )
60+
src_properties = src_inputFile.getProperties()
61+
src_audioStream = src_properties.getAudioProperties()[0]
62+
63+
# get dst file of transcode
64+
dst_inputFile = av.InputFile( outputFileName )
65+
dst_properties = dst_inputFile.getProperties()
66+
dst_audioStream = dst_properties.getAudioProperties()[0]
67+
68+
assert_equals( src_audioStream.getNbSamples(), dst_audioStream.getNbSamples() )

test/pyTest/testTranscoderOffset.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
import os
22

3+
# Check if environment is setup to run the tests
4+
if os.environ.get('AVTRANSCODER_TEST_AUDIO_WAVE_FILE') is None or os.environ.get('AVTRANSCODER_TEST_VIDEO_FILE') is None:
5+
from nose.plugins.skip import SkipTest
6+
raise SkipTest("Need to define environment variables AVTRANSCODER_TEST_VIDEO_FILE and AVTRANSCODER_TEST_AUDIO_WAVE_FILE")
7+
38
from nose.tools import *
49

510
from pyAvTranscoder import avtranscoder as av
611

712
av.preloadCodecsAndFormats()
13+
av.Logger.setLogLevel(av.AV_LOG_QUIET)
814

915

1016
def testTranscodeAudioOffset():
1117
"""
1218
Transcode one audio stream (profile wave24b48kmono) with offset at the beginning of the transcode.
1319
"""
14-
inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_FILE']
20+
inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE']
1521
outputFileName = "testTranscodeAudioOffset.wav"
1622

1723
ouputFile = av.OutputFile( outputFileName )
@@ -22,8 +28,18 @@ def testTranscodeAudioOffset():
2228
progress = av.ConsoleProgress()
2329
transcoder.process( progress )
2430

25-
# TODO: check output duration
31+
# get src file of transcode
32+
src_inputFile = av.InputFile( inputFileName )
33+
src_properties = src_inputFile.getProperties()
34+
src_audioStream = src_properties.getAudioProperties()[0]
35+
36+
# get dst file of transcode
37+
dst_inputFile = av.InputFile( outputFileName )
38+
dst_properties = dst_inputFile.getProperties()
39+
dst_audioStream = dst_properties.getAudioProperties()[0]
2640

41+
# check output duration
42+
assert_almost_equals( src_audioStream.getDuration() + 10, dst_audioStream.getDuration(), delta=0.1 )
2743

2844
def testTranscodeVideoOffset():
2945
"""
@@ -40,4 +56,15 @@ def testTranscodeVideoOffset():
4056
progress = av.ConsoleProgress()
4157
transcoder.process( progress )
4258

43-
# TODO: check output duration
59+
# get src file of transcode
60+
src_inputFile = av.InputFile( inputFileName )
61+
src_properties = src_inputFile.getProperties()
62+
src_videoStream = src_properties.getVideoProperties()[0]
63+
64+
# get dst file of transcode
65+
dst_inputFile = av.InputFile( outputFileName )
66+
dst_properties = dst_inputFile.getProperties()
67+
dst_videoStream = dst_properties.getVideoProperties()[0]
68+
69+
# check output duration
70+
assert_almost_equals( src_videoStream.getDuration() + 10, dst_videoStream.getDuration(), delta=0.1 )

test/pyTest/testTranscoderRewrap.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
import os
22

3+
# Check if environment is setup to run the tests
4+
if os.environ.get('AVTRANSCODER_TEST_AUDIO_WAVE_FILE') is None or os.environ.get('AVTRANSCODER_TEST_VIDEO_FILE') is None:
5+
from nose.plugins.skip import SkipTest
6+
raise SkipTest("Need to define environment variables AVTRANSCODER_TEST_VIDEO_FILE and AVTRANSCODER_TEST_AUDIO_WAVE_FILE")
7+
38
from nose.tools import *
49

510
from pyAvTranscoder import avtranscoder as av
611

712
av.preloadCodecsAndFormats()
13+
av.Logger.setLogLevel(av.AV_LOG_QUIET)
814

915

1016
def testRewrapAudioStream():
1117
"""
1218
Rewrap one audio stream.
1319
"""
1420
# get src file of wrap
15-
inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_FILE']
21+
inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE']
1622
src_inputFile = av.InputFile( inputFileName )
1723
progress = av.NoDisplayProgress()
1824
src_inputFile.analyse( progress )

0 commit comments

Comments
 (0)