From patchwork Tue Aug 13 09:29:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Fu, Linjie" X-Patchwork-Id: 14481 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id C70E7448F86 for ; Tue, 13 Aug 2019 12:30:05 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A1F4968AB2F; Tue, 13 Aug 2019 12:30:05 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C95FF68A35D for ; Tue, 13 Aug 2019 12:29:58 +0300 (EEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Aug 2019 02:29:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,381,1559545200"; d="scan'208";a="205024674" Received: from icl-dev.sh.intel.com ([10.239.158.73]) by fmsmga002.fm.intel.com with ESMTP; 13 Aug 2019 02:29:55 -0700 From: Linjie Fu To: ffmpeg-devel@ffmpeg.org Date: Tue, 13 Aug 2019 17:29:04 +0800 Message-Id: <1565688544-9043-1-git-send-email-linjie.fu@intel.com> X-Mailer: git-send-email 2.7.4 Subject: [FFmpeg-devel] [PATCH, RFC, v2 3/3] lavc/libvpxenc: add dynamic resolution encode support for libvpx X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Linjie Fu MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" According to spec, libvpx should support dynamic resolution changes. Add dynamic resolution encoding support in libvpx. Only single pass mode with no look ahead is supported for variable resolution encoding without initialization. cmdline: ffmpeg -noautoscale -y -i ./reinit-large_420_8-to-small_420_8.h264 -pix_fmt yuv420p -c:v libvpx-vp9 lena.ivf Filed an issue in https://bugs.chromium.org/p/webm/issues/detail?id=1642 to fix some memory problem. Signed-off-by: Linjie Fu --- libavcodec/libvpxenc.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c index feb52ea..3d2295d 100644 --- a/libavcodec/libvpxenc.c +++ b/libavcodec/libvpxenc.c @@ -1067,6 +1067,28 @@ static int vpx_encode(AVCodecContext *avctx, AVPacket *pkt, int res, coded_size; vpx_enc_frame_flags_t flags = 0; + if (frame && (avctx->width != frame->width || + avctx->height != frame->height)) { + avctx->width = frame->width; + avctx->height = frame->height; + + struct vpx_codec_enc_cfg new_cfg = { 0 }; + memcpy(&new_cfg, ctx->encoder.config.enc, + sizeof(struct vpx_codec_enc_cfg)); + + new_cfg.g_w = frame->width; + new_cfg.g_h = frame->height; + if (new_cfg.g_lag_in_frames > 1 || + new_cfg.g_pass != VPX_RC_ONE_PASS) { + av_log(avctx, AV_LOG_WARNING, "Only single pass mode " + "with no look ahead is supported for variable " + "resolution encoding without initialization.\n"); + new_cfg.g_pass = VPX_RC_ONE_PASS; + new_cfg.g_lag_in_frames = 0; + } + vpx_codec_enc_config_set(&ctx->encoder, &new_cfg); + } + if (frame) { rawimg = &ctx->rawimg; rawimg->planes[VPX_PLANE_Y] = frame->data[0]; @@ -1075,6 +1097,8 @@ static int vpx_encode(AVCodecContext *avctx, AVPacket *pkt, rawimg->stride[VPX_PLANE_Y] = frame->linesize[0]; rawimg->stride[VPX_PLANE_U] = frame->linesize[1]; rawimg->stride[VPX_PLANE_V] = frame->linesize[2]; + rawimg->d_w = frame->width; + rawimg->d_h = frame->height; if (ctx->is_alpha) { uint8_t *u_plane, *v_plane; rawimg_alpha = &ctx->rawimg_alpha;