From patchwork Tue May 2 00:51:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muhammad Faiz X-Patchwork-Id: 3541 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.3.129 with SMTP id 123csp1651351vsd; Mon, 1 May 2017 18:22:06 -0700 (PDT) X-Received: by 10.223.157.11 with SMTP id k11mr16698847wre.71.1493688126247; Mon, 01 May 2017 18:22:06 -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 n2si18190155wrb.4.2017.05.01.18.22.05; Mon, 01 May 2017 18:22:06 -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 B4748680674; Tue, 2 May 2017 04:21:59 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg0-f65.google.com (mail-pg0-f65.google.com [74.125.83.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 14DFC680674 for ; Tue, 2 May 2017 04:21:53 +0300 (EEST) Received: by mail-pg0-f65.google.com with SMTP id v1so18426579pgv.3 for ; Mon, 01 May 2017 18:21:56 -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; bh=35Lkh83DyXo/lFzp/T3n+hEYSOyH/v5LZbrmk4qqOU8=; b=E78A9yZrGL5UJIw6AirW5+Fna1VaqhqbRv05waP9ti+/z8TRPJ/Y2V+JzmGoMS+ikn v4bhpQBIxpSfqmd5HUL1oXj2PTNIiJY28xuVrp4W0nTD65xCXAnyU8WrTMyqouYtp6sT BoadO9TnIv3yt0W99IWTYt5FjBEeSDGZ9v5Dp8QOOgReF4Z/E3qaibpvWuXdAsXxsR2T EXY2ys22xPf2TD2Wa6mscG1iN+/Xy72bF5F3UpYs9bn44IfexA1QyfESjPRRa1HurErt DCI2wRrIpWlwNFutKleYD6rZ7Gy8Ldw/ZSI5OcwoKlWwawn+B//h1GozEEYDmP1a/DNo /8Qg== 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; bh=35Lkh83DyXo/lFzp/T3n+hEYSOyH/v5LZbrmk4qqOU8=; b=Zl66a1tNJmW3oyC0Qed3xka13+waK9PaNtf1+mFgroKveAdNc9JU2T+Nbex6rpdbyn tuO72keYvCxvCf/GxRsOX+qSjMOahrMX2N8NmbUnsS5wCOfyGxOUT/ZyQ2k4GbUPCb9D 2u7f3wpgqs0UYQn3EdPaTH+z8kCbhsTbmrTjtVLqlfGyOoqcHtIE/wdPjcyhpk8xD4tD KQXUBJpxrWhaOEueJpOVIikWfnvgg/gh/5pAxa0QZOjp/6PGGGCjcgr8RKUxDPQ2oOwj L8zwGsEe5GufG1mtQnjv4rQTQx1VSPtRLroUutayz/NnaxfaPygMRC8jY7TpKhGsL3LL nWVQ== X-Gm-Message-State: AN3rC/5JANCujuX1m3kEI6zr0jYNPVaAEe8+fDKc+tZ+2ggrrjaAsuu9 iPzUOnt3gab/eZmdlyI= X-Received: by 10.99.2.5 with SMTP id 5mr29442208pgc.205.1493686339031; Mon, 01 May 2017 17:52:19 -0700 (PDT) Received: from localhost.localdomain ([114.121.246.19]) by smtp.gmail.com with ESMTPSA id c83sm25519619pfd.113.2017.05.01.17.52.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 May 2017 17:52:18 -0700 (PDT) From: Muhammad Faiz To: ffmpeg-devel@ffmpeg.org Date: Tue, 2 May 2017 07:51:56 +0700 Message-Id: <20170502005156.13139-1-mfcc64@gmail.com> X-Mailer: git-send-email 2.9.3 Subject: [FFmpeg-devel] [PATCH] 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 | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/ffmpeg.c b/ffmpeg.c index bf04a6c..023cb98 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_packet2(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, @@ -802,6 +804,11 @@ static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost) av_packet_unref(pkt); } +static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost) +{ + write_packet2(of, pkt, ost, 0); +} + static void close_output_stream(OutputStream *ost) { OutputFile *of = output_files[ost->file_index]; @@ -2972,7 +2979,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_packet2(of, &pkt, ost, 1); } }