From: Marco Paniconi Date: Tue, 15 May 2018 05:56:15 +0000 (-0700) Subject: vp9-svc: Enable scene detection and re-encode for SVC. X-Git-Tag: v1.8.0~676 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bf7ee0524c98187166be7ab011613f28a90fa0e3;p=libvpx vp9-svc: Enable scene detection and re-encode for SVC. Keep a lower rate threshold for video case. Also lower the exiting threshold somewhat for screen-content mode. Change-Id: I79649a36678d802fd4d4080754fd366e78904214 --- diff --git a/vp9/encoder/vp9_encoder.c b/vp9/encoder/vp9_encoder.c index 95bf4622f..e41768a8f 100644 --- a/vp9/encoder/vp9_encoder.c +++ b/vp9/encoder/vp9_encoder.c @@ -3724,7 +3724,7 @@ static void encode_without_recode_loop(VP9_COMP *cpi, size_t *size, if (cm->show_frame && cpi->oxcf.mode == REALTIME && (cpi->oxcf.rc_mode == VPX_VBR || cpi->oxcf.content == VP9E_CONTENT_SCREEN || - (cpi->oxcf.speed >= 5 && cpi->oxcf.speed < 8 && !cpi->use_svc))) + (cpi->oxcf.speed >= 5 && cpi->oxcf.speed < 8))) vp9_scene_detection_onepass(cpi); if (cpi->svc.spatial_layer_id == 0) diff --git a/vp9/encoder/vp9_ratectrl.c b/vp9/encoder/vp9_ratectrl.c index 599337f80..c349a807a 100644 --- a/vp9/encoder/vp9_ratectrl.c +++ b/vp9/encoder/vp9_ratectrl.c @@ -2426,6 +2426,19 @@ void vp9_scene_detection_onepass(VP9_COMP *cpi) { if (cm->frame_type != KEY_FRAME && rc->reset_high_source_sad) rc->this_frame_target = rc->avg_frame_bandwidth; } + // For SVC the new (updated) avg_source_sad[0] for the current superframe + // updates the setting for all layers. + if (cpi->use_svc) { + int sl, tl; + SVC *const svc = &cpi->svc; + for (sl = 0; sl < svc->number_spatial_layers; ++sl) + for (tl = 0; tl < svc->number_temporal_layers; ++tl) { + int layer = LAYER_IDS_TO_IDX(sl, tl, svc->number_temporal_layers); + LAYER_CONTEXT *const lc = &svc->layer_context[layer]; + RATE_CONTROL *const lrc = &lc->rc; + lrc->avg_source_sad[0] = rc->avg_source_sad[0]; + } + } // For VBR, under scene change/high content change, force golden refresh. if (cpi->oxcf.rc_mode == VPX_VBR && cm->frame_type != KEY_FRAME && rc->high_source_sad && rc->frames_to_key > 3 && @@ -2460,7 +2473,10 @@ int vp9_encodedframe_overshoot(VP9_COMP *cpi, int frame_size, int *q) { VP9_COMMON *const cm = &cpi->common; RATE_CONTROL *const rc = &cpi->rc; int thresh_qp = 3 * (rc->worst_quality >> 2); - int thresh_rate = rc->avg_frame_bandwidth * 10; + int thresh_rate = rc->avg_frame_bandwidth << 3; + // Lower rate threshold for video. + if (cpi->oxcf.content != VP9E_CONTENT_SCREEN) + thresh_rate = rc->avg_frame_bandwidth << 2; if (cm->base_qindex < thresh_qp && frame_size > thresh_rate) { double rate_correction_factor = cpi->rc.rate_correction_factors[INTER_NORMAL]; diff --git a/vp9/encoder/vp9_speed_features.c b/vp9/encoder/vp9_speed_features.c index 8f1ec2155..d2842697d 100644 --- a/vp9/encoder/vp9_speed_features.c +++ b/vp9/encoder/vp9_speed_features.c @@ -539,7 +539,7 @@ static void set_rt_speed_feature_framesize_independent( if (cpi->use_svc && cpi->svc.spatial_layer_id > 0) sf->nonrd_keyframe = 1; if (cpi->oxcf.pass == 0 && cpi->oxcf.rc_mode == VPX_CBR && cm->frame_type != KEY_FRAME && cpi->resize_state == ORIG && - cpi->oxcf.content == VP9E_CONTENT_SCREEN) { + (cpi->use_svc || cpi->oxcf.content == VP9E_CONTENT_SCREEN)) { sf->re_encode_overshoot_rt = 1; } if (cpi->oxcf.rc_mode == VPX_VBR && cpi->oxcf.lag_in_frames > 0 &&