Skip to content

Commit

Permalink
NGC video (PoC only) tweak encoder settings for better output quality
Browse files Browse the repository at this point in the history
  • Loading branch information
zoff99 committed Aug 16, 2023
1 parent 4c14494 commit d06517d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 10 deletions.
27 changes: 22 additions & 5 deletions amalgamation/toxcore_amalgamation.c
Original file line number Diff line number Diff line change
Expand Up @@ -17407,7 +17407,7 @@ bool toxav_option_set(ToxAV *av, uint32_t friend_number, TOXAV_OPTIONS_OPTION op
/**
* NGC Group Video.
*/
void* toxav_ngc_video_init(const uint16_t v_bitrate);
void* toxav_ngc_video_init(const uint16_t v_bitrate, const uint16_t max_quantizer);
void toxav_ngc_video_kill(void *vngc);
bool toxav_ngc_video_encode(void *vngc, const uint16_t vbitrate, const uint16_t width, const uint16_t height,
const uint8_t *y, const uint8_t *u, const uint8_t *v,
Expand Down Expand Up @@ -77681,7 +77681,7 @@ struct ToxAV_NGC_vcoders {
AVCodecContext *ngc__h264_decoder;
};

void* toxav_ngc_video_init(const uint16_t v_bitrate)
void* toxav_ngc_video_init(const uint16_t v_bitrate, const uint16_t max_quantizer)
{
struct ToxAV_NGC_vcoders *ngc_video_coders = calloc(1, sizeof(struct ToxAV_NGC_vcoders));

Expand All @@ -77692,6 +77692,10 @@ void* toxav_ngc_video_init(const uint16_t v_bitrate)
// log warning
}

//if (x264_param_default_preset(&param, "superfast", "zerolatency,fastdecode") < 0) {
// // log warning
//}

#define NGC__H264_DECODER_THREADS 4
#define NGC__H264_DECODER_THREAD_FRAME_ACTIVE 1
#define NGC__X264_ENCODER_THREADS 4
Expand Down Expand Up @@ -77735,16 +77739,29 @@ void* toxav_ngc_video_init(const uint16_t v_bitrate)
param.rc.i_vbv_max_bitrate = NGC__VIDEO_BITRATE_INITIAL_VALUE_H264 * 1;

param.rc.i_qp_min = 3;
param.rc.i_qp_max = 51; // max quantizer for x264

// max quantizer for x264
if ((max_quantizer < 30) || (max_quantizer > 51))
{
param.rc.i_qp_max = 49;
}
else
{
param.rc.i_qp_max = max_quantizer;
}

ngc_video_coders->ngc__v_encoder_bitrate = NGC__VIDEO_BITRATE_INITIAL_VALUE_H264 * 1000;

param.rc.b_stat_read = 0;
param.rc.b_stat_write = 0;

param.i_log_level = X264_LOG_ERROR; // X264_LOG_NONE;
param.i_log_level = X264_LOG_NONE; // X264_LOG_ERROR; // X264_LOG_NONE;

//if (x264_param_apply_profile(&param, "baseline") < 0) { // "baseline", "main", "high", "high10", "high422", "high444"
// log warning
//}

if (x264_param_apply_profile(&param, "baseline") < 0) { // "baseline", "main", "high", "high10", "high422", "high444"
if (x264_param_apply_profile(&param, "high") < 0) {
// log warning
}

Expand Down
25 changes: 21 additions & 4 deletions toxav/toxav.c
Original file line number Diff line number Diff line change
Expand Up @@ -2689,7 +2689,7 @@ struct ToxAV_NGC_vcoders {
AVCodecContext *ngc__h264_decoder;
};

void* toxav_ngc_video_init(const uint16_t v_bitrate)
void* toxav_ngc_video_init(const uint16_t v_bitrate, const uint16_t max_quantizer)
{
struct ToxAV_NGC_vcoders *ngc_video_coders = calloc(1, sizeof(struct ToxAV_NGC_vcoders));

Expand All @@ -2700,6 +2700,10 @@ void* toxav_ngc_video_init(const uint16_t v_bitrate)
// log warning
}

//if (x264_param_default_preset(&param, "superfast", "zerolatency,fastdecode") < 0) {
// // log warning
//}

#define NGC__H264_DECODER_THREADS 4
#define NGC__H264_DECODER_THREAD_FRAME_ACTIVE 1
#define NGC__X264_ENCODER_THREADS 4
Expand Down Expand Up @@ -2743,16 +2747,29 @@ void* toxav_ngc_video_init(const uint16_t v_bitrate)
param.rc.i_vbv_max_bitrate = NGC__VIDEO_BITRATE_INITIAL_VALUE_H264 * 1;

param.rc.i_qp_min = 3;
param.rc.i_qp_max = 51; // max quantizer for x264

// max quantizer for x264
if ((max_quantizer < 30) || (max_quantizer > 51))
{
param.rc.i_qp_max = 49;
}
else
{
param.rc.i_qp_max = max_quantizer;
}

ngc_video_coders->ngc__v_encoder_bitrate = NGC__VIDEO_BITRATE_INITIAL_VALUE_H264 * 1000;

param.rc.b_stat_read = 0;
param.rc.b_stat_write = 0;

param.i_log_level = X264_LOG_ERROR; // X264_LOG_NONE;
param.i_log_level = X264_LOG_NONE; // X264_LOG_ERROR; // X264_LOG_NONE;

//if (x264_param_apply_profile(&param, "baseline") < 0) { // "baseline", "main", "high", "high10", "high422", "high444"
// log warning
//}

if (x264_param_apply_profile(&param, "baseline") < 0) { // "baseline", "main", "high", "high10", "high422", "high444"
if (x264_param_apply_profile(&param, "high") < 0) {
// log warning
}

Expand Down
2 changes: 1 addition & 1 deletion toxav/toxav.h
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ bool toxav_option_set(ToxAV *av, uint32_t friend_number, TOXAV_OPTIONS_OPTION op
/**
* NGC Group Video.
*/
void* toxav_ngc_video_init(const uint16_t v_bitrate);
void* toxav_ngc_video_init(const uint16_t v_bitrate, const uint16_t max_quantizer);
void toxav_ngc_video_kill(void *vngc);
bool toxav_ngc_video_encode(void *vngc, const uint16_t vbitrate, const uint16_t width, const uint16_t height,
const uint8_t *y, const uint8_t *u, const uint8_t *v,
Expand Down

0 comments on commit d06517d

Please sign in to comment.