Skip to content

Commit 0f8be92

Browse files
committed
Merge pull request #248 from cchampet/fix_getFps
Fix get fps
2 parents 6797dea + f1aa760 commit 0f8be92

File tree

9 files changed

+93
-42
lines changed

9 files changed

+93
-42
lines changed

src/AvTranscoder/mediaProperty/VideoProperties.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -516,17 +516,7 @@ int VideoProperties::getLevel() const
516516

517517
float VideoProperties::getFps() const
518518
{
519-
const Rational timeBase = getTimeBase();
520-
const float fps = timeBase.den / (double) timeBase.num;
521-
if( std::isinf( fps ) )
522-
{
523-
std::ostringstream os;
524-
os << "unable to retrieve a correct fps (found value: ";
525-
os << fps;
526-
os << ")";
527-
throw std::runtime_error( os.str() );
528-
}
529-
return fps;
519+
return av_q2d( _formatContext->streams[_streamIndex]->avg_frame_rate );
530520
}
531521

532522
bool VideoProperties::hasBFrames() const

src/AvTranscoder/mediaProperty/VideoProperties.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ class AvExport VideoProperties : public StreamProperties
5656
int getLevel() const;
5757

5858
/**
59-
* @brief Corresponds to the compute of the 'tbn' by ffmpeg.
60-
* tbn = the time base in AVStream that has come from the container
59+
* @brief Corresponds to the 'fps' returned by ffprobe.
60+
* fps = the average framerate that has come from the AVStream
61+
* tbn = the time base in AVStream that has come from the AVStream
6162
* tbc = the time base in AVCodecContext for the codec used for a particular stream
6263
* tbr = tbr is guessed from the video stream and is the value users want to see when they look for the video frame rate
63-
* @return
6464
*/
6565
float getFps() const;
6666

test/pyTest/testEProcessMethod.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import os
22

33
# Check if environment is setup to run the tests
4-
if os.environ.get('AVTRANSCODER_TEST_VIDEO_FILE') is None or os.environ.get('AVTRANSCODER_TEST_AUDIO_MOV_FILE') is None or os.environ.get('AVTRANSCODER_TEST_AUDIO_WAVE_FILE') is None:
4+
if os.environ.get('AVTRANSCODER_TEST_VIDEO_AVI_FILE') is None or os.environ.get('AVTRANSCODER_TEST_AUDIO_MOV_FILE') is None or os.environ.get('AVTRANSCODER_TEST_AUDIO_WAVE_FILE') is None:
55
from nose.plugins.skip import SkipTest
6-
raise SkipTest("Need to define environment variables AVTRANSCODER_TEST_VIDEO_FILE / AVTRANSCODER_TEST_AUDIO_MOV_FILE / AVTRANSCODER_TEST_AUDIO_WAVE_FILE")
6+
raise SkipTest("Need to define environment variables AVTRANSCODER_TEST_VIDEO_AVI_FILE / AVTRANSCODER_TEST_AUDIO_MOV_FILE / AVTRANSCODER_TEST_AUDIO_WAVE_FILE")
77

88
from nose.tools import *
99

@@ -17,7 +17,7 @@ def testEProcessMethodShortest():
1717
"""
1818
Process with method eProcessMethodShortest, check output duration.
1919
"""
20-
inputFileName_longest = os.environ['AVTRANSCODER_TEST_VIDEO_FILE']
20+
inputFileName_longest = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE']
2121
inputFileName_shortest = os.environ['AVTRANSCODER_TEST_AUDIO_MOV_FILE']
2222
outputFileName = "testEProcessMethodShortest.mov"
2323

@@ -46,7 +46,7 @@ def testEProcessMethodLongest():
4646
"""
4747
Process with method eProcessMethodLongest, check output duration.
4848
"""
49-
inputFileName_longest = os.environ['AVTRANSCODER_TEST_VIDEO_FILE']
49+
inputFileName_longest = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE']
5050
inputFileName_shortest = os.environ['AVTRANSCODER_TEST_AUDIO_MOV_FILE']
5151
outputFileName = "testEProcessMethodLongest.mov"
5252

