Skip to content

Commit dde24db

Browse files
Clement Champetiervalnoel
authored andcommitted
AudioProperties: get bitRate from ffmpeg if available
If not, compute bitRate like before.
1 parent 26a998f commit dde24db

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/AvTranscoder/mediaProperty/AudioProperties.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,14 @@ size_t AudioProperties::getBitRate() const
157157
{
158158
if( ! _codecContext )
159159
throw std::runtime_error( "unknown codec context" );
160-
int bitsPerSample = av_get_bits_per_sample( _codecContext->codec_id );
161-
size_t bitRate = bitsPerSample ? _codecContext->sample_rate * _codecContext->channels * bitsPerSample : _codecContext->bit_rate;
162-
return bitRate;
160+
161+
// return bit rate of stream
162+
if( _codecContext->bit_rate )
163+
return _codecContext->bit_rate;
164+
165+
// else get computed bit rate from our computation (warning: way to compute bit rate of PCM audio data)
166+
int bitsPerSample = av_get_bits_per_sample( _codecContext->codec_id ); // 0 if unknown for the given codec
167+
return _codecContext->sample_rate * _codecContext->channels * bitsPerSample;
163168
}
164169

165170
size_t AudioProperties::getNbSamples() const

src/AvTranscoder/mediaProperty/AudioProperties.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ class AvExport AudioProperties
2828
size_t getCodecId() const;
2929
size_t getSampleRate() const;
3030
size_t getChannels() const;
31-
size_t getBitRate() const;
32-
size_t getNbSamples() const;
31+
size_t getBitRate() const; ///< 0 if unknown
32+
size_t getNbSamples() const; ///< 0 if unknown
3333

3434
size_t getTicksPerFrame() const;
3535
Rational getTimeBase() const;

0 commit comments

Comments
 (0)