From patchwork Wed Sep 23 18:01:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Zhili X-Patchwork-Id: 22566 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 62C3244AC6B for ; Wed, 23 Sep 2020 21:01:35 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3076D68AAD8; Wed, 23 Sep 2020 21:01:35 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from qq.com (out203-205-221-236.mail.qq.com [203.205.221.236]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 580C568A817 for ; Wed, 23 Sep 2020 21:01:27 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1600884083; bh=rD5Qqb/PBom9KVgsBjsZxQ02REAqXT/MHqi0reEQV58=; h=From:To:Cc:Subject:Date; b=i9cRb5Ml4LT2FoOdtycb2YXqo7ecgu3QdjGBKawNE+uNQlB2rvkvS0INp7yCrGP9G ENsUaUpI564ORh0XwWMzmaKY8en+fG2Itcw874JqrwU89mGsegeJRudX9NNoC/ILX7 1UHDKC+9vSc24oj/mvYXMLz62U67pe1SIRMu6pfs= Received: from localhost.localdomain ([27.46.80.13]) by newxmesmtplogicsvrszb6.qq.com (NewEsmtp) with SMTP id 55294AB; Thu, 24 Sep 2020 02:01:21 +0800 X-QQ-mid: xmsmtpt1600884081tg9ieymkz Message-ID: X-QQ-XMAILINFO: M7iptXc3mHZW7vl3dWWuAP7mfZj05fcW+BI3RClb9Jhcr77zfWm+Xb/FJaJ0B+ vcNQBs7YImlG7W0AJl9QwffWQSViwPoEMm8qoymchbkawDJVVg5skD+6clKNDRnCK7EVm59rtpW7 KSv3UucQlHr2ElcayCSkWNtCpQRyncXSyyEjY5A4zUB8b2Z4YNiZBUu2QBh+LkckER51+tL6fBIf RWLatQbD1ko7MRwKJp4mTh+8GQ4vAWFhDjblUusEeHvQOtArtVbfaqn+BJeuAhdPv7Dzmxw71hfw yZe/VXYS+ukaoGlrXc5NzfQQjxKOaFTgQWghBqho9YeIPGip9v0rYlC7exLn9aTQE0msCq+uZiEx wvlQa8rvVgDotHM2GYd6Wky58dz8aCd/Uuig1gO1Sfb8DWZFshKkV1kwx6C01duoVefkgJnn01SM yUTkEXbKtvKhD379uDUoBJlV2O4ngn7yzDdmUc5aKxQbPkoItGR6ePKfEKTWhQYSMitRCkn2Xabk bUkrOOUPFELAnxUyVMQFc6mkDXpK4hE73xfriKRcFro1uDUoTVSshbnWIi2eS1Uqafj589tASiFF XuS/zYDSakVLEpwsV4ZgwfLjeYaBq1snZfpVpMSi3LCvlos68QhxLRapcLSzprKVIZNvUqxypm4k g3LZguIZQCrm9Fh2kXG/fTX6BR0aHtZeYdcYJCtW0bP5pfnHplvmeoD3GaZnVyw2oyrx1Z46xMJT J6AjQqEJPD/tWfwMtq42KRmk/3mUK6Cq9BNLwoW7hdcOk= From: Zhao Zhili To: ffmpeg-devel@ffmpeg.org Date: Thu, 24 Sep 2020 02:01:17 +0800 X-OQ-MSGID: <20200923180117.159116-1-quinkblack@foxmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2] examples/decode_video: flush parser to fix missing frame 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: Zhao Zhili Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" To reproduce, run decode_video with a single frame sample. No frame was decoded before the patch. --- doc/examples/decode_video.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/doc/examples/decode_video.c b/doc/examples/decode_video.c index 18ee90a6c0..9ce3531d63 100644 --- a/doc/examples/decode_video.c +++ b/doc/examples/decode_video.c @@ -92,6 +92,7 @@ int main(int argc, char **argv) uint8_t *data; size_t data_size; int ret; + int eof; AVPacket *pkt; if (argc <= 2) { @@ -150,15 +151,14 @@ int main(int argc, char **argv) exit(1); } - while (!feof(f)) { + do { /* read raw data from the input file */ data_size = fread(inbuf, 1, INBUF_SIZE, f); - if (!data_size) - break; + eof = !data_size; /* use the parser to split the data into frames */ data = inbuf; - while (data_size > 0) { + while (data_size > 0 || eof) { ret = av_parser_parse2(parser, c, &pkt->data, &pkt->size, data, data_size, AV_NOPTS_VALUE, AV_NOPTS_VALUE, 0); if (ret < 0) { @@ -170,8 +170,10 @@ int main(int argc, char **argv) if (pkt->size) decode(c, frame, pkt, outfilename); + else if (eof) + break; } - } + } while (!eof); /* flush the decoder */ decode(c, frame, NULL, outfilename);