@@ -75,7 +75,7 @@ def testEProcessMethodBasedOnStream():
7575
"""
7676
Process with method testEProcessMethodBasedOnStream, check output duration.
7777
"""
78-
inputFileName_first = os.environ['AVTRANSCODER_TEST_VIDEO_FILE']
78+
inputFileName_first = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE']
7979
inputFileName_second = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE']
8080
inputFileName_third = os.environ['AVTRANSCODER_TEST_AUDIO_MOV_FILE']
8181
outputFileName = "testEProcessMethodShortest.mov"
@@ -106,7 +106,7 @@ def testEProcessMethodBasedOnDuration():
106106
"""
107107
Process with method eProcessMethodBasedOnDuration, check output duration.
108108
"""
109-
inputFileName_first = os.environ['AVTRANSCODER_TEST_VIDEO_FILE']
109+
inputFileName_first = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE']
110110
inputFileName_second = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE']
111111
inputFileName_third = os.environ['AVTRANSCODER_TEST_AUDIO_MOV_FILE']
112112
outputFileName = "testEProcessMethodBasedOnDuration.mov"

test/pyTest/testNbFrames.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import os
22

33
# Check if environment is setup to run the tests
4-
if os.environ.get('AVTRANSCODER_TEST_VIDEO_FILE') is None:
4+
if os.environ.get('AVTRANSCODER_TEST_VIDEO_AVI_FILE') is None:
55
from nose.plugins.skip import SkipTest
6-
raise SkipTest("Need to define environment variable AVTRANSCODER_TEST_VIDEO_FILE")
6+
raise SkipTest("Need to define environment variable AVTRANSCODER_TEST_VIDEO_AVI_FILE")
77

88
from nose.tools import *
99

@@ -17,7 +17,7 @@ def testNbFramesVideoRewrap():
1717
"""
1818
Rewrap one video stream, check nb frames.
1919
"""
20-
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_FILE']
20+
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE']
2121
outputFileName = "testNbFramesVideoRewrap.mov"
2222

2323
ouputFile = av.OutputFile( outputFileName )
@@ -44,7 +44,7 @@ def testNbFramesVideoTranscode():
4444
"""
4545
Transcode one video stream (to h264), check nb frames.
4646
"""
47-
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_FILE']
47+
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE']
4848
outputFileName = "testNbFramesVideoTranscode.mov"
4949

5050
ouputFile = av.OutputFile( outputFileName )

test/pyTest/testOffset.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import os
22

33
# 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_AUDIO_MOV_FILE') is None or os.environ.get('AVTRANSCODER_TEST_VIDEO_FILE') is None:
4+
if os.environ.get('AVTRANSCODER_TEST_AUDIO_WAVE_FILE') is None or os.environ.get('AVTRANSCODER_TEST_AUDIO_MOV_FILE') is None or os.environ.get('AVTRANSCODER_TEST_VIDEO_AVI_FILE') is None:
55
from nose.plugins.skip import SkipTest
6-
raise SkipTest("Need to define environment variables AVTRANSCODER_TEST_VIDEO_FILE / AVTRANSCODER_TEST_AUDIO_MOV_FILE / AVTRANSCODER_TEST_AUDIO_WAVE_FILE")
6+
raise SkipTest("Need to define environment variables AVTRANSCODER_TEST_VIDEO_AVI_FILE / AVTRANSCODER_TEST_AUDIO_MOV_FILE / AVTRANSCODER_TEST_AUDIO_WAVE_FILE")
77

88
from nose.tools import *
99

@@ -138,7 +138,7 @@ def testTranscodeVideoPositiveOffset():
138138
"""
139139
Transcode one video stream (profile mpeg2) with offset at the beginning of the process.
140140
"""
141-
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_FILE']
141+
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE']
142142
outputFileName = "testTranscodeVideoPositiveOffset.mov"
143143
offset = 10
144144

@@ -168,7 +168,7 @@ def testTranscodeVideoNegativeOffset():
168168
"""
169169
Transcode one video stream (profile mpeg2) with a negative offset at the beginning of the process.
170170
"""
171-
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_FILE']
171+
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE']
172172
outputFileName = "testTranscodeVideoNegativeOffset.mov"
173173
offset = -5.5
174174

