From patchwork Sun Oct 23 22:12:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Hocevar X-Patchwork-Id: 1156 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.133 with SMTP id o127csp1920936vsd; Sun, 23 Oct 2016 15:12:08 -0700 (PDT) X-Received: by 10.28.140.136 with SMTP id o130mr16878507wmd.4.1477260728103; Sun, 23 Oct 2016 15:12:08 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id y204si9072094wmg.81.2016.10.23.15.12.07; Sun, 23 Oct 2016 15:12:08 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 43CE2689C89; Mon, 24 Oct 2016 01:12:02 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtp.zoy.org (poulet.zoy.org [193.200.42.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 37004689A9D for ; Mon, 24 Oct 2016 01:11:56 +0300 (EEST) Received: by smtp.zoy.org (Postfix, from userid 1000) id CC44B360D79; Mon, 24 Oct 2016 00:12:00 +0200 (CEST) Date: Mon, 24 Oct 2016 00:12:00 +0200 From: Sam Hocevar To: FFmpeg development discussions and patches Message-ID: <20161023221200.GA18633@hocevar.net> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) Subject: [FFmpeg-devel] [PATCH] doc/examples/muxing: Fix av_frame_make_writable usage 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This patch moves the av_frame_make_writable() call from fill_yuv_image to get_video_frame so that its argument can be the actual frame that will be sent to the encoder. This fixes data corruption issues in codecs that keep references on one or several previous frames. Signed-off-by: Sam Hocevar --- doc/examples/muxing.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/doc/examples/muxing.c b/doc/examples/muxing.c index f1f5bb8..1df5912 100644 --- a/doc/examples/muxing.c +++ b/doc/examples/muxing.c @@ -440,15 +440,7 @@ static void open_video(AVFormatContext *oc, AVCodec *codec, OutputStream *ost, A static void fill_yuv_image(AVFrame *pict, int frame_index, int width, int height) { - int x, y, i, ret; - - /* when we pass a frame to the encoder, it may keep a reference to it - * internally; - * make sure we do not overwrite it here - */ - ret = av_frame_make_writable(pict); - if (ret < 0) - exit(1); + int x, y, i; i = frame_index; @@ -475,6 +467,11 @@ static AVFrame *get_video_frame(OutputStream *ost) STREAM_DURATION, (AVRational){ 1, 1 }) >= 0) return NULL; + /* when we pass a frame to the encoder, it may keep a reference to it + * internally; make sure we do not overwrite it here */ + if (av_frame_make_writable(ost->frame) < 0) + exit(1); + if (c->pix_fmt != AV_PIX_FMT_YUV420P) { /* as we only generate a YUV420P picture, we must convert it * to the codec pixel format if needed */