From patchwork Sun Jul 28 09:54:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Fu, Linjie" X-Patchwork-Id: 14105 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 44A83447B7D for ; Sun, 28 Jul 2019 12:55:25 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2BFE568AAC3; Sun, 28 Jul 2019 12:55:25 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 223D768AAAC for ; Sun, 28 Jul 2019 12:55:17 +0300 (EEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Jul 2019 02:55:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,317,1559545200"; d="scan'208";a="178920133" Received: from icl-dev.sh.intel.com ([10.239.158.70]) by FMSMGA003.fm.intel.com with ESMTP; 28 Jul 2019 02:55:14 -0700 From: Linjie Fu To: ffmpeg-devel@ffmpeg.org Date: Sun, 28 Jul 2019 17:54:43 +0800 Message-Id: <1564307683-22194-1-git-send-email-linjie.fu@intel.com> X-Mailer: git-send-email 2.7.4 Subject: [FFmpeg-devel] [PATCH, RFC 2/2] fftools/ffmpeg: add dynamic resolution encode support for libvpx-vp9 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, vp9 should support dynamic resolution changes. Add dynamic resolution encoding support in libvpx-vp9, and flush encoders when resolution change happens. Format change should also be supported, but I didn't test it so just leave it open. cmdline: ffmpeg -noautoscale -y -i ./reinit-large_420_8-to-small_420_8.h264 -pix_fmt yuv420p -c:v libvpx-vp9 lena.ivf Signed-off-by: Linjie Fu --- fftools/ffmpeg.c | 9 +++++++++ libavcodec/libvpxenc.c | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 5d52430..e091117 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -64,6 +64,7 @@ #include "libavutil/thread.h" #include "libavutil/threadmessage.h" #include "libavcodec/mathops.h" +#include "libavcodec/internal.h" #include "libavformat/os_support.h" # include "libavfilter/avfilter.h" @@ -130,6 +131,7 @@ static void do_video_stats(OutputStream *ost, int frame_size); static BenchmarkTimeStamps get_benchmark_time_stamps(void); static int64_t getmaxrss(void); static int ifilter_has_all_input_formats(FilterGraph *fg); +static void flush_encoders(void); static int run_as_daemon = 0; static int nb_frames_dup = 0; @@ -1067,6 +1069,13 @@ static void do_video_out(OutputFile *of, InputStream *ist = NULL; AVFilterContext *filter = ost->filter->filter; + /* flush encoders in dynamic resolution encode */ + if (next_picture && (enc->width != next_picture->width || + enc->height != next_picture->height)) { + flush_encoders(); + enc->internal->draining = 0; + } + if (ost->source_index >= 0) ist = input_streams[ost->source_index]; diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c index feb52ea..54ac365 100644 --- a/libavcodec/libvpxenc.c +++ b/libavcodec/libvpxenc.c @@ -1067,6 +1067,15 @@ 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; + + avctx->codec->close(avctx); + avctx->codec->init(avctx); + } + if (frame) { rawimg = &ctx->rawimg; rawimg->planes[VPX_PLANE_Y] = frame->data[0];