@@ -198,7 +198,7 @@ def testRewrapVideoPositiveOffset():
198198
"""
199199
Rewrap one video stream with offset at the beginning of the process.
200200
"""
201-
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_FILE']
201+
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE']
202202
outputFileName = "testRewrapVideoPositiveOffset.mov"
203203
offset = 10
204204

@@ -228,7 +228,7 @@ def testRewrapVideoNegativeOffset():
228228
"""
229229
Rewrap one video stream with a negative offset at the beginning of the process.
230230
"""
231-
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_FILE']
231+
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE']
232232
outputFileName = "testRewrapVideoNegativeOffset.mov"
233233
offset = -5.5
234234

test/pyTest/testProperties.py

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

33
# Check if environment is setup to run the tests
4-
if os.environ.get('AVTRANSCODER_TEST_AUDIO_WAVE_FILE') is None:
4+
if os.environ.get('AVTRANSCODER_TEST_AUDIO_WAVE_FILE') is None or os.environ.get('AVTRANSCODER_TEST_VIDEO_MP4_FILE') is None:
55
from nose.plugins.skip import SkipTest
6-
raise SkipTest("Need to define environment variable AVTRANSCODER_TEST_AUDIO_WAVE_FILE")
6+
raise SkipTest("Need to define environment variables AVTRANSCODER_TEST_AUDIO_WAVE_FILE / AVTRANSCODER_TEST_VIDEO_MP4_FILE")
77

88
from nose.tools import *
99

@@ -63,3 +63,63 @@ def testAddImpossibleMetadata():
6363

6464
assert_not_in( metadata_to_check, properties.getMetadatas() )
6565

66+
67+
def testCheckVideoProperties():
68+
"""
69+
Check properties of a video stream.
70+
"""
71+
# get src file
72+
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_MP4_FILE']
73+
inputFile = av.InputFile( inputFileName )
74+
properties = inputFile.getProperties()
75+
videoStream = properties.getVideoProperties()[0]
76+
77+
expectedTotalBitRate = 3249739
78+
expectedVideoBitRate = 3247981
79+
80+
expectedCodecName = 'h264'
81+
expectedWidth = 1920
82+
expectedHeight = 1080
83+
expectedNbFrames = 241
84+
expectedDuration = 10.04
85+
expectedFps = 24
86+
87+
assert_equals( properties.getBitRate(), expectedTotalBitRate )
88+
assert_equals( videoStream.getBitRate(), expectedVideoBitRate )
89+
90+
assert_equals( videoStream.getCodecName(), expectedCodecName )
91+
assert_equals( videoStream.getWidth(), expectedWidth )
92+
assert_equals( videoStream.getHeight(), expectedHeight )
93+
assert_equals( videoStream.getNbFrames(), expectedNbFrames )
94+
assert_equals( round(videoStream.getDuration(), 2), expectedDuration )
95+
assert_equals( videoStream.getFps(), expectedFps )
96+
97+
def testCheckAudioProperties():
98+
"""
99+
Check properties of an audio stream.
100+
"""
101+
# get src file
102+
inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE']
103+
inputFile = av.InputFile( inputFileName )
104+
properties = inputFile.getProperties()
105+
audioStream = properties.getAudioProperties()[0]
106+
107+
expectedTotalBitRate = 4608040
108+
expectedAudioBitRate = 4608000
109+
110+
expectedCodecName = 'pcm_s16le'
111+
expectedSamples = 5760000
112+
expectedDuration = 20
113+
expectedChannels = 6
114+
expectedChannelLayout = '5.1'
115+
expectedSampleRate = 48000
116+
117+
assert_equals( properties.getBitRate(), expectedTotalBitRate )
118+
assert_equals( audioStream.getBitRate(), expectedAudioBitRate )
119+
120+
assert_equals( audioStream.getCodecName(), expectedCodecName )
121+
assert_equals( audioStream.getNbSamples(), expectedSamples )
122+
assert_equals( round(audioStream.getDuration(), 2), expectedDuration )
123+
assert_equals( audioStream.getChannels(), expectedChannels )
124+
assert_equals( audioStream.getChannelLayout(), expectedChannelLayout )
125+
assert_equals( audioStream.getSampleRate(), expectedSampleRate )

test/pyTest/testTranscoderRewrap.py

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

