Skip to content

Commit 28852a7

Browse files
committed
Merge pull request mikrosimage#217 from cchampet/fix_AudioPropertiesGetNbSamples
AudioProperties: compute nbSamples if the info is unknown from ffmpeg
2 parents 3e8aebb + 8d6192e commit 28852a7

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

src/AvTranscoder/mediaProperty/AudioProperties.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,10 @@ size_t AudioProperties::getNbSamples() const
167167
{
168168
if( ! _formatContext )
169169
throw std::runtime_error( "unknown format context" );
170-
return _formatContext->streams[_streamIndex]->nb_frames;
170+
size_t nbSamples = _formatContext->streams[_streamIndex]->nb_frames;
171+
if(nbSamples == 0)
172+
nbSamples = getSampleRate() * getChannels() * getDuration();
173+
return nbSamples;
171174
}
172175

173176
size_t AudioProperties::getTicksPerFrame() const

src/AvTranscoder/mediaProperty/AudioProperties.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class AvExport AudioProperties : public StreamProperties
2626
size_t getSampleRate() const;
2727
size_t getChannels() const;
2828
size_t getBitRate() const; ///< 0 if unknown
29-
size_t getNbSamples() const; ///< 0 if unknown
29+
size_t getNbSamples() const;
3030

3131
size_t getTicksPerFrame() const;
3232

test/pyTest/testNbSamples.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,14 @@ def testNbSamplesAudioTranscode():
5050
ouputFile = av.OutputFile( outputFileName )
5151
transcoder = av.Transcoder( ouputFile )
5252

53-
transcoder.add( inputFileName, 0, "wave24b48kmono" )
53+
# create custom profile
54+
customProfile = av.ProfileMap()
55+
customProfile[av.avProfileIdentificator] = "customProfile"
56+
customProfile[av.avProfileIdentificatorHuman] = "custom profile"
57+
customProfile[av.avProfileType] = av.avProfileTypeAudio
58+
customProfile[av.avProfileCodec] = "pcm_s16le"
59+
60+
transcoder.add( inputFileName, 0, customProfile )
5461

5562
progress = av.ConsoleProgress()
5663
transcoder.process( progress )

0 commit comments

Comments
 (0)