From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 2BEB342163 for ; Wed, 23 Feb 2022 15:04:31 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9DA3168B277; Wed, 23 Feb 2022 17:04:30 +0200 (EET) Received: from mail-oi1-f176.google.com (mail-oi1-f176.google.com [209.85.167.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D8E0168A8A5 for ; Wed, 23 Feb 2022 17:04:23 +0200 (EET) Received: by mail-oi1-f176.google.com with SMTP id l25so12915983oic.13 for ; Wed, 23 Feb 2022 07:04:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=aDcup/aVyy3A4XpDdVz73cKFBzcg1eWuQ6WWx8cddhU=; b=JKnm/W077OxHd305esUXjBS2UsR64ub4gVhcZnVeTMfJ/SB6PtBJ8PCIbB/6SoV3x0 Nx9hTxoMCu//V1VNXUZA4KN8kh+WSaN9SLnu80lc0E1dm0EbuFyPfww3IcvaXv7ZSsGi CYH4RaNX6Meu/hnUBk92vGq2pDSBYxGju19MessBzArQSEa5dp614TGNqQtjVjzg8skI Q7hbL2PYyZz0O2f1fbKCd1+3R4cyosISXWDcc1gJ/eQSXuY5MhQ1Mo/lkutefkx1pXCa NcPlMzaQatHHKEQwLYaUQGBlI/nCrPj4i7Hk/afiPrwyxZ2s0HotgXR2eMOpOFPfoXFS 34zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=aDcup/aVyy3A4XpDdVz73cKFBzcg1eWuQ6WWx8cddhU=; b=ux7WOA5dh+f1h4jN6W5UmiY6ukIcMryeIYIj7sg+4Iahwk5whcSsqAgRUtWjjMhtk8 PaHHleZERiy0IV4ESzIkHrLG6pTsU7t9gsPyTVnAECynF0+iyCNCimpkdndUNy0qb6U0 IjVHqsSWwbemM2K3iSMeBTcFkrCujYb1/fwJQ+gvYeGiC+kSEvf3Vqif6nE9ZPOhvZ/s Cacf71texSfBQ/N8ElMAmytKCMZkwFIYtXhWoM61tOd2MFGQsZ3rakLHOtZjgAWt/Z00 tDaUzS7ouQkDU8UfWM1aOpsLiMFE7Y+2xjH2j7iVqktc8LxacN4YWzSiuOBC4YlFYN+V dT1w== X-Gm-Message-State: AOAM531AAxc32AdcvEWWWRvuNCk0fTSo9lJCSEEbK1arttuuZhlUBSHT JFMXtRNoAbgggaH8LQyN0097XxZw4CRBhQ== X-Google-Smtp-Source: ABdhPJzrd9HTH3od3IwSkVl4Hd0ExxIuLUKrNn6vF97b/A4v37bhzVzJ1KQxgbKosWlf6D1MTBpIFg== X-Received: by 2002:a05:6808:178a:b0:2d2:f29e:e436 with SMTP id bg10-20020a056808178a00b002d2f29ee436mr44475oib.105.1645628661793; Wed, 23 Feb 2022 07:04:21 -0800 (PST) Received: from localhost.localdomain ([186.136.131.95]) by smtp.gmail.com with ESMTPSA id o2sm8571449otl.9.2022.02.23.07.04.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 07:04:21 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 23 Feb 2022 12:03:52 -0300 Message-Id: <20220223150355.944-1-jamrial@gmail.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/4 v2] ffmpeg: flush delayed frames in codec copy scenarios X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Bitstream filters inserted between the input and output were never drained, resulting packets being lost if the bsf had any buffered. Signed-off-by: James Almer --- Now also flushing packets when forcing a record duration. fftools/ffmpeg.c | 13 ++++++++----- fftools/ffmpeg.h | 1 + fftools/ffmpeg_filter.c | 1 + fftools/ffmpeg_opt.c | 4 ++++ 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index e5de099d14..44043ef203 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -2010,7 +2010,7 @@ static int check_output_constraints(InputStream *ist, OutputStream *ost) if (ost->source_index != ist_index) return 0; - if (ost->finished) + if (ost->finished & MUXER_FINISHED) return 0; if (of->start_time != AV_NOPTS_VALUE && ist->pts < of->start_time) @@ -2743,7 +2743,9 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo } ist->pts = ist->dts; ist->next_pts = ist->next_dts; - } + } else if (!ist->decoding_needed) + eof_reached = 1; + for (i = 0; i < nb_output_streams; i++) { OutputStream *ost = output_streams[i]; @@ -4224,11 +4226,12 @@ static int process_input(int file_index) for (i = 0; i < ifile->nb_streams; i++) { ist = input_streams[ifile->ist_index + i]; avctx = ist->dec_ctx; - if (ist->decoding_needed) { + if (ist->processing_needed) { ret = process_input_packet(ist, NULL, 1); if (ret>0) return 0; - avcodec_flush_buffers(avctx); + if (ist->decoding_needed) + avcodec_flush_buffers(avctx); } } #if HAVE_THREADS @@ -4258,7 +4261,7 @@ static int process_input(int file_index) for (i = 0; i < ifile->nb_streams; i++) { ist = input_streams[ifile->ist_index + i]; - if (ist->decoding_needed) { + if (ist->processing_needed) { ret = process_input_packet(ist, NULL, 0); if (ret>0) return 0; diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 649f6ee047..82f3db6b6d 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -306,6 +306,7 @@ typedef struct InputStream { int decoding_needed; /* non zero if the packets must be decoded in 'raw_fifo', see DECODING_FOR_* */ #define DECODING_FOR_OST 1 #define DECODING_FOR_FILTER 2 + int processing_needed; /* non zero if the packets must be processed */ AVCodecContext *dec_ctx; const AVCodec *dec; diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 31d9a8076e..0845c631a5 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -294,6 +294,7 @@ static void init_input_filter(FilterGraph *fg, AVFilterInOut *in) ist->discard = 0; ist->decoding_needed |= DECODING_FOR_FILTER; + ist->processing_needed = 1; ist->st->discard = AVDISCARD_NONE; ifilter = ALLOC_ARRAY_ELEM(fg->inputs, fg->nb_inputs); diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 76b9020e83..7ff3936dcf 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -2615,6 +2615,7 @@ loop_end: if (ost->encoding_needed && ost->source_index >= 0) { InputStream *ist = input_streams[ost->source_index]; ist->decoding_needed |= DECODING_FOR_OST; + ist->processing_needed = 1; if (ost->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || ost->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { @@ -2627,6 +2628,9 @@ loop_end: exit_program(1); } } + } else if (ost->stream_copy && ost->source_index >= 0) { + InputStream *ist = input_streams[ost->source_index]; + ist->processing_needed = 1; } /* set the filter output constraints */ -- 2.35.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".