33
# 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:
4+
if os.environ.get('AVTRANSCODER_TEST_AUDIO_WAVE_FILE') is None or os.environ.get('AVTRANSCODER_TEST_VIDEO_AVI_FILE') is None:
55
from nose.plugins.skip import SkipTest
6-
raise SkipTest("Need to define environment variables AVTRANSCODER_TEST_VIDEO_FILE and AVTRANSCODER_TEST_AUDIO_WAVE_FILE")
6+
raise SkipTest("Need to define environment variables AVTRANSCODER_TEST_VIDEO_AVI_FILE and AVTRANSCODER_TEST_AUDIO_WAVE_FILE")
77

88
from nose.tools import *
99

@@ -62,7 +62,7 @@ def testRewrapVideoStream():
6262
Rewrap one video stream.
6363
"""
6464
# get src file of wrap
65-
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_FILE']
65+
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE']
6666
src_inputFile = av.InputFile( inputFileName )
6767
progress = av.NoDisplayProgress()
6868
src_inputFile.analyse( progress )

test/pyTest/testTranscoderTranscodeVideo.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import os
22

33
# Check if environment is setup to run the tests
4-
if os.environ.get('AVTRANSCODER_TEST_VIDEO_FILE') is None:
4+
if os.environ.get('AVTRANSCODER_TEST_VIDEO_AVI_FILE') is None:
55
from nose.plugins.skip import SkipTest
6-
raise SkipTest("Need to define environment variable AVTRANSCODER_TEST_VIDEO_FILE")
6+
raise SkipTest("Need to define environment variable AVTRANSCODER_TEST_VIDEO_AVI_FILE")
77

88
from nose.tools import *
99

@@ -17,7 +17,7 @@ def testTranscodeDnxhd120():
1717
"""
1818
Transcode one video stream (profile dnxhd120).
1919
"""
20-
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_FILE']
20+
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE']
2121
outputFileName = "testTranscodeDnxhd120.mxf"
2222

2323
ouputFile = av.OutputFile( outputFileName )
@@ -44,7 +44,7 @@ def testTranscodeDnxhd185():
4444
"""
4545
Transcode one video stream (profile dnxhd185).
4646
"""
47-
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_FILE']
47+
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE']
4848
outputFileName = "testTranscodeDnxhd185.mxf"
4949

5050
ouputFile = av.OutputFile( outputFileName )
@@ -71,7 +71,7 @@ def testTranscodeDnxhd185x():
7171
"""
7272
Transcode one video stream (profile dnxhd185x).
7373
"""
74-
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_FILE']
74+
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE']
7575
outputFileName = "testTranscodeDnxhd185x.mxf"
7676

7777
ouputFile = av.OutputFile( outputFileName )
@@ -98,7 +98,7 @@ def testTranscodeYUV420():
9898
"""
9999
Process one video stream (custom profile of encoding, with pixel format YUV420).
100100
"""
101-
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_FILE']
101+
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE']
102102
outputFileName = "testTranscodeYUV420.avi"
103103

104104
ouputFile = av.OutputFile( outputFileName )

tools/travis.python.nosetests.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ export PYTHONPATH=${AVTRANSCODER_INSTALL}/lib/python2.7/site-packages/:$PYTHONPA
99

1010
# Get assets
1111
git clone https://github.com/avTranscoder/avTranscoder-data.git
12-
export AVTRANSCODER_TEST_VIDEO_FILE=`pwd`/avTranscoder-data/video/BigBuckBunny/BigBuckBunny_480p_stereo.avi
12+
export AVTRANSCODER_TEST_VIDEO_AVI_FILE=`pwd`/avTranscoder-data/video/BigBuckBunny/BigBuckBunny_480p_stereo.avi
13+
export AVTRANSCODER_TEST_VIDEO_MP4_FILE=`pwd`/avTranscoder-data/video/BigBuckBunny/BigBuckBunny_HD.mp4
1314
export AVTRANSCODER_TEST_AUDIO_WAVE_FILE=`pwd`/avTranscoder-data/audio/frequenciesPerChannel.wav
1415
export AVTRANSCODER_TEST_AUDIO_MOV_FILE=`pwd`/avTranscoder-data/video/BigBuckBunny/BigBuckBunny_1080p_5_1.mov
1516

0 commit comments

Comments
 (0)