Permalink
Browse files

+ Allow changing the time base in ffmpeg encoder

  • Loading branch information...
1 parent 8cec6f2 commit 436db14acd7749266516fd34664062c59bdc408b ru committed Jul 12, 2012
Showing with 18 additions and 1 deletion.
  1. +9 −1 sqmod/sqmod_ffmpeg/ff_encoder.cpp
  2. +9 −0 sqmod/sqmod_ffmpeg/ff_encoder.h
@@ -22,6 +22,8 @@ SQBIND_REGISTER_CLASS_BEGIN( CFfEncoder, CFfEncoder )
SQBIND_MEMBER_FUNCTION( CFfEncoder, calcPts )
SQBIND_MEMBER_FUNCTION( CFfEncoder, getFrame )
SQBIND_MEMBER_FUNCTION( CFfEncoder, setFrame )
+ SQBIND_MEMBER_FUNCTION( CFfEncoder, setTimeBase )
+ SQBIND_MEMBER_FUNCTION( CFfEncoder, getTimeBase )
SQBIND_REGISTER_CLASS_END()
DECLARE_INSTANCE_TYPE( CFfEncoder );
@@ -37,6 +39,7 @@ CFfEncoder::CFfEncoder()
m_nFmt = 0;
m_nFps = 0;
m_nFrame = 0;
+ m_nTimeBase = 0;
m_pCodec = oexNULL;
m_pCodecContext = oexNULL;
m_pStream = oexNULL;
@@ -114,14 +117,19 @@ int CFfEncoder::Create( int x_nCodec, int fmt, int width, int height, int fps, i
avcodec_get_context_defaults( m_pCodecContext );
+ // Get time base
+ oex::oexINT64 nTimeBase = m_nTimeBase;
+ if ( 0 >= nTimeBase )
+ nTimeBase = fps;
+
m_pCodecContext->codec_id = (CodecID)x_nCodec;
m_pCodecContext->codec_type = AVMEDIA_TYPE_VIDEO;
m_pCodecContext->bit_rate = brate;
m_pCodecContext->bit_rate_tolerance = brate / 5;
m_pCodecContext->width = width;
m_pCodecContext->height = height;
m_pCodecContext->gop_size = fps;
- m_pCodecContext->time_base.den = fps;
+ m_pCodecContext->time_base.den = nTimeBase;
m_pCodecContext->time_base.num = 1;
m_pCodecContext->me_method = 1;
m_pCodecContext->strict_std_compliance = ( ( m && m->isset( oexT( "cmp" ) ) ) ? (*m)[ oexT( "cmp" ) ].toint() : 0 );
@@ -121,6 +121,12 @@ class CFfEncoder
/// Sets the current frame number
void setFrame( SQInteger n ) { m_nFrame = n; }
+ /// Sets the time base, if zero, defaults to frame rate
+ void setTimeBase( SQInteger n ) { m_nTimeBase = n; }
+
+ /// Returns the current time base
+ SQInteger getTimeBase() { return m_nTimeBase; }
+
/** @} */
private:
@@ -131,6 +137,9 @@ class CFfEncoder
/// Frame rate
int m_nFps;
+ /// Time base, if zero, defaults to m_nFps
+ oex::oexINT64 m_nTimeBase;
+
/// Frame number
oex::oexINT64 m_nFrame;

0 comments on commit 436db14

Please sign in to comment.