Skip to content

Commit b962588

Browse files
author
Clement Champetier
committed
Video profiles do not need inevitably the frame rate
* Keep the frame rate of the input. * Add fps attribute in VideoFrameDesc.
1 parent dc660b6 commit b962588

File tree

5 files changed

+23
-31
lines changed

5 files changed

+23
-31
lines changed

src/AvTranscoder/ProfileLoader.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,7 @@ bool ProfileLoader::checkVideoProfile( const Profile& profileToCheck )
187187
if( ! profileToCheck.count( constants::avProfileIdentificator ) ||
188188
! profileToCheck.count( constants::avProfileIdentificatorHuman ) ||
189189
! profileToCheck.count( constants::avProfileType ) ||
190-
! profileToCheck.count( constants::avProfileCodec ) ||
191-
! profileToCheck.count( constants::avProfileFrameRate ) )
190+
! profileToCheck.count( constants::avProfileCodec ) )
192191
{
193192
isValid = false;
194193
}

src/AvTranscoder/codec/VideoCodec.cpp

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,20 @@ VideoFrameDesc VideoCodec::getVideoFrameDesc() const
2424
{
2525
assert( _avCodecContext != NULL );
2626
VideoFrameDesc videoFrameDesc( _avCodecContext->width, _avCodecContext->height, _avCodecContext->pix_fmt );
27+
double fps = 1.0 * _avCodecContext->time_base.den / ( _avCodecContext->time_base.num * _avCodecContext->ticks_per_frame );
28+
if( ! isinf( fps ) )
29+
videoFrameDesc.setFps( fps );
2730
return videoFrameDesc;
2831
}
2932

30-
std::pair< size_t, size_t > VideoCodec::getTimeBase() const
31-
{
32-
assert( _avCodecContext != NULL );
33-
std::pair< size_t, size_t > timeBase;
34-
timeBase.first = _avCodecContext->time_base.num;
35-
timeBase.second = _avCodecContext->time_base.den;
36-
return timeBase;
37-
}
38-
3933
void VideoCodec::setImageParameters( const VideoFrameDesc& videoFrameDesc )
4034
{
4135
_avCodecContext->width = videoFrameDesc.getWidth();
4236
_avCodecContext->height = videoFrameDesc.getHeight();
4337
_avCodecContext->pix_fmt = videoFrameDesc.getPixelFormat();
44-
}
45-
46-
void VideoCodec::setTimeBase( const size_t num, const size_t den, const size_t ticksPerFrame )
47-
{
48-
_avCodecContext->time_base.num = num;
49-
_avCodecContext->time_base.den = den;
50-
_avCodecContext->ticks_per_frame = ticksPerFrame;
38+
_avCodecContext->time_base.num = 1;
39+
_avCodecContext->time_base.den = videoFrameDesc.getFps();
40+
_avCodecContext->ticks_per_frame = 1;
5141
}
5242

5343
}

src/AvTranscoder/codec/VideoCodec.hpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
#include "ICodec.hpp"
55
#include <AvTranscoder/frame/VideoFrame.hpp>
66

7-
#include <utility>
8-
97
namespace avtranscoder
108
{
119

@@ -15,13 +13,10 @@ class AvExport VideoCodec : public ICodec
1513
VideoCodec( const ECodecType type, const std::string& codecName = "" );
1614
VideoCodec( const ECodecType type, const AVCodecID codecId );
1715
VideoCodec( const ECodecType type, AVCodecContext& avCodecContext );
18-
16+
1917
VideoFrameDesc getVideoFrameDesc() const;
20-
std::pair< size_t, size_t > getTimeBase() const;
21-
22-
void setImageParameters( const VideoFrameDesc& videoFrameDesc );
2318

24-
void setTimeBase( const size_t num, const size_t den, const size_t ticksPerFrame = 1 );
19+
void setImageParameters( const VideoFrameDesc& videoFrameDesc );
2520
};
2621

2722
}

src/AvTranscoder/encoder/VideoEncoder.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,10 @@ bool VideoEncoder::encodeFrame( Frame& codedFrame )
130130

131131
void VideoEncoder::setProfile( const ProfileLoader::Profile& profile, const avtranscoder::VideoFrameDesc& frameDesc )
132132
{
133-
const size_t frameRate = std::strtoul( profile.find( constants::avProfileFrameRate )->second.c_str(), NULL, 0 );
134-
_codec.setTimeBase( 1, frameRate );
135-
133+
// set width, height, pixel format, fps
136134
_codec.setImageParameters( frameDesc );
137-
135+
136+
// set encoder options
138137
for( ProfileLoader::Profile::const_iterator it = profile.begin(); it != profile.end(); ++it )
139138
{
140139
if( (*it).first == constants::avProfileIdentificator ||

src/AvTranscoder/frame/VideoFrame.hpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
#include <AvTranscoder/ProfileLoader.hpp>
66

77
extern "C" {
8-
#include <libavutil/rational.h>
98
#include <libavutil/pixfmt.h>
109
#include <libavutil/pixdesc.h>
1110
}
1211

1312
#include <stdexcept>
13+
#include <stdlib.h>
1414

1515
namespace avtranscoder
1616
{
@@ -22,12 +22,14 @@ class AvExport VideoFrameDesc
2222
: _width( width )
2323
, _height( height )
2424
, _pixelFormat( pixelFormat )
25+
, _fps( 1.0 )
2526
{
2627
}
2728
VideoFrameDesc( const size_t width, const size_t height, const std::string& pixelFormat )
2829
: _width( width )
2930
, _height( height )
3031
, _pixelFormat( av_get_pix_fmt( pixelFormat.c_str() ) )
32+
, _fps( 1.0 )
3133
{
3234
}
3335

@@ -39,6 +41,7 @@ class AvExport VideoFrameDesc
3941
const char* formatName = av_get_pix_fmt_name( _pixelFormat );
4042
return formatName ? std::string( formatName ) : "unknown pixel format";
4143
}
44+
double getFps() const { return _fps; }
4245

4346
size_t getDataSize() const
4447
{
@@ -56,17 +59,23 @@ class AvExport VideoFrameDesc
5659
void setHeight( const size_t height ) { _height = height; }
5760
void setPixelFormat( const std::string& pixelFormat ) { _pixelFormat = av_get_pix_fmt( pixelFormat.c_str() ); }
5861
void setPixelFormat( const AVPixelFormat pixelFormat ) { _pixelFormat = pixelFormat; }
62+
void setFps( const double fps ) { _fps = fps; }
5963

6064
void setParameters( const ProfileLoader::Profile& profile )
6165
{
62-
if( profile.find( constants::avProfilePixelFormat ) != profile.end() )
66+
// pixel format
67+
if( profile.count( constants::avProfilePixelFormat ) )
6368
setPixelFormat( profile.find( constants::avProfilePixelFormat )->second );
69+
// fps
70+
if( profile.count( constants::avProfileFrameRate ) )
71+
setFps( atof( profile.find( constants::avProfileFrameRate )->second.c_str() ) );
6472
}
6573

6674
private:
6775
size_t _width;
6876
size_t _height;
6977
AVPixelFormat _pixelFormat;
78+
double _fps;
7079
};
7180

7281
//template< template<typename> Alloc >

0 commit comments

Comments
 (0)