Skip to content

Commit 8c2c666

Browse files
author
Clement Champetier
committed
AudioFrameDesc: add fps attribute
* AudioFrameDesc is the description of a number of samples, which corresponds to one video frame. * By default at 25 fps.
1 parent fc98187 commit 8c2c666

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

src/AvTranscoder/codec/AudioCodec.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ AudioFrameDesc AudioCodec::getAudioFrameDesc() const
2424
{
2525
assert( _avCodecContext != NULL );
2626
AudioFrameDesc audioFrameDesc( _avCodecContext->sample_rate, _avCodecContext->channels, _avCodecContext->sample_fmt );
27-
// audioFrameDesc.setFps( 25 );
27+
double fps = 1.0 * _avCodecContext->time_base.den / ( _avCodecContext->time_base.num * _avCodecContext->ticks_per_frame );
28+
if( ! isinf( fps ) )
29+
audioFrameDesc.setFps( fps );
2830
return audioFrameDesc;
2931
}
3032

@@ -33,6 +35,9 @@ void AudioCodec::setAudioParameters( const AudioFrameDesc& audioFrameDesc )
3335
_avCodecContext->sample_rate = audioFrameDesc.getSampleRate();
3436
_avCodecContext->channels = audioFrameDesc.getChannels();
3537
_avCodecContext->sample_fmt = audioFrameDesc.getSampleFormat();
38+
_avCodecContext->time_base.num = 1;
39+
_avCodecContext->time_base.den = audioFrameDesc.getFps();
40+
_avCodecContext->ticks_per_frame = 1;
3641
}
3742

3843
}

src/AvTranscoder/decoder/AudioGenerator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ bool AudioGenerator::decodeNextFrame( Frame& frameBuffer )
2424
if( ! _inputFrame )
2525
{
2626
AudioFrame& audioFrameBuffer = static_cast<AudioFrame&>( frameBuffer );
27-
audioFrameBuffer.setNbSamples( 1.0 * _frameDesc.getSampleRate() / 25. );
27+
audioFrameBuffer.setNbSamples( 1.0 * _frameDesc.getSampleRate() / _frameDesc.getFps() );
2828

2929
//av_samples_set_silence( data.getPtr(), offset, nb_samples, nb_channels, sample_fmt );
3030
int fill_char = (

src/AvTranscoder/frame/AudioFrame.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,21 @@ extern "C" {
1313
namespace avtranscoder
1414
{
1515

16+
/// @brief Description of a number of samples, which corresponds to one video frame
1617
class AvExport AudioFrameDesc
1718
{
1819
public:
1920
AudioFrameDesc( const size_t sampleRate = 0, const size_t channels = 0, const AVSampleFormat sampleFormat = AV_SAMPLE_FMT_NONE )
2021
: _sampleRate( sampleRate )
2122
, _channels( channels )
2223
, _sampleFormat( sampleFormat )
24+
, _fps( 25. )
2325
{}
2426
AudioFrameDesc( const size_t sampleRate, const size_t channels, const std::string& sampleFormat )
2527
: _sampleRate( sampleRate )
2628
, _channels( channels )
2729
, _sampleFormat( av_get_sample_fmt( sampleFormat.c_str() ) )
30+
, _fps( 25. )
2831
{}
2932

3033
size_t getSampleRate() const { return _sampleRate; }
@@ -35,6 +38,7 @@ class AvExport AudioFrameDesc
3538
const char* formatName = av_get_sample_fmt_name( _sampleFormat );
3639
return formatName ? std::string( formatName ) : "unknown sample format";
3740
}
41+
double getFps() const { return _fps; }
3842

3943
size_t getDataSize() const
4044
{
@@ -52,6 +56,7 @@ class AvExport AudioFrameDesc
5256
void setChannels( const size_t channels ) { _channels = channels; }
5357
void setSampleFormat( const std::string& sampleFormatName ) { _sampleFormat = av_get_sample_fmt( sampleFormatName.c_str() ); }
5458
void setSampleFormat( const AVSampleFormat sampleFormat ) { _sampleFormat = sampleFormat; }
59+
void setFps( const double fps ) { _fps = fps; }
5560

5661
void setParameters( const ProfileLoader::Profile& profile )
5762
{
@@ -63,6 +68,7 @@ class AvExport AudioFrameDesc
6368
size_t _sampleRate;
6469
size_t _channels;
6570
AVSampleFormat _sampleFormat;
71+
double _fps;
6672
};
6773

6874
class AvExport AudioFrame : public Frame

0 commit comments

Comments
 (0)