Skip to content

Commit

Permalink
auto set ticks per second for non-standard frame rates (fixes #252) (#…
Browse files Browse the repository at this point in the history
…255)

* fixes #252
auto set ticks per second for non-standard frame rates

* using error instead of warning for wrong ticks/sec
  • Loading branch information
lehmann-c committed Mar 15, 2023
1 parent 2cdefe3 commit 9553a66
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/vvenc/vvencCfg.h
Expand Up @@ -88,6 +88,7 @@ typedef void (*vvencLoggingCallback)(void*, int, const char*, va_list);
#define VVENC_DEFAULT_QP 32 // default base QP
#define VVENC_AUTO_QP -1 // indicates to use default QP, or ignore if RC is used
#define VVENC_RC_OFF 0 // indicates rate control is disabled
#define VVENC_TICKS_PER_SEC_DEF 27000000 // default ticks per second

// ====================================================================================================================

Expand Down
30 changes: 27 additions & 3 deletions source/Lib/vvenc/vvencCfg.cpp
Expand Up @@ -55,6 +55,7 @@ POSSIBILITY OF SUCH DAMAGE.

#include <math.h>
#include <thread>
#include <iomanip>

#include "apputils/VVEncAppCfg.h"

Expand Down Expand Up @@ -331,7 +332,7 @@ VVENC_DECL void vvenc_config_default(vvenc_config *c )
c->m_SourceHeight = 0; ///< source height in pixel (when interlaced = field height)
c->m_FrameRate = 0; ///< source frame-rates (Hz) Numerator
c->m_FrameScale = 1; ///< source frame-rates (Hz) Denominator
c->m_TicksPerSecond = 27000000; ///< ticks per second for dts generation (default: 27000000, 1..27000000, -1: ticks per frame=1)
c->m_TicksPerSecond = VVENC_TICKS_PER_SEC_DEF; ///< ticks per second for dts generation (default: 27000000, 1..27000000, -1: ticks per frame=1)

c->m_framesToBeEncoded = 0; ///< number of encoded frames

Expand Down Expand Up @@ -705,7 +706,30 @@ VVENC_DECL bool vvenc_init_config_parameter( vvenc_config *c )
vvenc_confirmParameter( c, c->m_FrameRate <= 0, "Frame rate must be greater than 0" );
vvenc_confirmParameter( c, c->m_FrameScale <= 0, "Frame scale must be greater than 0" );
vvenc_confirmParameter( c, c->m_TicksPerSecond < -1 || c->m_TicksPerSecond == 0 || c->m_TicksPerSecond > 27000000, "TicksPerSecond must be in range from 1 to 27000000, or -1 for ticks per frame=1" );
vvenc_confirmParameter( c, ( c->m_TicksPerSecond > 0 ) && ((int64_t)c->m_TicksPerSecond*(int64_t)c->m_FrameScale)%c->m_FrameRate, "TicksPerSecond should be a multiple of FrameRate/Framescale. Use 27000000 for NTSC content" );

std::stringstream css;
if ( c->m_FrameScale != 1 && c->m_FrameScale != 1001 && c->m_TicksPerSecond == VVENC_TICKS_PER_SEC_DEF )
{
double dFrameRate = c->m_FrameRate/(double)c->m_FrameScale;
css << "Detected non-standard Frame Rate " << c->m_FrameRate << "/" << c->m_FrameScale;
css << " (" << std::fixed << std:: setprecision(2) << dFrameRate << std::setprecision(-1) << " Hz).";
css << " Default TicksPerSecond (" << VVENC_TICKS_PER_SEC_DEF << ") can not be used.";

if ( c->m_FrameRate * c->m_FrameScale <= VVENC_TICKS_PER_SEC_DEF )
{
css << " possible TicksPerSecond: " << (c->m_FrameRate * c->m_FrameScale) << std::endl;
}
else
{
css << " cannot find a proper value for TicksPerSecond in the range (1-" << VVENC_TICKS_PER_SEC_DEF << ")" << std::endl;
}
}
else
{
css << "TicksPerSecond must be a multiple of FrameRate/Framescale (" << c->m_FrameRate << "/" << c->m_FrameScale << "). Use 27000000 for NTSC content" << std::endl;
}
vvenc_confirmParameter( c, ( c->m_TicksPerSecond > 0 ) && ((int64_t)c->m_TicksPerSecond*(int64_t)c->m_FrameScale)%c->m_FrameRate, css.str().c_str() );


vvenc_confirmParameter( c, c->m_numThreads < -1 || c->m_numThreads > 256, "Number of threads out of range (-1 <= t <= 256)");

Expand Down Expand Up @@ -2256,7 +2280,7 @@ VVENC_DECL int vvenc_init_default( vvenc_config *c, int width, int height, int f
default: break;
}

c->m_TicksPerSecond = 27000000; // ticks per second for dts generation
c->m_TicksPerSecond = VVENC_TICKS_PER_SEC_DEF; // ticks per second for dts generation

c->m_inputBitDepth[0] = 8; // input bitdepth
c->m_internalBitDepth[0] = 10; // internal bitdepth
Expand Down

0 comments on commit 9553a66

Please sign in to comment.