From d06517dae258a3ded8cf64ebd9ee1b4d959a7eb9 Mon Sep 17 00:00:00 2001 From: zoff99 Date: Wed, 16 Aug 2023 22:20:24 +0200 Subject: [PATCH] NGC video (PoC only) tweak encoder settings for better output quality --- amalgamation/toxcore_amalgamation.c | 27 ++++++++++++++++++++++----- toxav/toxav.c | 25 +++++++++++++++++++++---- toxav/toxav.h | 2 +- 3 files changed, 44 insertions(+), 10 deletions(-) diff --git a/amalgamation/toxcore_amalgamation.c b/amalgamation/toxcore_amalgamation.c index 743f0fb6a5..d42eea0a41 100644 --- a/amalgamation/toxcore_amalgamation.c +++ b/amalgamation/toxcore_amalgamation.c @@ -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, @@ -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)); @@ -77692,6 +77692,10 @@ void* toxav_ngc_video_init(const uint16_t v_bitrate) // log warning } + //if (x264_param_default_preset(¶m, "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 @@ -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(¶m, "baseline") < 0) { // "baseline", "main", "high", "high10", "high422", "high444" + // log warning + //} - if (x264_param_apply_profile(¶m, "baseline") < 0) { // "baseline", "main", "high", "high10", "high422", "high444" + if (x264_param_apply_profile(¶m, "high") < 0) { // log warning } diff --git a/toxav/toxav.c b/toxav/toxav.c index cf05ba3511..397f60404c 100644 --- a/toxav/toxav.c +++ b/toxav/toxav.c @@ -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)); @@ -2700,6 +2700,10 @@ void* toxav_ngc_video_init(const uint16_t v_bitrate) // log warning } + //if (x264_param_default_preset(¶m, "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 @@ -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(¶m, "baseline") < 0) { // "baseline", "main", "high", "high10", "high422", "high444" + // log warning + //} - if (x264_param_apply_profile(¶m, "baseline") < 0) { // "baseline", "main", "high", "high10", "high422", "high444" + if (x264_param_apply_profile(¶m, "high") < 0) { // log warning } diff --git a/toxav/toxav.h b/toxav/toxav.h index 8cb27500a2..19bc8d4eda 100644 --- a/toxav/toxav.h +++ b/toxav/toxav.h @@ -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,