From patchwork Sun Aug 2 02:22:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: 453647684 <453647684@qq.com> X-Patchwork-Id: 21443 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 9AB9144B2D2 for ; Sun, 2 Aug 2020 05:23:06 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 78F1D68BAF3; Sun, 2 Aug 2020 05:23:06 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from qq.com (out203-205-251-113.mail.qq.com [203.205.251.113]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DC4A268BAF3 for ; Sun, 2 Aug 2020 05:22:58 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1596334973; bh=xe2l+IPYtaoov2HSEB2qjZEEG1O56dFNmq767H0waoM=; h=From:To:Cc:Subject:Date; b=oUYuJE9zwlTDXBJVOTNr0eS9gnU3rDX0EbVRmPsoaekiVFYJrjGO6CUApzVBOhZ1V E4naOTUN8WXmKiDsB/4rnqdW0GkAS47Ar55QSLtuw06g376DDtMhKQBEPCsjokpEk/ vsez2sysYYH3wXZuOkkzbsiacduRyKVfby4bqwzs= Received: from localhost.localdomain ([119.4.240.125]) by newxmesmtplogicsvrsza7.qq.com (NewEsmtp) with SMTP id 5B21F494; Sun, 02 Aug 2020 10:22:50 +0800 X-QQ-mid: xmsmtpt1596334970tn6usfww2 Message-ID: X-QQ-XMAILINFO: OUSM5EbZgfmrhbkirEFhnEtU3wSygGS9CfxgViOh4D8iTx/2vpiu7dQnehZzy6 3eVrUxe8/2M8++Gpm4OxiqKXc3Ecc7v2+DrIEst2MRLarTn18tvvDKfEsxI5vp0NdIvOO8CONpsD TTEt3ZFGf5vqRajvDTTmVIKrl+vlliP5MxWhRNHRgbK9JnznTu2XZ5GY2cP31+Jb68HWDphqtTM+ 73I4Gh9jOPbBd8xZDnq2aykg9B2N2nIC7OMQDXWshR3d0++FA1T9gpUV2SCLO+nfpp+8M2QRavl6 n31XKE+pRv/zarFeXk2DTbZDroU1tN2NMHvrVnqeGBTD9jGyrdQYHSsXJcxvVeieWTmsVWl+aAOb +8xeq8nuTLx4qv8ORV1FvNbapfGAyKn8RlYQ8wVdBzBWZyR4Z/cdxYXDXv/Wad1SxgfCo+JiJs3c eyfDQlpYNOCTZpAhBE7SF9hXz3k937UBRVJX2O5OTXkme8FPzuuuE4LKfv02/ztCmtQRbzqzY3tq OdHHsDVIZAUDQIuIkQNdcRzByhEi/qAPFLjfss+dTCGvAZMYv1aHO0fAUBp8X6PoyCgZIHp3y2N7 vI58y6sHKES2bFudrE1q4eGh7UmGxZEEioKbk6U7PP/mNrhuMb3UKGZhRB5NcnbHLR0qnK9I70p3 uFG2UOBtppvq2lMjkLNmBlnJvs3gsZPUXrVE1y8aW3Hkxl6h/SqvDzVZgA7JtSSLSAwSo5Z+CG5b uPopoCd+esDFnTN6DriihE1m1UlZYNuMGm+jWaGnh3S8Q= X-QQ-SPAM: true From: 453647684 <453647684@qq.com> To: ffmpeg-devel@ffmpeg.org Date: Sun, 2 Aug 2020 10:22:31 +0800 X-OQ-MSGID: <20200802022231.10571-1-453647684@qq.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4] Title:Fix buffer data lost bug. 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: 453647684 <453647684@qq.com> Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Description: At arm architechture of Linux system, use ffmpeg to record the screen. command: ffmpeg -video_size 1920x1080 -framerate 30 -thread_queue_size 512 -f x11grab -i :0+0,0 -c:v libx264 -pix_fmt yuv420p -crf 1 -vf 'scale=trunc(iw/2)*2:trunc(ih/2)*2' out.mp4 The last few seconds of the recorded video to be lost. RootCause:After quit, the data in the buffer(thread_queue_size) is not processed. Solution:After Processing the buffer data, the program really exits. --- fftools/ffmpeg.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 2e9448ea2b..9e294d3cab 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -138,6 +138,7 @@ static int nb_frames_drop = 0; static int64_t decode_error_stat[2]; static int want_sdp = 1; +static int ready_quit = 0; static BenchmarkTimeStamps current_time; AVIOContext *progress_avio = NULL; @@ -4615,8 +4616,12 @@ static int transcode_step(void) return 0; } - if (ret < 0) + if (ret < 0){ + if(ready_quit){ + return ret; + } return ret == AVERROR_EOF ? 0 : ret; + } return reap_filters(0); } @@ -4653,8 +4658,10 @@ static int transcode(void) /* if 'q' pressed, exits */ if (stdin_interaction) - if (check_keyboard_interaction(cur_time) < 0) + if (check_keyboard_interaction(cur_time) < 0){ + ready_quit = 1; break; + } /* check if there's any stream where output is still needed */ if (!need_output()) { @@ -4671,6 +4678,26 @@ static int transcode(void) /* dump report by using the output first video and audio streams */ print_report(0, timer_start, cur_time); } + +#if HAVE_THREADS + if(ready_quit){ + int flag = 0; + for (i = 0; i < nb_input_files; i++){ + InputFile *f = input_files[i]; + if (!f || !f->in_thread_queue){ + continue; + } + flag = 1; + av_thread_message_queue_set_err_send(f->in_thread_queue, AVERROR_EOF); + } + while(flag){ + ret = transcode_step(); + if (ret < 0 && ret == AVERROR_EOF) { + break; + } + } + } +#endif #if HAVE_THREADS free_input_threads(); #endif