From patchwork Tue Jun 9 08:48:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Fu, Linjie" X-Patchwork-Id: 20239 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 A247B449974 for ; Tue, 9 Jun 2020 11:53:22 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7BB3868B21D; Tue, 9 Jun 2020 11:53:22 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C29EA680ABA for ; Tue, 9 Jun 2020 11:53:15 +0300 (EEST) IronPort-SDR: 8D0W8nwignfGGOp7Lf1PWaddhrqk2k5c30psIC1XSBi2OtFbc7I4SuxDDidrlBzooH11YkKgQT K4V88LprQ6qA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jun 2020 01:53:11 -0700 IronPort-SDR: 4xuPLg0oknDLyN1ljBMV9urSurRPyyLpy07PY/JKLUXlOKSdiJQV8G3lGTZSlN4h2vtRW+pDPR 1FDT6z5oUS8w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,491,1583222400"; d="scan'208";a="418339545" Received: from icl-dev.sh.intel.com ([10.239.158.73]) by orsmga004.jf.intel.com with ESMTP; 09 Jun 2020 01:53:10 -0700 From: Linjie Fu To: ffmpeg-devel@ffmpeg.org Date: Tue, 9 Jun 2020 16:48:46 +0800 Message-Id: <1591692526-18839-1-git-send-email-linjie.fu@intel.com> X-Mailer: git-send-email 2.7.4 Subject: [FFmpeg-devel] [PATCH 4/5] fftools/ffmpeg: flush and recreate encoder instance if resolution changes 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" Signed-off-by: Linjie Fu --- Should be squashed with: https://patchwork.ffmpeg.org/project/ffmpeg/list/?series=1434 fftools/ffmpeg.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 5859781..8cdd532 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -130,6 +130,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; @@ -1058,11 +1059,21 @@ static void do_video_out(OutputFile *of, if (next_picture && (enc->width != next_picture->width || enc->height != next_picture->height)) { + flush_encoders(); + avcodec_flush_buffers(enc); if (!(enc->codec->capabilities & AV_CODEC_CAP_VARIABLE_DIMENSIONS)) { av_log(NULL, AV_LOG_ERROR, "Variable dimension encoding " "is not supported by %s.\n", enc->codec->name); goto error; } + + enc->width = next_picture->width; + enc->height = next_picture->height; + + if (enc->codec->close(enc) < 0) + goto error; + if (enc->codec->init(enc) < 0) + goto error; } if (ost->source_index >= 0)