From patchwork Tue May 2 07:39:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muhammad Faiz X-Patchwork-Id: 3546 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.3.129 with SMTP id 123csp1751584vsd; Tue, 2 May 2017 00:40:17 -0700 (PDT) X-Received: by 10.28.238.9 with SMTP id m9mr1259900wmh.72.1493710817118; Tue, 02 May 2017 00:40:17 -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 m11si18004603wrb.251.2017.05.02.00.40.16; Tue, 02 May 2017 00:40:17 -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; dkim=neutral (body hash did not verify) header.i=@gmail.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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1DB35689811; Tue, 2 May 2017 10:40:10 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg0-f66.google.com (mail-pg0-f66.google.com [74.125.83.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8E3946882AE for ; Tue, 2 May 2017 10:40:03 +0300 (EEST) Received: by mail-pg0-f66.google.com with SMTP id v1so19950808pgv.3 for ; Tue, 02 May 2017 00:40:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=05I5hjqs5qzj1V8b+EXVrLxO1zkIXP1A10HZJv7seT8=; b=BoTfRWVJ/MWGVL4/WNUmtArCZQBro4mK9FySb7ieHMqBVrktKvMPckEcvP1rFq8QQP otxzUlPNBw4riTnjhKpmes+HIsO942kNlAWQ0xYhfrGECbke4rjdbqPPWujlVcIGo7Hx 78NTP9BkYe8W5zJkwmxrQNUVuKw1vGbGfMUwq8zyRPzt4PMhvZ7FrsQP36HqRk/ghO1f PTQKTTyOlqVJEaf0OGyoJm080U111Rf9edeF5U0No0sCw3hmv+7PeBe3azI1FNQuJ+bM hM30YR3bWpTEb5YzQUmE7bVNLQJS7vfSuHZk4Akw84yI9oJDHZ+8zawxbkEL7MgCJFAQ xXEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=05I5hjqs5qzj1V8b+EXVrLxO1zkIXP1A10HZJv7seT8=; b=RgC2LFCw3V5L9HLbj6RVSHBuRMuR30QUjNiSe+9ySuWvyH3eL0tp/YekOZmkiugjiB cXfmltGFSixXozgVo1ZdKNUyqzeygrVr6bMjrVFebFu0uoBaDAr1MM3QfujdT546+7hs 89X5wiLSb0SW0lzS2NwkChx/pokRfdpXVuXDT+LzqEyOCWPTgKKmY7U992/C7/+Ya1DP Sjr18LTirzsIjjTM3UzHukWnFfaniE6DaLmBiTB/tC/2O5SMtX2gS33gE7bVacx7K3zG iyVhq+6ajpx5HGlusnKOjL5CPovYC5PPG3h5k56S/FM0Ox8/ltT2r5Tt01/38IRn+ce2 lGSw== X-Gm-Message-State: AN3rC/5btOLa0NwNBWUCThFKEFLL+8NbeYg7xINSMWZG279A7dQccgA+ p/U1BBnHMeDBNg== X-Received: by 10.99.123.25 with SMTP id w25mr9984333pgc.139.1493710805696; Tue, 02 May 2017 00:40:05 -0700 (PDT) Received: from localhost.localdomain ([114.124.183.10]) by smtp.gmail.com with ESMTPSA id z126sm7266333pgb.65.2017.05.02.00.40.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 May 2017 00:40:05 -0700 (PDT) From: Muhammad Faiz To: ffmpeg-devel@ffmpeg.org Date: Tue, 2 May 2017 14:39:46 +0700 Message-Id: <20170502073946.3243-1-mfcc64@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <4298f500-cd61-8271-eb1f-e221743d80ff@gmail.com> References: <4298f500-cd61-8271-eb1f-e221743d80ff@gmail.com> Subject: [FFmpeg-devel] [PATCH v2] ffmpeg: count packets when queued 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: Muhammad Faiz MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Because write_packet() fakely writes packets to muxer by queueing them when muxer hasn't been initialized, it should also increment frame_number fakely. This is required because code in do_streamcopy() rely on frame_number. Should fix Ticket6227 Signed-off-by: Muhammad Faiz --- ffmpeg.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/ffmpeg.c b/ffmpeg.c index bf04a6c..e798d92 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -669,12 +669,28 @@ static void close_all_output_streams(OutputStream *ost, OSTFinished this_stream, } } -static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost) +static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue) { AVFormatContext *s = of->ctx; AVStream *st = ost->st; int ret; + /* + * Audio encoders may split the packets -- #frames in != #packets out. + * But there is no reordering, so we can limit the number of output packets + * by simply dropping them here. + * Counting encoded video frames needs to be done separately because of + * reordering, see do_video_out(). + * Do not count the packet when unqueued because it has been counted when queued. + */ + if (!(st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && ost->encoding_needed) && !unqueue) { + if (ost->frame_number >= ost->max_frames) { + av_packet_unref(pkt); + return; + } + ost->frame_number++; + } + if (!of->header_written) { AVPacket tmp_pkt = {0}; /* the muxer is not initialized yet, buffer the packet */ @@ -703,20 +719,6 @@ static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost) (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && audio_sync_method < 0)) pkt->pts = pkt->dts = AV_NOPTS_VALUE; - /* - * Audio encoders may split the packets -- #frames in != #packets out. - * But there is no reordering, so we can limit the number of output packets - * by simply dropping them here. - * Counting encoded video frames needs to be done separately because of - * reordering, see do_video_out() - */ - if (!(st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && ost->encoding_needed)) { - if (ost->frame_number >= ost->max_frames) { - av_packet_unref(pkt); - return; - } - ost->frame_number++; - } if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { int i; uint8_t *sd = av_packet_get_side_data(pkt, AV_PKT_DATA_QUALITY_STATS, @@ -861,10 +863,10 @@ static void output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost) goto finish; idx++; } else - write_packet(of, pkt, ost); + write_packet(of, pkt, ost, 0); } } else - write_packet(of, pkt, ost); + write_packet(of, pkt, ost, 0); finish: if (ret < 0 && ret != AVERROR_EOF) { @@ -2972,7 +2974,7 @@ static int check_init_output_file(OutputFile *of, int file_index) while (av_fifo_size(ost->muxing_queue)) { AVPacket pkt; av_fifo_generic_read(ost->muxing_queue, &pkt, sizeof(pkt), NULL); - write_packet(of, &pkt, ost); + write_packet(of, &pkt, ost, 1); } }