From patchwork Wed May 17 10:19:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41659 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1077999pzb; Wed, 17 May 2023 03:21:27 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4BXylzG4Z31BdESnm8+DeP3oxYjgp+HDaF6OgKAKS37m2Qcn6fJcUTNfAzu4wxqPkshDlc X-Received: by 2002:a17:907:9710:b0:96a:ee54:9f2b with SMTP id jg16-20020a170907971000b0096aee549f2bmr13305589ejc.29.1684318887677; Wed, 17 May 2023 03:21:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684318887; cv=none; d=google.com; s=arc-20160816; b=rJfUfb/qlNimeQ9/fpNdEg2MPzo8tzLB2X3UyFz0jLcXmDYNpBYwMMLgLVcZKqcMVj pnWsKO792P08atqyzobwm4NQwjnvpDJ0FyqxLTJIEq17T1mC5P6vMEb5Gix5Zb9aGFHL K0k0waQ67J2jD/PPdFFNSDqFVC6rx/01/+NrD/z5QJi+xDxqm+/fCIqU3pcjDzy9Fqv+ dshO8mqoSoXSZ8actC5WqSkvxZj6tQROC92xsPNuTCwWt8dnBVJ57YKXuK39ILAqW7fl 7r4VNa6Vvf4bZLyJXXZFq0csTOUSdtge45ARpfuYx2VcV4C8pvyW+M5MEggWQEYatCsj fFKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=DXEAx1Jg2Y1dY0Rf9OCfitnen/TCs/OQdiOnK4w9Fnk=; b=IWYzXu+KBlAIXG63q7PfGiLnv1SAjHPpIw9Qg0CWZAaOOpI6Oa4spptfjRIgON/F2F 5DrRyf8/n+XY+bEd1cEVoRBE6kQsFjzGbNnnrio23HOCScliFifwuyXOGnlxHNjUOuth XHg41fCIdP+qPDmfVgQuSkz6Sw94+3KRhnR6YvrKk4B83GuXdwGJLiZV+0u2Yj6f+Ssx aAcTMTocoPxem+tKa2P0PrFFxSv1ZNFZF+gVssz6GWfHz/v9oE265AUcDpdwd6pY99HA vyiXRF41qMtbOFiZkXaRn85FczKYl2bAl6t1ZOxIxwZAUDeTOEehrhmos6OvEBG5udZu 7ejw== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id ja3-20020a170907988300b0094ee039da42si17060459ejc.751.2023.05.17.03.21.27; Wed, 17 May 2023 03:21:27 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D82B968C12A; Wed, 17 May 2023 13:20:56 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F145968C0FF for ; Wed, 17 May 2023 13:20:47 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id B8A692404EE for ; Wed, 17 May 2023 12:20:47 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id dep6NHaWb_o6 for ; Wed, 17 May 2023 12:20:45 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id CDE6F240177 for ; Wed, 17 May 2023 12:20:45 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 636773A031B for ; Wed, 17 May 2023 12:20:39 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 May 2023 12:19:54 +0200 Message-Id: <20230517102029.541-1-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/36] fftools/ffmpeg: shorten a variable name 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: dO8Zvpj0QFgR There is only one frame used in decode_video() -- the one output by the decoder. So there is no point in explicitly calling it the _decoded_ frame. --- fftools/ffmpeg.c | 52 ++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index ebd793a98c..084192f270 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1027,7 +1027,7 @@ static int64_t video_duration_estimate(const InputStream *ist, const AVFrame *fr static int decode_video(InputStream *ist, const AVPacket *pkt, int *got_output, int eof, int *decode_failed) { - AVFrame *decoded_frame = ist->decoded_frame; + AVFrame *frame = ist->decoded_frame; int ret = 0, err = 0; int64_t best_effort_timestamp; @@ -1038,7 +1038,7 @@ static int decode_video(InputStream *ist, const AVPacket *pkt, int *got_output, return 0; update_benchmark(NULL); - ret = decode(ist, ist->dec_ctx, decoded_frame, got_output, pkt); + ret = decode(ist, ist->dec_ctx, frame, got_output, pkt); update_benchmark("decode_video %d.%d", ist->file_index, ist->st->index); if (ret < 0) *decode_failed = 1; @@ -1062,13 +1062,13 @@ static int decode_video(InputStream *ist, const AVPacket *pkt, int *got_output, check_decode_result(ist, got_output, ret); if (*got_output && ret >= 0) { - if (ist->dec_ctx->width != decoded_frame->width || - ist->dec_ctx->height != decoded_frame->height || - ist->dec_ctx->pix_fmt != decoded_frame->format) { + if (ist->dec_ctx->width != frame->width || + ist->dec_ctx->height != frame->height || + ist->dec_ctx->pix_fmt != frame->format) { av_log(NULL, AV_LOG_DEBUG, "Frame parameters mismatch context %d,%d,%d != %d,%d,%d\n", - decoded_frame->width, - decoded_frame->height, - decoded_frame->format, + frame->width, + frame->height, + frame->format, ist->dec_ctx->width, ist->dec_ctx->height, ist->dec_ctx->pix_fmt); @@ -1079,17 +1079,17 @@ static int decode_video(InputStream *ist, const AVPacket *pkt, int *got_output, return ret; if(ist->top_field_first>=0) - decoded_frame->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST; + frame->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST; ist->frames_decoded++; - if (ist->hwaccel_retrieve_data && decoded_frame->format == ist->hwaccel_pix_fmt) { - err = ist->hwaccel_retrieve_data(ist->dec_ctx, decoded_frame); + if (ist->hwaccel_retrieve_data && frame->format == ist->hwaccel_pix_fmt) { + err = ist->hwaccel_retrieve_data(ist->dec_ctx, frame); if (err < 0) goto fail; } - best_effort_timestamp= decoded_frame->best_effort_timestamp; + best_effort_timestamp = frame->best_effort_timestamp; if (ist->framerate.num) best_effort_timestamp = ist->cfr_next_pts++; @@ -1100,13 +1100,13 @@ static int decode_video(InputStream *ist, const AVPacket *pkt, int *got_output, ist->last_frame_pts + ist->last_frame_duration_est; if(best_effort_timestamp != AV_NOPTS_VALUE) { - decoded_frame->pts = best_effort_timestamp; + frame->pts = best_effort_timestamp; } // update timestamp history - ist->last_frame_duration_est = video_duration_estimate(ist, decoded_frame); - ist->last_frame_pts = decoded_frame->pts; - ist->last_frame_tb = decoded_frame->time_base; + ist->last_frame_duration_est = video_duration_estimate(ist, frame); + ist->last_frame_pts = frame->pts; + ist->last_frame_tb = frame->time_base; if (debug_ts) { av_log(ist, AV_LOG_INFO, @@ -1115,25 +1115,25 @@ static int decode_video(InputStream *ist, const AVPacket *pkt, int *got_output, "best_effort_ts:%"PRId64" best_effort_ts_time:%s " "duration:%s duration_time:%s " "keyframe:%d frame_type:%d time_base:%d/%d\n", - av_ts2str(decoded_frame->pts), - av_ts2timestr(decoded_frame->pts, &ist->st->time_base), - av_ts2str(decoded_frame->pkt_dts), - av_ts2timestr(decoded_frame->pkt_dts, &ist->st->time_base), + av_ts2str(frame->pts), + av_ts2timestr(frame->pts, &ist->st->time_base), + av_ts2str(frame->pkt_dts), + av_ts2timestr(frame->pkt_dts, &ist->st->time_base), best_effort_timestamp, av_ts2timestr(best_effort_timestamp, &ist->st->time_base), - av_ts2str(decoded_frame->duration), - av_ts2timestr(decoded_frame->duration, &ist->st->time_base), - !!(decoded_frame->flags & AV_FRAME_FLAG_KEY), decoded_frame->pict_type, + av_ts2str(frame->duration), + av_ts2timestr(frame->duration, &ist->st->time_base), + !!(frame->flags & AV_FRAME_FLAG_KEY), frame->pict_type, ist->st->time_base.num, ist->st->time_base.den); } if (ist->st->sample_aspect_ratio.num) - decoded_frame->sample_aspect_ratio = ist->st->sample_aspect_ratio; + frame->sample_aspect_ratio = ist->st->sample_aspect_ratio; - err = send_frame_to_filters(ist, decoded_frame); + err = send_frame_to_filters(ist, frame); fail: - av_frame_unref(decoded_frame); + av_frame_unref(frame); return err < 0 ? err : ret; } From patchwork Wed May 17 10:19:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41656 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1077743pzb; Wed, 17 May 2023 03:20:57 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5fUNwcx72eizu3lnXj45lxlqY5nZ0B8CU1qMzAglEXhE41nyvnRNNOIkrX+tSAAT+b8drL X-Received: by 2002:a17:907:6090:b0:96a:4ea0:a1e7 with SMTP id ht16-20020a170907609000b0096a4ea0a1e7mr24700567ejc.50.1684318856949; Wed, 17 May 2023 03:20:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684318856; cv=none; d=google.com; s=arc-20160816; b=POviAZOIlX1oHGSRzRlX+wHMdiNlZEzZB1ymcoYihVxcJJLPcDLBoDCNKOY14m6XX+ J4JQjMMom/6pKWVkuxGu+vcIlKoNCn0qZ0aINoezfpZwRVHUmg15SOxr38x6gh+pjYxW yVLq1X8vDXtbxKuAc58p2nr2EU2M04qhMyXpR/tYxbIdYGoxUCE2Zk6yQ9+7PjsSLnHh X/LMwQNKARLCye1OCn+M89FcODXRSr0+LT+BPLDtg74WNK9X7dkkOo7TcBKc/RauTwd9 i8amW8JGIRjUDwkjQhJXX1akbovpZCrdj8vhFBMZcJPGanNIEajXhKfwclrgeufoABeQ 553A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=5wioa3mLzjAp6VUfsdvoM2uW5pRCcPQhTwVQqSOIS+g=; b=esqWD7BJzUge3+uJ6pa98XuC3L2HAyGfotz8H3TCcg90vTs4U62SZHnvIe/Tf4KG5M Q6cfQx4KMKd6VmUw2wxA194KnTp8xLRGl+5xlIQy6seKwpwrXaJbrbua5BNwSv4t8XaK C8fue/PNrcYV/1hs14wcsxrhAJg5WD2hqhJJFy/qnGhtLe/cadA7cuIx4q8XVCwOndCS qrap45bptMjf2yY054x6YGnLx/oZQAhtrnCTF6f5sfxTVpFNw8FCXGdg35KHcy8msh5q 4ndId33NTzVw0sydVKc0e/t3ytnR9AnWIxwGDpgoY9jl3iqsrCGdtn0Zt/UbJEOExHzh AP2Q== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id k21-20020a170906579500b0096647f97dc8si15534847ejq.82.2023.05.17.03.20.56; Wed, 17 May 2023 03:20:56 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 078C968C10E; Wed, 17 May 2023 13:20:53 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E35DD68BF17 for ; Wed, 17 May 2023 13:20:46 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 6D930240D28 for ; Wed, 17 May 2023 12:20:46 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id MV2vcecAjXGw for ; Wed, 17 May 2023 12:20:45 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id D394C2404EC for ; Wed, 17 May 2023 12:20:45 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 7025F3A048F for ; Wed, 17 May 2023 12:20:39 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 May 2023 12:19:55 +0200 Message-Id: <20230517102029.541-2-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517102029.541-1-anton@khirnov.net> References: <20230517102029.541-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 02/36] fftools/ffmpeg: drop a useless local variable 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: zIIPinDx1rkS Store decoded frame timestamp directly in AVFrame.pts, there is no advantage to using a separate local variable for it. --- fftools/ffmpeg.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 084192f270..60f0ff3b12 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1029,7 +1029,6 @@ static int decode_video(InputStream *ist, const AVPacket *pkt, int *got_output, { AVFrame *frame = ist->decoded_frame; int ret = 0, err = 0; - int64_t best_effort_timestamp; // With fate-indeo3-2, we're getting 0-sized packets before EOF for some // reason. This seems like a semi-critical bug. Don't trigger EOF, and @@ -1089,19 +1088,15 @@ static int decode_video(InputStream *ist, const AVPacket *pkt, int *got_output, goto fail; } - best_effort_timestamp = frame->best_effort_timestamp; + frame->pts = frame->best_effort_timestamp; if (ist->framerate.num) - best_effort_timestamp = ist->cfr_next_pts++; + frame->pts = ist->cfr_next_pts++; // no timestamp available - extrapolate from previous frame duration - if (best_effort_timestamp == AV_NOPTS_VALUE) - best_effort_timestamp = ist->last_frame_pts == AV_NOPTS_VALUE ? 0 : - ist->last_frame_pts + ist->last_frame_duration_est; - - if(best_effort_timestamp != AV_NOPTS_VALUE) { - frame->pts = best_effort_timestamp; - } + if (frame->pts == AV_NOPTS_VALUE) + frame->pts = ist->last_frame_pts == AV_NOPTS_VALUE ? 0 : + ist->last_frame_pts + ist->last_frame_duration_est; // update timestamp history ist->last_frame_duration_est = video_duration_estimate(ist, frame); @@ -1112,15 +1107,12 @@ static int decode_video(InputStream *ist, const AVPacket *pkt, int *got_output, av_log(ist, AV_LOG_INFO, "decoder -> pts:%s pts_time:%s " "pkt_dts:%s pkt_dts_time:%s " - "best_effort_ts:%"PRId64" best_effort_ts_time:%s " "duration:%s duration_time:%s " "keyframe:%d frame_type:%d time_base:%d/%d\n", av_ts2str(frame->pts), av_ts2timestr(frame->pts, &ist->st->time_base), av_ts2str(frame->pkt_dts), av_ts2timestr(frame->pkt_dts, &ist->st->time_base), - best_effort_timestamp, - av_ts2timestr(best_effort_timestamp, &ist->st->time_base), av_ts2str(frame->duration), av_ts2timestr(frame->duration, &ist->st->time_base), !!(frame->flags & AV_FRAME_FLAG_KEY), frame->pict_type, From patchwork Wed May 17 10:19:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41658 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1077920pzb; Wed, 17 May 2023 03:21:17 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5Cx1MJ9yTkdya27y5jZ6JzwcMDv3BmOOrhpCjRaZbC6LcLatu15QX2BY86sUxbt046Z205 X-Received: by 2002:a17:907:6e03:b0:96a:2210:7dd8 with SMTP id sd3-20020a1709076e0300b0096a22107dd8mr1422184ejc.38.1684318877481; Wed, 17 May 2023 03:21:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684318877; cv=none; d=google.com; s=arc-20160816; b=ppf44bmWYJDT/3aYwVo/2e1aLt8jSBFIKxf1yyBg2knkUnWCJ++hhG3A32DhIlLNjW 2FJs65A9z88+V+Ca+m76eSHi21CisgGSPsUb9rlU3hlmdHLL+o5ZQ5A0lUNYcBktS0UZ CDyFPvf2WwGTc75tNoHJ66eYZPMZCESFqASHkrSx3SsBYo0LLIc9FmSb2xtgl7z/n0YF Is0Af8oaak500U3lPhaBxbL3Mggz9koiMDyo+PVTCYSONa98iyk7LqwTHpuCUjFh+EbD jMYDxsYf/gf3p0EDpghl6z2K3DKBxc0tfWdneOxibUKxUf5lrEv2ptYoEoAeWW1x60AQ F4yQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=Y3KxBPkpfuSfgPUVD4iIXmfjOHItKVhxiXFAwAHaRZQ=; b=gyd9PeVchR2heij4Ae2a9/n27s04nINvgAId+YSJqWV00cknBeMb2vqkwdkNUQOXdX KpTkTz5l5a51PgUfj4/Vzczp5yfJUmdnuYTjybC6F8/EXlNE1s1/j5iLBThaqYOiaao6 W4UwZd5eNQU8R9jHwDok+dnSR7Ju3AbtbLWAp06luKwH20ReqUs1yWDAb2STd1wcfoXo aM58hiusAWC6nfhJlc57DQS0AMPU5ym1z+VqTd6dTCG901QTxkWlYrnrVpaE93G9eKqI AQDznMODMzOmguOlroTEQMr5Io/Lq8vcu8HveI435E3cFZQJAKomrLxhQFPWBzg/18w/ n3Ug== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id d9-20020a170906370900b0094aa087617asi14230236ejc.844.2023.05.17.03.21.17; Wed, 17 May 2023 03:21: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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 064C268C122; Wed, 17 May 2023 13:20:56 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C35F068C0FF for ; Wed, 17 May 2023 13:20:47 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 8C8492404F5 for ; Wed, 17 May 2023 12:20:47 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id uBe6cDhvLhX1 for ; Wed, 17 May 2023 12:20:47 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id D7D302404EE for ; Wed, 17 May 2023 12:20:45 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 7B1BE3A11B4 for ; Wed, 17 May 2023 12:20:39 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 May 2023 12:19:56 +0200 Message-Id: <20230517102029.541-3-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517102029.541-1-anton@khirnov.net> References: <20230517102029.541-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 03/36] fftools/ffmpeg: replace stream timebase with decoded frame one 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 9yrjrS703Ch7 They are the same for now, but this may change in the future. --- fftools/ffmpeg.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 60f0ff3b12..9e5e56e9e7 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -993,7 +993,7 @@ static int64_t video_duration_estimate(const InputStream *ist, const AVFrame *fr AVRational field_rate = av_mul_q(ist->dec_ctx->framerate, (AVRational){ 2, 1 }); codec_duration = av_rescale_q(fields, av_inv_q(field_rate), - ist->st->time_base); + frame->time_base); } // prefer codec-layer duration for containers without timestamps @@ -1015,7 +1015,7 @@ static int64_t video_duration_estimate(const InputStream *ist, const AVFrame *fr // try average framerate if (ist->st->avg_frame_rate.num && ist->st->avg_frame_rate.den) { int64_t d = av_rescale_q(1, av_inv_q(ist->st->avg_frame_rate), - ist->st->time_base); + frame->time_base); if (d > 0) return d; } @@ -1110,13 +1110,13 @@ static int decode_video(InputStream *ist, const AVPacket *pkt, int *got_output, "duration:%s duration_time:%s " "keyframe:%d frame_type:%d time_base:%d/%d\n", av_ts2str(frame->pts), - av_ts2timestr(frame->pts, &ist->st->time_base), + av_ts2timestr(frame->pts, &frame->time_base), av_ts2str(frame->pkt_dts), - av_ts2timestr(frame->pkt_dts, &ist->st->time_base), + av_ts2timestr(frame->pkt_dts, &frame->time_base), av_ts2str(frame->duration), - av_ts2timestr(frame->duration, &ist->st->time_base), + av_ts2timestr(frame->duration, &frame->time_base), !!(frame->flags & AV_FRAME_FLAG_KEY), frame->pict_type, - ist->st->time_base.num, ist->st->time_base.den); + frame->time_base.num, frame->time_base.den); } if (ist->st->sample_aspect_ratio.num) From patchwork Wed May 17 10:19:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41660 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1078106pzb; Wed, 17 May 2023 03:21:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7EfkkCc5axGf+OYKheoWndqPByMszzCUlq61XD3KO4PfnbpHxMI49KEz2/zVsZSmTWLjHL X-Received: by 2002:aa7:da45:0:b0:50b:d863:30ea with SMTP id w5-20020aa7da45000000b0050bd86330eamr2014529eds.0.1684318897918; Wed, 17 May 2023 03:21:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684318897; cv=none; d=google.com; s=arc-20160816; b=VoXy9ZoeSVO4LXv+petO4DQQjj6x21lLeJEFJHQ/Tb2qez98mMQmdmT+XVUU5SSFwq +Uox0o3fkBwPYECKdfqpxUw59gAClCIguH4gAEQlKNPX14XWF9+atTl1JBPXHHTf+grx 2QVnSTokf/7deQ9IWjad4CKr8QR/atokr/PA2J+XYZ/J87TXJ+2e1Y6PXp8fuM8/oUMc soYajutZV2QfgGYAZPPHT6J3RtXH7GZexmbW0pcLDHVIfiNNop3bucq4vw8/3tHhT41N RyAfTGSm2soswnnBIPHm9yS/Bpec+D5MEn6Q3WPoxB9/0uWeOFvZZdSHKojc8pggMUGX KqBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=RQb2Mxe0HPrCQvSdSjsqOu1+IgYdYGW7fL7Tv/tXFxM=; b=xUp4pCkom2VI25jjo1NfRUWYO5BuKuVgmxPIBmf+fTzeLf3EcOLtpuHnOuXNwMhisH wJz1ycGwj+fuBBkgAZ0lm9lcmWvlNAAcgDXsKW0iHTINKXWR+ELRxGd1zi3xD9xR0M2S UXl5sFC03Yemj3Z1XuRob2OEKIahlXNPbR+SV8FRKEDtZso85TBKshJjiCPUxhezt/ji N3spOyuV7dTChLP1ZsYbPO3ND3zbDapzX7m+yyRuzfKQ2ouzyh8nvGgIPo/YNz4oYfKG lqMHHHANh1GR3Iw7pE4Kwzcv75AnLt4aElkjYXz9m8oSJipQ6EoQpT298MFNQkESbYm5 dFJg== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id i11-20020aa7dd0b000000b00506b2a534fcsi15661650edv.85.2023.05.17.03.21.37; Wed, 17 May 2023 03:21:37 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D8A6A68C12D; Wed, 17 May 2023 13:20:57 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 698D768C0E4 for ; Wed, 17 May 2023 13:20:48 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 318F1240177 for ; Wed, 17 May 2023 12:20:48 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id sWbek8Hd5cYm for ; Wed, 17 May 2023 12:20:47 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id E2B09240591 for ; Wed, 17 May 2023 12:20:45 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 85CC03A11DB for ; Wed, 17 May 2023 12:20:39 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 May 2023 12:19:57 +0200 Message-Id: <20230517102029.541-4-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517102029.541-1-anton@khirnov.net> References: <20230517102029.541-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 04/36] fftools/ffmpeg_filter: convert input frame timestamps 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: pv3i+hq+GTQA Decoder timebase does not always have to match filter timebase. --- fftools/ffmpeg_filter.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index aea951a2da..95ffa0f087 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -55,6 +55,9 @@ static FilterGraphPriv *fgp_from_fg(FilterGraph *fg) typedef struct InputFilterPriv { InputFilter ifilter; + // used to hold submitted input + AVFrame *frame; + int eof; AVRational time_base; @@ -244,6 +247,10 @@ static InputFilter *ifilter_alloc(FilterGraph *fg) ifilter->graph = fg; ifilter->format = -1; + ifp->frame = av_frame_alloc(); + if (!ifp->frame) + report_and_exit(AVERROR(ENOMEM)); + ifp->fallback.format = -1; ifp->frame_queue = av_fifo_alloc2(8, sizeof(AVFrame*), AV_FIFO_FLAG_AUTO_GROW); @@ -284,6 +291,8 @@ void fg_free(FilterGraph **pfg) av_channel_layout_uninit(&ifp->fallback.ch_layout); + av_frame_free(&ifp->frame); + av_buffer_unref(&ifp->hw_frames_ctx); av_freep(&ifilter->name); av_freep(&fg->inputs[j]); @@ -1541,10 +1550,6 @@ int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame, int keep_reference) FilterGraph *fg = ifilter->graph; AVFrameSideData *sd; int need_reinit, ret; - int buffersrc_flags = AV_BUFFERSRC_FLAG_PUSH; - - if (keep_reference) - buffersrc_flags |= AV_BUFFERSRC_FLAG_KEEP_REF; /* determine if the parameters for this input changed */ need_reinit = ifilter->format != frame->format; @@ -1606,8 +1611,22 @@ int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame, int keep_reference) } } - ret = av_buffersrc_add_frame_flags(ifilter->filter, frame, buffersrc_flags); + if (keep_reference) { + ret = av_frame_ref(ifp->frame, frame); + if (ret < 0) + return ret; + } else + av_frame_move_ref(ifp->frame, frame); + frame = ifp->frame; + + frame->pts = av_rescale_q(frame->pts, frame->time_base, ifp->time_base); + frame->duration = av_rescale_q(frame->duration, frame->time_base, ifp->time_base); + frame->time_base = ifp->time_base; + + ret = av_buffersrc_add_frame_flags(ifilter->filter, frame, + AV_BUFFERSRC_FLAG_PUSH); if (ret < 0) { + av_frame_unref(frame); if (ret != AVERROR_EOF) av_log(NULL, AV_LOG_ERROR, "Error while filtering: %s\n", av_err2str(ret)); return ret; From patchwork Wed May 17 10:19:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41676 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1079363pzb; Wed, 17 May 2023 03:24:01 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5a0DG2iCBy5xmHjbHfGelYU/TL1qOzxqUiHtQlxKM0QsxL85H3iuInMei2qXQS+USn6TIQ X-Received: by 2002:a17:907:5c5:b0:95f:56e8:1c3c with SMTP id wg5-20020a17090705c500b0095f56e81c3cmr37658309ejb.17.1684319041315; Wed, 17 May 2023 03:24:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684319041; cv=none; d=google.com; s=arc-20160816; b=MhBd9KWoepveztW9mkAR4r3sU0QjpjAW8+xQZxltZfydAqU7b/5Gh4jgRFFms3dcAZ USYDEHK8gz1mOioHnCCPhytS6478REyKGHqf/raHwwI0bnHucz4GDonmLtgzRqqcAiFV tLpSmDXevvg+pC+nzi0RkSjKI7benM0vCsYEYZFqxW49smoeO1t5pNb9kH9j210T3hlD vMp7OpTzi6gDG8O7oKZhi4XxxdP79VcomHK+kFkKqmo+Y38ZWc2oMZWOVqOpV+Vt98Jp 28CBzAv8P+sUKUPEQSWl+mgFEGv/LHeY1fyesvLXFBO5fyq+IQ3r6uylPFbFdve6DxN0 gZhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=uieWWXObBu3LyphC84gmkcfkpWgruCSjhaDj1PB8Ksc=; b=u1qywZABOuAWP6Da0iXMu24PGKqUJklaHvUhsvobCkIrhZZD64LTqEvZqXrANb48j7 AXTAZ8NFDgbvXO80EZmdilAaUuuq299K5NYTKBe80NzJARe2kYxZ0UaIliM4+OathypJ VZ2GVn5NQR2IKQZu2Rokobf5Q39oXpd9LjzT6/CovdBXpGPL3Bey3dvCA8DnPKc5mMBZ B9tOGU8kUZlTITXQFnEG+XIpFhvDmNKR9xvIweSFSGehcG2uMvZ2cz5IXpLgsgFLp6YL tLeqqX3PJdLkWAb9HMJvod/gbSl648uLaD1w7AOgDu+5S8QziGU3lfQHMMi9/vkViltq CNLg== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id d22-20020aa7ce16000000b0050db7e5fdd4si15042890edv.245.2023.05.17.03.24.01; Wed, 17 May 2023 03:24:01 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 878DB68C1B3; Wed, 17 May 2023 13:21:13 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0868268C14F for ; Wed, 17 May 2023 13:20:53 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 141152406CB for ; Wed, 17 May 2023 12:20:51 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id ZAKJtxAWvgjr for ; Wed, 17 May 2023 12:20:47 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id E16C92404F8 for ; Wed, 17 May 2023 12:20:45 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 9085B3A1251 for ; Wed, 17 May 2023 12:20:39 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 May 2023 12:19:58 +0200 Message-Id: <20230517102029.541-5-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517102029.541-1-anton@khirnov.net> References: <20230517102029.541-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 05/36] fftools/ffmpeg_filter: make sure pkt_duration matches duration 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 5Do2eYHveIT7 Otherwise the two values might get desynchronized and lavfi can prefer the wrong one. --- fftools/ffmpeg_filter.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 95ffa0f087..274eefe11c 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -1622,6 +1622,11 @@ int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame, int keep_reference) frame->pts = av_rescale_q(frame->pts, frame->time_base, ifp->time_base); frame->duration = av_rescale_q(frame->duration, frame->time_base, ifp->time_base); frame->time_base = ifp->time_base; +#if LIBAVUTIL_VERSION_MAJOR < 59 + AV_NOWARN_DEPRECATED( + frame->pkt_duration = frame->duration; + ) +#endif ret = av_buffersrc_add_frame_flags(ifilter->filter, frame, AV_BUFFERSRC_FLAG_PUSH); From patchwork Wed May 17 10:19:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41657 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1077852pzb; Wed, 17 May 2023 03:21:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7C7UUyW3zjss3dRCq/h4on03bdSDW4AS040fC2maoALGmcDelmFxv5XmZqKv5WNeLawcR8 X-Received: by 2002:aa7:da95:0:b0:50b:c456:a72a with SMTP id q21-20020aa7da95000000b0050bc456a72amr1583019eds.19.1684318867360; Wed, 17 May 2023 03:21:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684318867; cv=none; d=google.com; s=arc-20160816; b=UHsM04jWf2dz8gbPbq7+jor9ZKMzNlicSap0J/NQ+LtYe8wO0V0/kJP6un7H3g/y0k TFYcCUJZQTytZ2fCZBfSM1fpNjawH61Wl54O/i6zifvq1Esx4iaopLxQpIhIXPnX7vEJ xvk9CDS37w3wYlUl8U4FoT8Osl/Nf1aqRzY5ODa3LXcBOdEQM6u6lOOu2o6/HLdsm6sC OsVq4wM0EzFeTFRn7ChPz0xYa6Jbxuel7EJAYnSM5nGFrDGPMOyOBzdX8Fu9UwV5uvBH temqLfVtshFelSca25TC6Esroz1GH2Xd+2IAYydeCwHm0YdG9h2ZBaQPVi969UnQMIyD xFhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=CQC+8Kd3p/sDvAYMtMfHZJXChO11U2inZT0t8VxtZxA=; b=Hx4eKtaGkE1gZNeeGXI/OOZIwmOM3OCKELiuZmD5MaAfR53+U+lzSymANqpxDNkjcI v+WErfYAMEdQ867kJXWZsFMfHjgxvQAVBKupu7c2r0dZwExeCtBkQ4eXw3cqaUV6E77K m6UQeG3GxqWkZa790n9DSXKCetIYWAkRjfgi5bsdAdpnnFBBF5RsafCed/uXhoAl3e6i BLJJd79gab/XBoTUIMgIrWPxS9VKkWXnjGwuAuJkcMnepUMgVam/aGuRE+KXrXvplV9E YclXHUvaUS87EXWMfGUN26gM3UmHWN3SvPE9CzhSR3sLFAnc1Am2MElZZXp9ifpKm67Y JqrA== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id b16-20020aa7df90000000b0050bc6d73961si15022043edy.129.2023.05.17.03.21.07; Wed, 17 May 2023 03:21:07 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 018DA68C116; Wed, 17 May 2023 13:20:54 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3683868BF17 for ; Wed, 17 May 2023 13:20:47 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id F33BE2404EC for ; Wed, 17 May 2023 12:20:46 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id KU8ApxtExpDy for ; Wed, 17 May 2023 12:20:46 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id DF62F2404F5 for ; Wed, 17 May 2023 12:20:45 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 9B4603A1267 for ; Wed, 17 May 2023 12:20:39 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 May 2023 12:19:59 +0200 Message-Id: <20230517102029.541-6-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517102029.541-1-anton@khirnov.net> References: <20230517102029.541-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 06/36] fftools/ffmpeg: rework applying input -r 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: GmNllAkDeadt Do not use a separate counter for CFR timestamps forced with -r used as an input option. Set durations properly and let estimation code do the rest. --- fftools/ffmpeg.c | 10 +++++++--- fftools/ffmpeg.h | 4 ---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 9e5e56e9e7..e368f5a148 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -985,7 +985,7 @@ static int64_t video_duration_estimate(const InputStream *ist, const AVFrame *fr // durations, then this should be simplified. // prefer frame duration for containers with timestamps - if (frame->duration > 0 && !ifile->format_nots) + if (frame->duration > 0 && (!ifile->format_nots || ist->framerate.num)) return frame->duration; if (ist->dec_ctx->framerate.den && ist->dec_ctx->framerate.num) { @@ -1090,8 +1090,12 @@ static int decode_video(InputStream *ist, const AVPacket *pkt, int *got_output, frame->pts = frame->best_effort_timestamp; - if (ist->framerate.num) - frame->pts = ist->cfr_next_pts++; + // forced fixed framerate + if (ist->framerate.num) { + frame->pts = AV_NOPTS_VALUE; + frame->duration = 1; + frame->time_base = av_inv_q(ist->framerate); + } // no timestamp available - extrapolate from previous frame duration if (frame->pts == AV_NOPTS_VALUE) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index f88792d7eb..3c7991c73a 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -372,10 +372,6 @@ typedef struct InputStream { int64_t filter_in_rescale_delta_last; - // when forcing constant input framerate through -r, - // this contains the pts that will be given to the next decoded frame - int64_t cfr_next_pts; - int64_t nb_samples; /* number of samples in the last decoded audio frame before looping */ AVDictionary *decoder_opts; From patchwork Wed May 17 10:20:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41669 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1078739pzb; Wed, 17 May 2023 03:22:50 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ59MNgl743pdO15POZ4Tq2iYvib6KCWmwx+KWABJ3uBq8cdvF2JK+QUlBMHSa4Mq3+o29Qu X-Received: by 2002:a17:907:3606:b0:961:800b:3f57 with SMTP id bk6-20020a170907360600b00961800b3f57mr35936244ejc.77.1684318970603; Wed, 17 May 2023 03:22:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684318970; cv=none; d=google.com; s=arc-20160816; b=Ptbn9Wthn2lU1bLwUjm4oDyDq/TKMatGXsZFQQv47447SdVNJn4MFilOqevZpldpHG zlSOsOvanXzWD+KQuJsAgTp9/63K2GWtiiFhnKNe2YTzVf/5oYf6/IPRHOpoXhSB1NqP 25Ihf9MhmxJ1RYBD6lG0pM0zopqU2EDZZfPRT2yn5yCR6lFV10nVAsXzyr6PKT+J6R3L Z4gYCPaG1hmZ7zEIpIrFdh+opc3fNVlAcBMhE63BIAbH03gCc2BJ/iB5PRZw5NGSuARr QpoPjnMzbheq5dT6CpPxPzY58sg0SD2GbZ6SOkyQaCJmzWRtsZDKH+n3KWehWeJnCJz0 7CKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=HPkNYegtPKyYqchSSLBaOvtG7pJm5LThDzL3vLN10no=; b=rDY5M0TbNzVKyh3tnUYAqk56XdZXvVzJRMrt6LBrgjDSGcEugTkjp6Ha8BE/BV9fSb XmUkmBCV903F6u0fjs7xDLGODxJKDRMwSCmcWxxH2FGx7jpbg6ZhHmAxXosYWefxR4Ye Tb9t7HyPpfownRdejVkSqiWsOK6Ki/rZGP+Za+UxRDsFWXLsCvD5/vuUsl3YraUF3YJD c29PBhmQEdUIZwAZ3Z8yas0D/y6ZX4Qcl1SjAMI1KIqqKAxur0A+/ybvtMdheTe/FNDx +PRDgU+2lKlxI149foL/VG73K7DAfMyiMm78nADHzigLJjGBVj/KMaXtCZ52m11dgiTy b3rQ== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id jw19-20020a17090776b300b009591dd6c71esi15838430ejc.896.2023.05.17.03.22.50; Wed, 17 May 2023 03:22:50 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BEE3768C168; Wed, 17 May 2023 13:21:05 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 76B3B68C13C for ; Wed, 17 May 2023 13:20:52 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id E19772405EC for ; Wed, 17 May 2023 12:20:50 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id vnhINEK7hZ2i for ; Wed, 17 May 2023 12:20:50 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 06A412406CB for ; Wed, 17 May 2023 12:20:46 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id A60AB3A1506 for ; Wed, 17 May 2023 12:20:39 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 May 2023 12:20:00 +0200 Message-Id: <20230517102029.541-7-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517102029.541-1-anton@khirnov.net> References: <20230517102029.541-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 07/36] tests/fate/ffmpeg: move a misplaced line 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: Rms+NjwYDrsb --- tests/fate/ffmpeg.mak | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/fate/ffmpeg.mak b/tests/fate/ffmpeg.mak index 0f33c2a0ed..892624e523 100644 --- a/tests/fate/ffmpeg.mak +++ b/tests/fate/ffmpeg.mak @@ -190,6 +190,7 @@ fate-copy-shortest1: CMD = framemd5 -auto_conversion_filters -fflags +bitexact - fate-copy-shortest2: CMD = framemd5 -auto_conversion_filters -fflags +bitexact -flags +bitexact -f lavfi -i "sine=3000:d=10" -i $(TARGET_PATH)/tests/data/audio_shorter_than_video.nut -filter_complex "[0:a:0][1:a:0]amix=inputs=2[audio]" -map 1:v:0 -map "[audio]" -fflags +bitexact -flags +bitexact -c:v copy -c:a ac3_fixed -shortest fate-streamcopy: $(FATE_STREAMCOPY-yes) +FATE_SAMPLES_FFMPEG-yes += $(FATE_STREAMCOPY-yes) FATE_SAMPLES_FFMPEG-$(call TRANSCODE, RAWVIDEO, MATROSKA, MOV_DEMUXER QTRLE_DECODER) += fate-rgb24-mkv fate-rgb24-mkv: CMD = transcode "mov" $(TARGET_SAMPLES)/qtrle/aletrek-rle.mov\ @@ -218,8 +219,6 @@ fate-ffmpeg-bsf-remove-e: CMD = transcode "mpeg" $(TARGET_SAMPLES)/mpeg2/matrixb FATE_SAMPLES_FFMPEG-$(call DEMMUX, APNG, FRAMECRC, SETTS_BSF PIPE_PROTOCOL) += fate-ffmpeg-setts-bsf fate-ffmpeg-setts-bsf: CMD = framecrc -i $(TARGET_SAMPLES)/apng/clock.png -c:v copy -bsf:v "setts=duration=if(eq(NEXT_PTS\,NOPTS)\,PREV_OUTDURATION\,(NEXT_PTS-PTS)/2):ts=PTS/2" -fflags +bitexact -FATE_SAMPLES_FFMPEG-yes += $(FATE_STREAMCOPY-yes) - FATE_TIME_BASE-$(call PARSERDEMDEC, MPEGVIDEO, MPEGPS, MPEG2VIDEO, MPEGVIDEO_DEMUXER MXF_MUXER) += fate-time_base fate-time_base: CMD = md5 -i $(TARGET_SAMPLES)/mpeg2/dvd_single_frame.vob -an -sn -c:v copy -r 25 -time_base 1001:30000 -fflags +bitexact -f mxf From patchwork Wed May 17 10:20:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41662 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1078221pzb; Wed, 17 May 2023 03:21:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ558iX8CeGm+M9b4sUko6HQrflu1ydkiawHoNXnzR+JuvN5lK32+o7bWXNfxcQVtG80/BXc X-Received: by 2002:a17:907:9454:b0:94e:54ec:1a10 with SMTP id dl20-20020a170907945400b0094e54ec1a10mr36115125ejc.29.1684318908278; Wed, 17 May 2023 03:21:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684318908; cv=none; d=google.com; s=arc-20160816; b=x/E719/g8mv9PfwrLjdxEvckurbNKYpQxmeCok8BxhLh8OeCLLjdq6BaqZ8xjxiFwR cJiDleKN1I1bgch47awodMLXGNUdfkusYhySZe0RoWClA1nQpw2VDy43uuHDae4CPCii DuY6Frvy8DIDUTwuKIGP633RS7OZu0t/unHwEmMATSfUfySfrFZNW2so3FYd24m2ZhZP VUMR1etutg60rottUW486jhzcFb0ZJhcqsISDfrkJwFB/MkYkj8gaSdcy4dqeIDJ99kc NHPLZkNKYLjXrDpRgXi5M4LbUxd+JRKLdMZ4Gj91c7u2KfoQ1eqpRIWUlGRdZ4CT1n6B 4Hwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=/C9eAuWw/lGBGc+cBRz3LAh/nJ91iRMxR3cEUxxQs+U=; b=hCUzTg4iUUSMThMjOD+xp/6dlbiisqGpv0MGR9R492Xx3TcitszTU41msPH11bG9pm P52yTWOKUInXzeLNweBwU5hGZpB1Ocd9UQ3L90nmcblf4HAHm1odWCmSTiN2dho5LE9n dnTZp4mCWUJMDoEodphKGxsD/y1WBxaY0rJ+qGbw2lAVr9iWYrVOVVZTDQ4GVa4ld63G 8KYFJLPWLhBXi4ws4TBjbUwXtWRXBPqVq1KdNlgKRUtm5/P96vUEx3/NPBVp4kg0lAZ1 SuAAfDPOzHcn4U5T2UVPBtATgqca5iF+HeoQTH0osPALZnwnzQ8HHQwFhiftuEfsy5Ey OhdA== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id sa27-20020a1709076d1b00b009661e745104si20091006ejc.30.2023.05.17.03.21.47; Wed, 17 May 2023 03:21:48 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CFBD168C14D; Wed, 17 May 2023 13:20:58 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2670868C10F for ; Wed, 17 May 2023 13:20:52 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 07CCA240591 for ; Wed, 17 May 2023 12:20:49 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id fPJ1q-WG9Mf9 for ; Wed, 17 May 2023 12:20:48 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id E6BF02405B5 for ; Wed, 17 May 2023 12:20:45 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id B0E983A154F for ; Wed, 17 May 2023 12:20:39 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 May 2023 12:20:01 +0200 Message-Id: <20230517102029.541-8-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517102029.541-1-anton@khirnov.net> References: <20230517102029.541-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 08/36] tests/fate/ffmpeg: add a test for input -r option 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: fDQm/hWY7tQl --- tests/fate/ffmpeg.mak | 4 ++++ tests/ref/fate/ffmpeg-input-r | 12 ++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 tests/ref/fate/ffmpeg-input-r diff --git a/tests/fate/ffmpeg.mak b/tests/fate/ffmpeg.mak index 892624e523..aca949176a 100644 --- a/tests/fate/ffmpeg.mak +++ b/tests/fate/ffmpeg.mak @@ -223,3 +223,7 @@ FATE_TIME_BASE-$(call PARSERDEMDEC, MPEGVIDEO, MPEGPS, MPEG2VIDEO, MPEGVIDEO_DEM fate-time_base: CMD = md5 -i $(TARGET_SAMPLES)/mpeg2/dvd_single_frame.vob -an -sn -c:v copy -r 25 -time_base 1001:30000 -fflags +bitexact -f mxf FATE_SAMPLES_FFMPEG-yes += $(FATE_TIME_BASE-yes) + +# test -r used as an input option +fate-ffmpeg-input-r: CMD = framecrc -r 27 -i $(TARGET_SAMPLES)/mpeg2/sony-ct3.bs +FATE_SAMPLES_FFMPEG-$(call FRAMECRC, MPEGVIDEO, MPEG2VIDEO) += fate-ffmpeg-input-r diff --git a/tests/ref/fate/ffmpeg-input-r b/tests/ref/fate/ffmpeg-input-r new file mode 100644 index 0000000000..d11f870b10 --- /dev/null +++ b/tests/ref/fate/ffmpeg-input-r @@ -0,0 +1,12 @@ +#tb 0: 1/27 +#media_type 0: video +#codec_id 0: rawvideo +#dimensions 0: 720x480 +#sar 0: 8/9 +0, 0, 0, 1, 518400, 0xc1866f5f +0, 1, 1, 1, 518400, 0x9ba32764 +0, 2, 2, 1, 518400, 0xa9031bb8 +0, 3, 3, 1, 518400, 0x5e2c3502 +0, 4, 4, 1, 518400, 0xe860027a +0, 5, 5, 1, 518400, 0xa9152430 +0, 6, 6, 1, 518400, 0xb98dd9f7 From patchwork Wed May 17 10:20:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41667 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1078617pzb; Wed, 17 May 2023 03:22:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5rxLmkD1ior4XKlNeQddww1Q409SYhRisjfkIFddwHdRwrY0PzGgJfdaBkmcmHxEHb7Ds7 X-Received: by 2002:a17:907:60d2:b0:966:1284:e3e with SMTP id hv18-20020a17090760d200b0096612840e3emr34471830ejc.9.1684318953345; Wed, 17 May 2023 03:22:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684318953; cv=none; d=google.com; s=arc-20160816; b=QVVCEsajC4DM9+30w7D3XP7Jwpi5i5Hm2CBqmVKugUglN1aO9ZmczMOgTl33p46DW9 JKAMbMXsm5n6bf4/A6o+7Yr49Kx6erAISZFfqA4K0f5fFSRrfOE0qP4ZaMDtpzZryTcW KMcxvpDAZ2W3z9KmwWWp47EuciDZz2mHIJMJn0kK4G2gL1aW2x23akHjR0bXqw64UeE8 aypTlaMi+rZilnWFIMwmM+FPPMVSuW6Q0pGtsCQadxeDAiO1LuoVYrB0cs7FaRcHzCs3 T9boEkY7PD0cMHrC9iB+BnIXOuLjQe56+CEqxLWgfKReDx5wF/63qJrO3sNIOjnwnGKh kRCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=H4DtcINqtUkkHplKqHm6iXlGMrOHGqvlflhSkDF11ho=; b=ASqjsxkR+9d2IfYqWImLdB8e0G/vLrsXDi/D6/1wTkHBwyIsFwTM9Lv6mhha8C+d8J +th0m53r1IGWf+YYGaCqv/G7KIgLCbkCCilJuvCoO2U0nl3tGxC0KM0IEhziX4npeWVm PPD2JfwnrPJoHcVuj15Wtx3A54B1s+bNr6R6HWA3GnOw6fm+DHj4Xk0SoCEL2oWfDiUH YxjuPQHpgq6b0afQpmDJwtyhC5Pun1ALI+zFiUsp1iYthrWzZGj3cS+HSpjuzJ3LyYUg Jq1glX4gqVu4boS07zk9Og08zdgYKcUcH03jCHsf4HHYXAnrghJBewWcENE5pekAhPzK pwLA== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id fj12-20020a1709069c8c00b0096ac6840afesi9035816ejc.169.2023.05.17.03.22.32; Wed, 17 May 2023 03:22:33 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B161068C140; Wed, 17 May 2023 13:21:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7440E68C13A for ; Wed, 17 May 2023 13:20:57 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 0C59D2404EE for ; Wed, 17 May 2023 12:20:53 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id ENX9DangzMux for ; Wed, 17 May 2023 12:20:52 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 2E5F0240706 for ; Wed, 17 May 2023 12:20:46 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id BCF3A3A1571 for ; Wed, 17 May 2023 12:20:39 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 May 2023 12:20:02 +0200 Message-Id: <20230517102029.541-9-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517102029.541-1-anton@khirnov.net> References: <20230517102029.541-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 09/36] fftools/ffmpeg_filter: split finding an unused stream into a function 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: ntEXcceMnPYK Avoids filtering code from digging in demuxer internals. --- fftools/ffmpeg.h | 5 +++++ fftools/ffmpeg_demux.c | 10 ++++++++++ fftools/ffmpeg_filter.c | 8 +------- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 3c7991c73a..9cb7198dfd 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -882,6 +882,11 @@ int ifile_get_packet(InputFile *f, AVPacket **pkt); void ist_output_add(InputStream *ist, OutputStream *ost); void ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple); +/** + * Find an unused input stream of given type. + */ +InputStream *ist_find_unused(enum AVMediaType type); + /* iterate over all input streams in all input files; * pass NULL to start iteration */ InputStream *ist_iter(InputStream *prev); diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 0a37cc7c25..b93e171037 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -130,6 +130,16 @@ static Demuxer *demuxer_from_ifile(InputFile *f) return (Demuxer*)f; } +InputStream *ist_find_unused(enum AVMediaType type) +{ + for (InputStream *ist = ist_iter(NULL); ist; ist = ist_iter(ist)) { + if (ist->par->codec_type == type && ist->discard && + ist->user_set_discard != AVDISCARD_ALL) + return ist; + } + return NULL; +} + static void report_new_stream(Demuxer *d, const AVPacket *pkt) { AVStream *st = d->f.ctx->streams[pkt->stream_index]; diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 274eefe11c..8cc76209d0 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -420,13 +420,7 @@ static void init_input_filter(FilterGraph *fg, AVFilterInOut *in) exit_program(1); } } else { - /* find the first unused stream of corresponding type */ - for (ist = ist_iter(NULL); ist; ist = ist_iter(ist)) { - if (ist->user_set_discard == AVDISCARD_ALL) - continue; - if (ist->dec_ctx->codec_type == type && ist->discard) - break; - } + ist = ist_find_unused(type); if (!ist) { av_log(NULL, AV_LOG_FATAL, "Cannot find a matching stream for " "unlabeled input pad %d on filter %s\n", in->pad_idx, From patchwork Wed May 17 10:20:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41668 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1078680pzb; Wed, 17 May 2023 03:22:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5cNarn146rRkyF1PEaB2BJsmnyi2RnNml8KiH5LPwBfTOyf++tAWky5osCUZY+n6KZ9wLl X-Received: by 2002:a17:907:9449:b0:94f:2efa:a3eb with SMTP id dl9-20020a170907944900b0094f2efaa3ebmr37016760ejc.33.1684318961772; Wed, 17 May 2023 03:22:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684318961; cv=none; d=google.com; s=arc-20160816; b=Q1Ge19f2UIRvYnBOtEZamQ0w3F/6QIal7FaX1TbshTuASC9qt9skVebylh3q/XNWeA Dt/qjd9Q51DZHdUh9tu13wlW29Ijc6J6gFGH1RU74RbE2FV/nTaHFWAvu11/jS3vnyHK h4h4cU2wCPazG0E1LtOJ1YH7KDSGm1iK7WUeMmF6b5yJPwoo31JQ98+uTJH/2NntMrs6 sztJd/GfmpFRfeYjzTcxEm+Ers9vcEIeojPm/Ft1nHsn6p7jOXbEvppUAioTAa8ZK+7N vs3Za6Qg2g7HpGE5MSKx6/m7vlTaZZB5dNZZTWQBTN0xMi/ZPcdaaVXgQVkDkSMYTS5Q odeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=nJWwRmykfuG5bqfrCcNztRIobrnr9zajajawXCIV1bU=; b=JMmkZ48YllJzckaPZN6mIsuzLi8aTBE542Gt9rKMqbTY98TglhPD0/4pfgABNaZWYX VDObb+SYr0kmLx3A3rZiYj7PSO5xrb48aFbImpjbCHXRp3nkthgLuWkzgyfLPjhVD3L+ ZIG2QHcoEPuvPkAq7NQ0hOwkOeK+o90O9Mr8//BSS46hTbbiUiJiIaNR2JmunLaISTeo 1qsDTk2pzr8spUHWkRiEKMo3QKJs9A5vlWCplNBRLH5vC6NMm8KK5hXiVOH7E/B0SulF cJ3b74M6ZZ/hqh0eKadkFtTwY1ZMwttopSH0sugdCMvY6iUL8+/eyARGy3uHA4CL6TfT wljQ== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id hr34-20020a1709073fa200b00969ea55d647si18190123ejc.92.2023.05.17.03.22.41; Wed, 17 May 2023 03:22:41 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C37D068C13A; Wed, 17 May 2023 13:21:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7646268C13B for ; Wed, 17 May 2023 13:20:52 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 4D5B32406CA for ; Wed, 17 May 2023 12:20:50 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id qjdurX8aYitl for ; Wed, 17 May 2023 12:20:49 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id F28DA2405EC for ; Wed, 17 May 2023 12:20:45 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id C8AD83A1594 for ; Wed, 17 May 2023 12:20:39 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 May 2023 12:20:03 +0200 Message-Id: <20230517102029.541-10-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517102029.541-1-anton@khirnov.net> References: <20230517102029.541-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 10/36] fftools/ffmpeg: return error codes from ist_*_add() 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: +9puwrpggyrG Will be useful in future commits. --- fftools/ffmpeg.h | 4 ++-- fftools/ffmpeg_demux.c | 26 +++++++++++++++++++------- fftools/ffmpeg_filter.c | 15 ++++++++++++--- fftools/ffmpeg_mux_init.c | 10 ++++++++-- 4 files changed, 41 insertions(+), 14 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 9cb7198dfd..189454d629 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -879,8 +879,8 @@ void ifile_close(InputFile **f); */ int ifile_get_packet(InputFile *f, AVPacket **pkt); -void ist_output_add(InputStream *ist, OutputStream *ost); -void ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple); +int ist_output_add(InputStream *ist, OutputStream *ost); +int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple); /** * Find an unused input stream of given type. diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index b93e171037..ae2133bdbf 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -844,7 +844,7 @@ void ifile_close(InputFile **pf) av_freep(pf); } -static void ist_use(InputStream *ist, int decoding_needed) +static int ist_use(InputStream *ist, int decoding_needed) { DemuxStream *ds = ds_from_ist(ist); @@ -856,23 +856,33 @@ static void ist_use(InputStream *ist, int decoding_needed) if (decoding_needed && !avcodec_is_open(ist->dec_ctx)) { int ret = dec_open(ist); if (ret < 0) - report_and_exit(ret); + return ret; } + + return 0; } -void ist_output_add(InputStream *ist, OutputStream *ost) +int ist_output_add(InputStream *ist, OutputStream *ost) { - ist_use(ist, ost->enc ? DECODING_FOR_OST : 0); + int ret; + + ret = ist_use(ist, ost->enc ? DECODING_FOR_OST : 0); + if (ret < 0) + return ret; GROW_ARRAY(ist->outputs, ist->nb_outputs); ist->outputs[ist->nb_outputs - 1] = ost; + + return 0; } -void ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple) +int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple) { int ret; - ist_use(ist, is_simple ? DECODING_FOR_OST : DECODING_FOR_FILTER); + ret = ist_use(ist, is_simple ? DECODING_FOR_OST : DECODING_FOR_FILTER); + if (ret < 0) + return ret; GROW_ARRAY(ist->filters, ist->nb_filters); ist->filters[ist->nb_filters - 1] = ifilter; @@ -880,7 +890,9 @@ void ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple) // initialize fallback parameters for filtering ret = ifilter_parameters_from_dec(ifilter, ist->dec_ctx); if (ret < 0) - report_and_exit(ret); + return ret; + + return 0; } static const AVCodec *choose_decoder(const OptionsContext *o, AVFormatContext *s, AVStream *st, diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 8cc76209d0..ca43b4803a 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -334,6 +334,7 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost) FilterGraph *fg; OutputFilter *ofilter; InputFilter *ifilter; + int ret; fg = fg_create(NULL); if (!fg) @@ -347,7 +348,9 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost) ifilter = ifilter_alloc(fg); ifilter->ist = ist; - ist_filter_add(ist, ifilter, 1); + ret = ist_filter_add(ist, ifilter, 1); + if (ret < 0) + return ret; return 0; } @@ -375,7 +378,7 @@ static void init_input_filter(FilterGraph *fg, AVFilterInOut *in) InputStream *ist = NULL; enum AVMediaType type = avfilter_pad_get_type(in->filter_ctx->input_pads, in->pad_idx); InputFilter *ifilter; - int i; + int i, ret; // TODO: support other filter types if (type != AVMEDIA_TYPE_VIDEO && type != AVMEDIA_TYPE_AUDIO) { @@ -435,7 +438,13 @@ static void init_input_filter(FilterGraph *fg, AVFilterInOut *in) ifilter->type = ist->st->codecpar->codec_type; ifilter->name = describe_filter_link(fg, in, 1); - ist_filter_add(ist, ifilter, 0); + ret = ist_filter_add(ist, ifilter, 0); + if (ret < 0) { + av_log(NULL, AV_LOG_ERROR, + "Error binding an input stream to complex filtergraph input %s.\n", + in->name ? in->name : ""); + exit_program(1); + } } static int read_binary(const char *path, uint8_t **data, int *len) diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 2c0e2faf4a..b73791acee 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -1225,8 +1225,14 @@ static OutputStream *ost_add(Muxer *mux, const OptionsContext *o, "Error initializing a simple filtergraph\n"); exit_program(1); } - } else - ist_output_add(ost->ist, ost); + } else { + ret = ist_output_add(ost->ist, ost); + if (ret < 0) { + av_log(ost, AV_LOG_ERROR, + "Error binding an input stream\n"); + exit_program(1); + } + } } if (ost->ist && !ost->enc) { From patchwork Wed May 17 10:20:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41666 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1078543pzb; Wed, 17 May 2023 03:22:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7wCKXdV566TNYqaW/ySWJYjcvYNt533P0cAGLsbMx5/tZLZuzEOAUt3iFUaJ+i1NGnBU4N X-Received: by 2002:a17:907:8a07:b0:968:c2c2:3a21 with SMTP id sc7-20020a1709078a0700b00968c2c23a21mr31782228ejc.12.1684318944684; Wed, 17 May 2023 03:22:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684318944; cv=none; d=google.com; s=arc-20160816; b=LAB0jEdY6QYIpZcE8UXRBZbnrn1PeCV97Lz/qGS9m+53o+8/en1gK3ay58qISnCHDM RHrP6e17nWPFZRs/weu6zKJHalAJV7zq0hnJhlcTTPohklnAiGtvmb5dV5NcTPCJpZEo i4C3kF/BV2/2T9ZMTWF5YIa6nIPJRNAzAd/C4aYTko5hi2ZwIYz7zPk/E2woKT8VYQDM qhuslC4bOTh4RxaXCmhxAcohJz00cr6ClukO39kiXixEV0SoU6QY4C7liDeAtUw1Fqj5 pvNqn6yy2Sj1Ilg9Rcw1eTlgJcSlOxxHu+SbaNjXykwrBn2XPEgjB2rHksu4t7LiPyY/ mqgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=2I3Cue05RdwPdDC17UPYh+8xGmGUSKLb04anGtyGVxw=; b=tQdWVghLSGRsORJ6G7aNfSRqAzL1inzmMaOY8SZCdDKreoVN9/gD27nzqNSUBNbAA2 m+xYydTOk36jA9ZIXi93peA3KatOXOIFQHfdBktsuzIs75aKvxL6pPkc9mAFZaIJ2Rrn WjBgetyb19/27GN/SwgVv307DQdfbzLvHw7hQ9NvMFTV8P/y+opSN49oVhOobQitOlYY 7lhCDbbocd2u3+dt69WtE3JflDf5tbl0Bk1Q91oapRh2/uPaQc0rCcipWeBmPv0SGIqw 55FgMasAMJ15YzY8nsz1q/GaAq2oyQqds4kV3j/c31aOPBp30GPkRjSdbBrPKt9miCV2 cLEg== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id y13-20020a170906070d00b00965d9892ba7si17626427ejb.551.2023.05.17.03.22.24; Wed, 17 May 2023 03:22:24 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B031668C193; Wed, 17 May 2023 13:21:02 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 718CA68C139 for ; Wed, 17 May 2023 13:20:57 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 8FBE7240177 for ; Wed, 17 May 2023 12:20:53 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id QKfwejgm4Ivg for ; Wed, 17 May 2023 12:20:53 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 31FF1240D03 for ; Wed, 17 May 2023 12:20:46 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id D44CE3A163A for ; Wed, 17 May 2023 12:20:39 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 May 2023 12:20:04 +0200 Message-Id: <20230517102029.541-11-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517102029.541-1-anton@khirnov.net> References: <20230517102029.541-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 11/36] fftools/ffmpeg_demux: disallow using disabled input streams 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: +aYRSyCr7196 This is less ad-hoc than checking explicitly in every place that binds an input stream to a filter or output. --- fftools/ffmpeg_demux.c | 6 ++++++ fftools/ffmpeg_filter.c | 5 ----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index ae2133bdbf..df87e0f30a 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -848,6 +848,12 @@ static int ist_use(InputStream *ist, int decoding_needed) { DemuxStream *ds = ds_from_ist(ist); + if (ist->user_set_discard == AVDISCARD_ALL) { + av_log(ist, AV_LOG_ERROR, "Cannot %s a disabled input stream\n", + decoding_needed ? "decode" : "streamcopy"); + return AVERROR(EINVAL); + } + ist->discard = 0; ist->st->discard = ist->user_set_discard; ist->decoding_needed |= decoding_needed; diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index ca43b4803a..2c3e2a96f7 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -417,11 +417,6 @@ static void init_input_filter(FilterGraph *fg, AVFilterInOut *in) exit_program(1); } ist = input_files[file_idx]->streams[st->index]; - if (ist->user_set_discard == AVDISCARD_ALL) { - av_log(NULL, AV_LOG_FATAL, "Stream specifier '%s' in filtergraph description %s " - "matches a disabled input stream.\n", p, fgp->graph_desc); - exit_program(1); - } } else { ist = ist_find_unused(type); if (!ist) { From patchwork Wed May 17 10:20:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41677 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1079455pzb; Wed, 17 May 2023 03:24:10 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7AOe9lPl8Xnuqr6xjVN1iYkHz6B5z922we17/7x4oJQgeR+ZrVlRbDLwtfnOMbKg2inmrW X-Received: by 2002:a17:907:80e:b0:94e:9a73:1637 with SMTP id wv14-20020a170907080e00b0094e9a731637mr33960971ejb.75.1684319050347; Wed, 17 May 2023 03:24:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684319050; cv=none; d=google.com; s=arc-20160816; b=zk95KdV9aN3bZnhVGIRWEgcwhlA/5SaqVp6m+PduHp+AvT6exdFr2kXIvM9UffiY2e ol/RtU5WeYs88/IabUGy/KjozdPu5e+xSzkzkEM+BpqHcuIxWzIU3CBpDrm+rRH+Lumo mFYZdIhy++1kTj3TSQ2T8UKeZi8aFtLklJQOMkCQuHbihNuNqYa/zsxPgy+Y5KVs2BhD vVqo15qp0gOMB8G4OkeEqWc/dkb7AtRea7iw+A9hp86nTMRV7HTRKaJns+aEYpB7UBjc AP86vXOEF5Vws8YrNer+5xOoWerUPnARsFiGQhM7RJBOLftd5W6rjjOa2DS2QzDyDpjE wuaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=OLMHgWkN7NTt5ZjNhX8c1364wRPBKfrXYheLGmpuJp8=; b=IclkSPlg7FRbvoBZV+NRW5G+4ucwgvCRFpTt2MpVSGZsKSqPD/B6RNoWNzpQJVHSc0 DseUcaLQoqDemtBnoaCsPBywp1MsDsJClAdSFlsixtZsVNIOP+WJDkSReQPViVZixp+Q iJ3NpkRcfYPqNhpkLd0FXXPBkeINrbLgEmb/yDqKZzcptBpSuhPMizKjXDU+RAWYam7b fYZcxbY+ozPMNtfOGGJZ63XdGmW5C11YWiV/hGkmgRjNxdDvNtTMd6qfQRXxZsENjsNQ UXvth9CiS1Ehs/7kEQWEET28SQEb2CaEoQgBxTAMRbZFLpfmrQYMLDcjqebGcjcYExQR +cNw== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id rh7-20020a17090720e700b00953842dab75si14229415ejb.818.2023.05.17.03.24.09; Wed, 17 May 2023 03:24:10 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8745F68C1B7; Wed, 17 May 2023 13:21:14 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 090B768C14B for ; Wed, 17 May 2023 13:20:53 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 7BDBA2404F8 for ; Wed, 17 May 2023 12:20:51 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id dtC_5PSPOHEz for ; Wed, 17 May 2023 12:20:50 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 001C22405F9 for ; Wed, 17 May 2023 12:20:46 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id DFDB73A168E for ; Wed, 17 May 2023 12:20:39 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 May 2023 12:20:05 +0200 Message-Id: <20230517102029.541-12-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517102029.541-1-anton@khirnov.net> References: <20230517102029.541-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 12/36] fftools/ffmpeg_filter: only use fallback parameters when necessary 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 3ChCKvIT75c/ With complex filtergraphs it can happen that the filtergraph is unconfigured because some other filter than the one we just got EOF on is missing parameters. Make sure that the fallback parametes for a given input are only used when that input is unconfigured. --- fftools/ffmpeg_filter.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 2c3e2a96f7..8eca0f2cae 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -1521,17 +1521,19 @@ int ifilter_send_eof(InputFilter *ifilter, int64_t pts, AVRational tb) if (ret < 0) return ret; } else { - // the filtergraph was never configured, use the fallback parameters - ifilter->format = ifp->fallback.format; - ifilter->sample_rate = ifp->fallback.sample_rate; - ifilter->width = ifp->fallback.width; - ifilter->height = ifp->fallback.height; - ifilter->sample_aspect_ratio = ifp->fallback.sample_aspect_ratio; - - ret = av_channel_layout_copy(&ifilter->ch_layout, - &ifp->fallback.ch_layout); - if (ret < 0) - return ret; + if (ifilter->format < 0) { + // the filtergraph was never configured, use the fallback parameters + ifilter->format = ifp->fallback.format; + ifilter->sample_rate = ifp->fallback.sample_rate; + ifilter->width = ifp->fallback.width; + ifilter->height = ifp->fallback.height; + ifilter->sample_aspect_ratio = ifp->fallback.sample_aspect_ratio; + + ret = av_channel_layout_copy(&ifilter->ch_layout, + &ifp->fallback.ch_layout); + if (ret < 0) + return ret; + } if (ifilter->format < 0 && (ifilter->type == AVMEDIA_TYPE_AUDIO || ifilter->type == AVMEDIA_TYPE_VIDEO)) { av_log(NULL, AV_LOG_ERROR, "Cannot determine format of input stream %d:%d after EOF\n", ifilter->ist->file_index, ifilter->ist->st->index); From patchwork Wed May 17 10:20:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41663 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1078301pzb; Wed, 17 May 2023 03:21:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6N9LndSqy3E2ePzBsqdmadvkwyUAewDdl2lEijpOaLPvO6o6B3ee79nIMqB+kfJvErkthK X-Received: by 2002:a17:907:9444:b0:966:5730:c3fe with SMTP id dl4-20020a170907944400b009665730c3femr35965873ejc.52.1684318918273; Wed, 17 May 2023 03:21:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684318918; cv=none; d=google.com; s=arc-20160816; b=dxruhE18S5OyajxlPAmJ4IBtJXueaSWs0YZuwiRpv/Y91UkYO3DJLEJui/KJmjTSFR WsS78hhVcr3u4Huudc0UIWNJeNda0O3vFd1QYW6tMWwgWIdcXVriMbOT8Dnrimxfcley dO6wPNipIN1CC2HFRDPJb0xeQxuimc+5JH8zDvkk9DuxuzQr8ScHRI7190rW0lEk+ZGg 45To3x94Lh/tM9gfjIMvu7necZ3ocMyKb5j3xMty9mZAUkb/Eal381V2k4DX9BSoFZm3 mQ3RBqUYeCOpAOB17oSQmG1UrdyLkT+upRgjWpeAYp79SMX96UHMNtFJTtqxKnjfLFOo n2sQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=wazlgPnzUOJwleJt5L0Zo7danGNzH4VkwxWg+zk8x0Y=; b=ja9QSvIqKQ4PBO5h1ByltZCN9DTIZ3kEnv4lSus0WBGG20UAYLTQs5leMJUmLw63BF eNro5kBas7x9rJZd1rPCHc0KvHSlMNxs9xdcK6rVEzRb1P5BmHGoZZVKWrkoH2Nt6V0f dwkCjCTctmysuI3kGYGtwO6LG8TC/GmkrG6t2QuvngzcWYPGjbD+NNuyD6MAegvZ6kya HlqVC60lRyRTLdh2DYlamazcAXq4xx3nFAHofJcaPUXVY8yHzjLptSKPWzpVhtmDOJ3Z T6FhwK2ToFDAxmwfR8bDAPyB8hm9BZ4mLpIbrKocKBbK9be0bh7mB1jxQmMuKb06CJN7 fd6g== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id r8-20020aa7cfc8000000b0050bd1b55099si15154102edy.172.2023.05.17.03.21.57; Wed, 17 May 2023 03:21:58 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BFCE068C163; Wed, 17 May 2023 13:20:59 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2D2F968C12D for ; Wed, 17 May 2023 13:20:52 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 868562405B5 for ; Wed, 17 May 2023 12:20:49 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 0Q_dS6-hcOHI for ; Wed, 17 May 2023 12:20:49 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 009592406CA for ; Wed, 17 May 2023 12:20:46 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id EBC5C3A16B6 for ; Wed, 17 May 2023 12:20:39 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 May 2023 12:20:06 +0200 Message-Id: <20230517102029.541-13-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517102029.541-1-anton@khirnov.net> References: <20230517102029.541-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 13/36] fftools/ffmpeg_filter: try configuring graphs from input EOF 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: eqjwp4lVjwAi When a filtergraph input receives EOF but never saw any input frames, we use the fallback parameters. Currently an attempt to actually configure the filtergraph will happen elsewhere, but there is no reason to postpone this. --- fftools/ffmpeg_filter.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 8eca0f2cae..6323278d15 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -1533,6 +1533,14 @@ int ifilter_send_eof(InputFilter *ifilter, int64_t pts, AVRational tb) &ifp->fallback.ch_layout); if (ret < 0) return ret; + + if (ifilter_has_all_input_formats(ifilter->graph)) { + ret = configure_filtergraph(ifilter->graph); + if (ret < 0) { + av_log(NULL, AV_LOG_ERROR, "Error initializing filters!\n"); + return ret; + } + } } if (ifilter->format < 0 && (ifilter->type == AVMEDIA_TYPE_AUDIO || ifilter->type == AVMEDIA_TYPE_VIDEO)) { From patchwork Wed May 17 10:20:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41680 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1079650pzb; Wed, 17 May 2023 03:24:34 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6dZAyINWetb+u5rpIN6frwIXZyEVF3Y/48a2wwdCLdY58rmYQ+dFKGDEns/3jSjHc3V8Ea X-Received: by 2002:a17:907:94c5:b0:96a:7196:6e2b with SMTP id dn5-20020a17090794c500b0096a71966e2bmr19099862ejc.14.1684319074706; Wed, 17 May 2023 03:24:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684319074; cv=none; d=google.com; s=arc-20160816; b=o68Z6+qFxqNppDnmCtd99aGklZ8N1juh/VRrlbAfqOgNbwrHnNB0TGryCz8hHNFQrr ZXmR5fBRsfWB0vrYo8cx/NBe72WiHTsM4nA8djnZ30RstpBMK53CTW3N+CzAz9Ej/SrO DbzUI/vF+ocK8uwJsL4ZKmNyv3zHu4Nwdqz8okticl3X7VX7bzaS77l3NyRTfTv53pSX U1JwkXepheJFNOB8JINU67gKBH08wCCcVWtHuTfD2cDnFpJY0O5WFfpuJ2/IkavOVDR6 9iPYhbStDCznR7LFCZB6Fw6Q37HIMG6pzJbkITRZsNNnEo94KlvaNiuUOFpcIAtNe5Jk xyWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=oK8Wm98xKxK9ar1y7lIo3juYzstHnSS5g0+lylq0qeQ=; b=vnrhgZO/nYfciUNMxmvrlNEpAkKg6eetrSe28w8czg343Jh+xzoXsOsCIH6yBMCIZI ygpCfDdQdWxM3Yy17WTSqydSahhLOkOLb3aI7DoRMVumOAG+zTel/GRetZJ3q92i1paj wo9KmbncHnm6WpT5RAewXBnRXKBHGn7kuZJNXPGJhpIqV2ESe3KzvkbtFB/9zOMoiMi4 lq9wICZo1Z2APryTiA6dgx4umhc5FD21q6xuDotUVRHqdpMJQKuAZo109HJAK7lvaYtB 7KoJLqpxCXqS9pAprJKRxeZHxY61EerGhKCTwn3H85yXu3bDW6V1EtQZWbLVxDJ/J6qB ASPQ== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id i10-20020a1709064eca00b009659fdd26adsi11336773ejv.105.2023.05.17.03.24.34; Wed, 17 May 2023 03:24:34 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 681FA68C1C8; Wed, 17 May 2023 13:21:17 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8A96968C149 for ; Wed, 17 May 2023 13:20:58 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 48329240177 for ; Wed, 17 May 2023 12:20:58 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id wp6SQq5XtOXc for ; Wed, 17 May 2023 12:20:57 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 63A3E240D25 for ; Wed, 17 May 2023 12:20:46 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 035C83A16DB for ; Wed, 17 May 2023 12:20:40 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 May 2023 12:20:07 +0200 Message-Id: <20230517102029.541-14-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517102029.541-1-anton@khirnov.net> References: <20230517102029.541-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 14/36] fftools/ffmpeg: move ifilter_has_all_input_formats() to ffmpeg_filter 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: g9Y6YITuMJQo That is a more appropriate place for that function. --- fftools/ffmpeg.c | 12 ------------ fftools/ffmpeg_filter.c | 12 ++++++++++++ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index e368f5a148..9d554e2fb0 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -787,18 +787,6 @@ static void check_decode_result(InputStream *ist, int *got_output, int ret) } } -// Filters can be configured only if the formats of all inputs are known. -int ifilter_has_all_input_formats(FilterGraph *fg) -{ - int i; - for (i = 0; i < fg->nb_inputs; i++) { - if (fg->inputs[i]->format < 0 && (fg->inputs[i]->type == AVMEDIA_TYPE_AUDIO || - fg->inputs[i]->type == AVMEDIA_TYPE_VIDEO)) - return 0; - } - return 1; -} - // This does not quite work like avcodec_decode_audio4/avcodec_decode_video2. // There is the following difference: if you got a frame, you must call // it again with pkt=NULL. pkt==NULL is treated differently from pkt->size==0 diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 6323278d15..d85d9e2c67 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -1445,6 +1445,18 @@ static int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *fr return 0; } +// Filters can be configured only if the formats of all inputs are known. +int ifilter_has_all_input_formats(FilterGraph *fg) +{ + int i; + for (i = 0; i < fg->nb_inputs; i++) { + if (fg->inputs[i]->format < 0 && (fg->inputs[i]->type == AVMEDIA_TYPE_AUDIO || + fg->inputs[i]->type == AVMEDIA_TYPE_VIDEO)) + return 0; + } + return 1; +} + int filtergraph_is_simple(FilterGraph *fg) { FilterGraphPriv *fgp = fgp_from_fg(fg); From patchwork Wed May 17 10:20:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41675 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1079278pzb; Wed, 17 May 2023 03:23:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4ueNtxZ7HZVuslVmjVFIP/WE7opp0PLkdpz8R4RMIKbV0Slq21I4Bm0AzOigwuWfhdduTS X-Received: by 2002:aa7:da1a:0:b0:50b:c97f:47bd with SMTP id r26-20020aa7da1a000000b0050bc97f47bdmr1551633eds.30.1684319032050; Wed, 17 May 2023 03:23:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684319032; cv=none; d=google.com; s=arc-20160816; b=O39XVIZgSVGcy2/2q17Qmls+StHITXsiBNcBejzoAdcO73u3y0hNvvYcM8kU3NZuKK g4Wa+UOGMTrwd6z6PQi5XOjXPCHUAnqDpf6MKoswvH9rG1ogocn1bnZ5A5AMaEtAp4I9 oUEBfrh21zs/uSo6ocCdBfLBzutqrT668btbhDA4crhhLLHJ2EDZoxVIH4zSg7E8sezh 9tM62VWU7tH5iG4FqYpQ6bbpqOoa2P0hJIQuY9WTUpJeG6LSDbOlqrnT4WSjcMF2cG1j lqxd2lcYQBZWJG28fPQ6U8cZu42f9Q7183Aidjb4y4U8M3SnBm1rzDXWgpVHhTcoJBl+ WsuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=snSYXDKOx60GZQIXAgi0R6iy7CmZWNUirn1kGkEdEUg=; b=yBDBGCY37E19km0kUvd/m8h7IYFwBvsjh0thlDVw9tZkwPW2XxjP8ZBU8muj0OzaSG EL6Ptmqsurj2ZUbmIsqhJuJju6wtq2JzwUNdfir6L4XhStUUuWuqoPvFKhd8WI3NMJ20 lDlmwxnFzpodl7TFTdD66BWRrehpyCj5NrsgYJ4qzxTAAYWtYITyt+/1cbKSEx4TC8o7 ZpNZGWHuRJx9sb1LedvEFE4Xek3208PBTF6VXFRKxpU49H8xvNouwj9Gi4xipeHYLIPJ wP4llOkJfuoCkc5BuCn4fnuXJD/PR+Qa2gqLewPDH/S1NyPVsdSFLzBTYddvjGdJ+veG yZew== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id p1-20020a056402044100b00510d729d5c1si441242edw.491.2023.05.17.03.23.51; Wed, 17 May 2023 03:23:52 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7A9CB68C1AD; Wed, 17 May 2023 13:21:12 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EE04C68C131 for ; Wed, 17 May 2023 13:20:57 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id BB27D2404EE for ; Wed, 17 May 2023 12:20:57 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id FpI5rD75bDpA for ; Wed, 17 May 2023 12:20:56 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 48833240D1D for ; Wed, 17 May 2023 12:20:46 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 0F07E3A1758 for ; Wed, 17 May 2023 12:20:40 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 May 2023 12:20:08 +0200 Message-Id: <20230517102029.541-15-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517102029.541-1-anton@khirnov.net> References: <20230517102029.541-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 15/36] fftools/ffmpeg_filter: make input filter configured parameters private 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: z7x5DxBt2hUT They are not used outside of ffmpeg_filter. --- fftools/ffmpeg.h | 9 ----- fftools/ffmpeg_filter.c | 89 +++++++++++++++++++++++------------------ 2 files changed, 50 insertions(+), 48 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 189454d629..9cb9f35bc2 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -283,15 +283,6 @@ typedef struct InputFilter { struct FilterGraph *graph; uint8_t *name; enum AVMediaType type; // AVMEDIA_TYPE_SUBTITLE for sub2video - - // parameters configured for this input - int format; - - int width, height; - AVRational sample_aspect_ratio; - - int sample_rate; - AVChannelLayout ch_layout; } InputFilter; typedef struct OutputFilter { diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index d85d9e2c67..12e756e489 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -60,6 +60,15 @@ typedef struct InputFilterPriv { int eof; + // parameters configured for this input + int format; + + int width, height; + AVRational sample_aspect_ratio; + + int sample_rate; + AVChannelLayout ch_layout; + AVRational time_base; AVFifo *frame_queue; @@ -245,12 +254,12 @@ static InputFilter *ifilter_alloc(FilterGraph *fg) InputFilter *ifilter = &ifp->ifilter; ifilter->graph = fg; - ifilter->format = -1; ifp->frame = av_frame_alloc(); if (!ifp->frame) report_and_exit(AVERROR(ENOMEM)); + ifp->format = -1; ifp->fallback.format = -1; ifp->frame_queue = av_fifo_alloc2(8, sizeof(AVFrame*), AV_FIFO_FLAG_AUTO_GROW); @@ -956,14 +965,15 @@ void check_filter_outputs(void) static int sub2video_prepare(InputStream *ist, InputFilter *ifilter) { + InputFilterPriv *ifp = ifp_from_ifilter(ifilter); AVFormatContext *avf = input_files[ist->file_index]->ctx; int i, w, h; /* Compute the size of the canvas for the subtitles stream. If the subtitles codecpar has set a size, use it. Otherwise use the maximum dimensions of the video streams in the same file. */ - w = ifilter->width; - h = ifilter->height; + w = ifp->width; + h = ifp->height; if (!(w && h)) { for (i = 0; i < avf->nb_streams; i++) { if (avf->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { @@ -977,15 +987,15 @@ static int sub2video_prepare(InputStream *ist, InputFilter *ifilter) } av_log(avf, AV_LOG_INFO, "sub2video: using %dx%d canvas\n", w, h); } - ist->sub2video.w = ifilter->width = w; - ist->sub2video.h = ifilter->height = h; + ist->sub2video.w = ifp->width = w; + ist->sub2video.h = ifp->height = h; - ifilter->width = ist->dec_ctx->width ? ist->dec_ctx->width : ist->sub2video.w; - ifilter->height = ist->dec_ctx->height ? ist->dec_ctx->height : ist->sub2video.h; + ifp->width = ist->dec_ctx->width ? ist->dec_ctx->width : ist->sub2video.w; + ifp->height = ist->dec_ctx->height ? ist->dec_ctx->height : ist->sub2video.h; /* rectangles are AV_PIX_FMT_PAL8, but we have no guarantee that the palettes for all rectangles are identical or compatible */ - ifilter->format = AV_PIX_FMT_RGB32; + ifp->format = AV_PIX_FMT_RGB32; ist->sub2video.frame = av_frame_alloc(); if (!ist->sub2video.frame) @@ -1042,14 +1052,14 @@ static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter, ifp->time_base = ist->framerate.num ? av_inv_q(ist->framerate) : ist->st->time_base; - sar = ifilter->sample_aspect_ratio; + sar = ifp->sample_aspect_ratio; if(!sar.den) sar = (AVRational){0,1}; av_bprint_init(&args, 0, AV_BPRINT_SIZE_AUTOMATIC); av_bprintf(&args, "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:" "pixel_aspect=%d/%d", - ifilter->width, ifilter->height, ifilter->format, + ifp->width, ifp->height, ifp->format, ifp->time_base.num, ifp->time_base.den, sar.num, sar.den); if (fr.num && fr.den) av_bprintf(&args, ":frame_rate=%d/%d", fr.num, fr.den); @@ -1067,7 +1077,7 @@ static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter, av_freep(&par); last_filter = ifilter->filter; - desc = av_pix_fmt_desc_get(ifilter->format); + desc = av_pix_fmt_desc_get(ifp->format); av_assert0(desc); // TODO: insert hwaccel enabled filters like transpose_vaapi into the graph @@ -1147,19 +1157,19 @@ static int configure_input_audio_filter(FilterGraph *fg, InputFilter *ifilter, return AVERROR(EINVAL); } - ifp->time_base = (AVRational){ 1, ifilter->sample_rate }; + ifp->time_base = (AVRational){ 1, ifp->sample_rate }; av_bprint_init(&args, 0, AV_BPRINT_SIZE_AUTOMATIC); av_bprintf(&args, "time_base=%d/%d:sample_rate=%d:sample_fmt=%s", ifp->time_base.num, ifp->time_base.den, - ifilter->sample_rate, - av_get_sample_fmt_name(ifilter->format)); - if (av_channel_layout_check(&ifilter->ch_layout) && - ifilter->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC) { + ifp->sample_rate, + av_get_sample_fmt_name(ifp->format)); + if (av_channel_layout_check(&ifp->ch_layout) && + ifp->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC) { av_bprintf(&args, ":channel_layout="); - av_channel_layout_describe_bprint(&ifilter->ch_layout, &args); + av_channel_layout_describe_bprint(&ifp->ch_layout, &args); } else - av_bprintf(&args, ":channels=%d", ifilter->ch_layout.nb_channels); + av_bprintf(&args, ":channels=%d", ifp->ch_layout.nb_channels); snprintf(name, sizeof(name), "graph_%d_in_%d_%d", fg->index, ist->file_index, ist->st->index); @@ -1426,14 +1436,14 @@ static int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *fr if (ret < 0) return ret; - ifilter->format = frame->format; + ifp->format = frame->format; - ifilter->width = frame->width; - ifilter->height = frame->height; - ifilter->sample_aspect_ratio = frame->sample_aspect_ratio; + ifp->width = frame->width; + ifp->height = frame->height; + ifp->sample_aspect_ratio = frame->sample_aspect_ratio; - ifilter->sample_rate = frame->sample_rate; - ret = av_channel_layout_copy(&ifilter->ch_layout, &frame->ch_layout); + ifp->sample_rate = frame->sample_rate; + ret = av_channel_layout_copy(&ifp->ch_layout, &frame->ch_layout); if (ret < 0) return ret; @@ -1450,8 +1460,9 @@ int ifilter_has_all_input_formats(FilterGraph *fg) { int i; for (i = 0; i < fg->nb_inputs; i++) { - if (fg->inputs[i]->format < 0 && (fg->inputs[i]->type == AVMEDIA_TYPE_AUDIO || - fg->inputs[i]->type == AVMEDIA_TYPE_VIDEO)) + InputFilterPriv *ifp = ifp_from_ifilter(fg->inputs[i]); + if (ifp->format < 0 && (fg->inputs[i]->type == AVMEDIA_TYPE_AUDIO || + fg->inputs[i]->type == AVMEDIA_TYPE_VIDEO)) return 0; } return 1; @@ -1533,15 +1544,15 @@ int ifilter_send_eof(InputFilter *ifilter, int64_t pts, AVRational tb) if (ret < 0) return ret; } else { - if (ifilter->format < 0) { + if (ifp->format < 0) { // the filtergraph was never configured, use the fallback parameters - ifilter->format = ifp->fallback.format; - ifilter->sample_rate = ifp->fallback.sample_rate; - ifilter->width = ifp->fallback.width; - ifilter->height = ifp->fallback.height; - ifilter->sample_aspect_ratio = ifp->fallback.sample_aspect_ratio; + ifp->format = ifp->fallback.format; + ifp->sample_rate = ifp->fallback.sample_rate; + ifp->width = ifp->fallback.width; + ifp->height = ifp->fallback.height; + ifp->sample_aspect_ratio = ifp->fallback.sample_aspect_ratio; - ret = av_channel_layout_copy(&ifilter->ch_layout, + ret = av_channel_layout_copy(&ifp->ch_layout, &ifp->fallback.ch_layout); if (ret < 0) return ret; @@ -1555,7 +1566,7 @@ int ifilter_send_eof(InputFilter *ifilter, int64_t pts, AVRational tb) } } - if (ifilter->format < 0 && (ifilter->type == AVMEDIA_TYPE_AUDIO || ifilter->type == AVMEDIA_TYPE_VIDEO)) { + if (ifp->format < 0 && (ifilter->type == AVMEDIA_TYPE_AUDIO || ifilter->type == AVMEDIA_TYPE_VIDEO)) { av_log(NULL, AV_LOG_ERROR, "Cannot determine format of input stream %d:%d after EOF\n", ifilter->ist->file_index, ifilter->ist->st->index); return AVERROR_INVALIDDATA; } @@ -1572,16 +1583,16 @@ int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame, int keep_reference) int need_reinit, ret; /* determine if the parameters for this input changed */ - need_reinit = ifilter->format != frame->format; + need_reinit = ifp->format != frame->format; switch (ifilter->ist->par->codec_type) { case AVMEDIA_TYPE_AUDIO: - need_reinit |= ifilter->sample_rate != frame->sample_rate || - av_channel_layout_compare(&ifilter->ch_layout, &frame->ch_layout); + need_reinit |= ifp->sample_rate != frame->sample_rate || + av_channel_layout_compare(&ifp->ch_layout, &frame->ch_layout); break; case AVMEDIA_TYPE_VIDEO: - need_reinit |= ifilter->width != frame->width || - ifilter->height != frame->height; + need_reinit |= ifp->width != frame->width || + ifp->height != frame->height; break; } From patchwork Wed May 17 10:20:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41679 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1079588pzb; Wed, 17 May 2023 03:24:27 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5QAI7LwYuXxc7rnJjA0phyhSL19BlkSaCzhZnA1mFmYLqMynHW7ecJbGJgiqcLFa1UEDo6 X-Received: by 2002:aa7:da98:0:b0:505:4f7:8a50 with SMTP id q24-20020aa7da98000000b0050504f78a50mr1839350eds.5.1684319066950; Wed, 17 May 2023 03:24:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684319066; cv=none; d=google.com; s=arc-20160816; b=ccRUyUmCxKw8Lx9Ur1WSZ88S/erByb9+U6IPuF0O0fLcLF7e9hqCiWEmT289WnLFVd N+V3U583PtO86q9481Bg++bAoMU7/p+dU+qkw1lWCoKjB62SEGBEqcY3OPHhUiWG5ido Ei1oZXlHePqNQs81cmH+qecIPNg/qC4ojmTwV/36nZFGV94OnFO2QrHVaM+wVNTCTDbu beqspXBnrBEIOjd5FAetz/U2Fl2q9qwRZaiSielpc5tB4E6ddOWoq75XG9HDtCGFaiQn ewYiuvyCJ5qSCmDaVOeemB0c87k+TDfWxO2uryvg1uCkVbke41kwTvOInKjNepVpctlU wmLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=lWY84YhA7zO6a+LYq+zqB+MTgxyobKfnJQyPJkPqKCE=; b=qXfEodMLpS2U9SzjU4u1dy9cgTj/AvwUY6IPtFQRijFn0WMFHtbbIQOLjPEN92i1Bq hjtZpfu+wMS2iss3yzds7+tjnuzQz4FTHVEMKBy0RzDMGDDvG2IePCQFZTm4EyjWzfOd PNUHO3c/80NOwGjersqyh+r48iATfEjbE3Sc3AUyHHxg9cBHg6p2ipiYnMlkMYwJQbNj k/SkQnBGNGWyVgrvyQNk3+zzPwg7el+xAhcFo2hdUOzROBQ4iM/mx2HN5hofYt+72duT j0QV2R+K6rpKG16FIm1vE3QM+Kd/o4ahTBNw/NTFDgHJhfuOUTPtO7TzIrVcKythgQVA FybA== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id y13-20020a50eb0d000000b0050de918773fsi11827699edp.12.2023.05.17.03.24.26; Wed, 17 May 2023 03:24:26 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 851F568C1C7; Wed, 17 May 2023 13:21:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3F38B68C13B for ; Wed, 17 May 2023 13:20:53 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id F2FFD2406CD for ; Wed, 17 May 2023 12:20:51 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id Y4WDS8xxYid6 for ; Wed, 17 May 2023 12:20:51 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 1B30C2406CC for ; Wed, 17 May 2023 12:20:46 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 1AA3B3A17DA for ; Wed, 17 May 2023 12:20:40 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 May 2023 12:20:09 +0200 Message-Id: <20230517102029.541-16-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517102029.541-1-anton@khirnov.net> References: <20230517102029.541-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 16/36] fftools/ffmpeg_filter: drop a redundant error message 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: thvvL0APbfQk In case no decoder is available, dec_open() called from ist_use() will fail with 'Decoding requested, but no decoder found', so this check is redundant. --- fftools/ffmpeg_filter.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 12e756e489..16f29a313f 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -1201,12 +1201,6 @@ static int configure_input_audio_filter(FilterGraph *fg, InputFilter *ifilter, static int configure_input_filter(FilterGraph *fg, InputFilter *ifilter, AVFilterInOut *in) { - if (!ifilter->ist->dec) { - av_log(NULL, AV_LOG_ERROR, - "No decoder for stream #%d:%d, filtering impossible\n", - ifilter->ist->file_index, ifilter->ist->st->index); - return AVERROR_DECODER_NOT_FOUND; - } switch (avfilter_pad_get_type(in->filter_ctx->input_pads, in->pad_idx)) { case AVMEDIA_TYPE_VIDEO: return configure_input_video_filter(fg, ifilter, in); case AVMEDIA_TYPE_AUDIO: return configure_input_audio_filter(fg, ifilter, in); From patchwork Wed May 17 10:20:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41686 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1080128pzb; Wed, 17 May 2023 03:25:37 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6RKosg8PzSNn3Ef1zQ2PcmJSbL70brOhVHnK8CySNQxYfOcoEIEUfXO5nEltyDiYLWww0y X-Received: by 2002:a05:6402:704:b0:50a:276f:a3ba with SMTP id w4-20020a056402070400b0050a276fa3bamr1339739edx.34.1684319136929; Wed, 17 May 2023 03:25:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684319136; cv=none; d=google.com; s=arc-20160816; b=KdEzSy5Vd0BPxlFTWimU7t0F1prbhJ5PowgH+HwuLY1o40gxSeSRgR5fjNZj235QGj HEZRYI1lknMa8pGeR9YECzryx9egHr1NleeUVo9JU4rfK1vYqn5JE3GGeKsJIvxZz538 jJ4Ra7FEsdKgj/xCJ20AE2L18xUT1T+13DPXdqIRvaohCo/LQSZRjqZOZh7c65U+Ibvs NII3pn1IrM+kJKSWs4orP8ov2OQY6OweuQjmleRQnhUXWTzw85FsmXPPqcmX97dRLg3a aYyRdPfg8KJ+YThxderCZHvy3uxzZsFEmccsPGLJRh0bdEo1/RzGLCupz3H7ht4Exepp LbYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=nxVljDjj4+/BRNBudKqp9/5ItxupjfpVLLlOT7MiqIA=; b=F8vlPFfJwIWdkMWkRKtFhwY7OEk6RwXmu7w+2ZfbGHgwquj5IdXyzHMnagaoOhH+1h 0Vczw1713XFJMMTle1mvOVKFiA7CQJHresltv2E/y5wb8TNx7Er6S/lGakrOEyohKfBq +wJMH/IM1E9PEm/OGaG5J0hsGyQJ/jzWdlUQ6Jm8oTjjqZvcDm7OyQH37K4bXDtl8s1D g8l0uJj6Bo3kuQjVARerL9ltX/zekZC8IbMhrWbrCq8ss5DxXuxt7RYBZoUTRnYGmQnA zZjKVT1UWPQYqtTO1pedhQqF/h035eefvcTXrAgiYPPTVip4KagIdbHfBC+5DqgD0piD tOOg== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id h2-20020aa7c602000000b0050c0e683b3bsi14420294edq.98.2023.05.17.03.25.36; Wed, 17 May 2023 03:25:36 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E0F4068C1FE; Wed, 17 May 2023 13:21:24 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8FA1668C189 for ; Wed, 17 May 2023 13:21:01 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 494AC240177 for ; Wed, 17 May 2023 12:21:01 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id f2QSanyryfH8 for ; Wed, 17 May 2023 12:20:59 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 6131B240D22 for ; Wed, 17 May 2023 12:20:46 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 265D23A1858 for ; Wed, 17 May 2023 12:20:40 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 May 2023 12:20:10 +0200 Message-Id: <20230517102029.541-17-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517102029.541-1-anton@khirnov.net> References: <20230517102029.541-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 17/36] fftools/ffmpeg_filter: move InputFilter.ist to private data 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: mJoLXX0Yxm4W It is not accessed outside of ffmpeg_filter. --- fftools/ffmpeg.h | 1 - fftools/ffmpeg_filter.c | 34 +++++++++++++++++++--------------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 9cb9f35bc2..c33e537faa 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -279,7 +279,6 @@ typedef struct OptionsContext { typedef struct InputFilter { AVFilterContext *filter; - struct InputStream *ist; struct FilterGraph *graph; uint8_t *name; enum AVMediaType type; // AVMEDIA_TYPE_SUBTITLE for sub2video diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 16f29a313f..e6e9e00985 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -55,6 +55,8 @@ static FilterGraphPriv *fgp_from_fg(FilterGraph *fg) typedef struct InputFilterPriv { InputFilter ifilter; + InputStream *ist; + // used to hold submitted input AVFrame *frame; @@ -247,7 +249,7 @@ static OutputFilter *ofilter_alloc(FilterGraph *fg) return ofilter; } -static InputFilter *ifilter_alloc(FilterGraph *fg) +static InputFilter *ifilter_alloc(FilterGraph *fg, InputStream *ist) { InputFilterPriv *ifp = allocate_array_elem(&fg->inputs, sizeof(*ifp), &fg->nb_inputs); @@ -261,6 +263,7 @@ static InputFilter *ifilter_alloc(FilterGraph *fg) ifp->format = -1; ifp->fallback.format = -1; + ifp->ist = ist; ifp->frame_queue = av_fifo_alloc2(8, sizeof(AVFrame*), AV_FIFO_FLAG_AUTO_GROW); if (!ifp->frame_queue) @@ -282,7 +285,7 @@ void fg_free(FilterGraph **pfg) for (int j = 0; j < fg->nb_inputs; j++) { InputFilter *ifilter = fg->inputs[j]; InputFilterPriv *ifp = ifp_from_ifilter(ifilter); - struct InputStream *ist = ifilter->ist; + InputStream *ist = ifp->ist; if (ifp->frame_queue) { AVFrame *frame; @@ -354,8 +357,7 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost) ost->filter = ofilter; - ifilter = ifilter_alloc(fg); - ifilter->ist = ist; + ifilter = ifilter_alloc(fg, ist); ret = ist_filter_add(ist, ifilter, 1); if (ret < 0) @@ -437,8 +439,8 @@ static void init_input_filter(FilterGraph *fg, AVFilterInOut *in) } av_assert0(ist); - ifilter = ifilter_alloc(fg); - ifilter->ist = ist; + ifilter = ifilter_alloc(fg, ist); + ifilter->type = ist->st->codecpar->codec_type; ifilter->name = describe_filter_link(fg, in, 1); @@ -1019,7 +1021,7 @@ static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter, AVFilterContext *last_filter; const AVFilter *buffer_filt = avfilter_get_by_name("buffer"); const AVPixFmtDescriptor *desc; - InputStream *ist = ifilter->ist; + InputStream *ist = ifp->ist; InputFile *f = input_files[ist->file_index]; AVRational fr = ist->framerate; AVRational sar; @@ -1145,7 +1147,7 @@ static int configure_input_audio_filter(FilterGraph *fg, InputFilter *ifilter, InputFilterPriv *ifp = ifp_from_ifilter(ifilter); AVFilterContext *last_filter; const AVFilter *abuffer_filt = avfilter_get_by_name("abuffer"); - InputStream *ist = ifilter->ist; + InputStream *ist = ifp->ist; InputFile *f = input_files[ist->file_index]; AVBPrint args; char name[255]; @@ -1380,7 +1382,7 @@ int configure_filtergraph(FilterGraph *fg) /* process queued up subtitle packets */ for (i = 0; i < fg->nb_inputs; i++) { - InputStream *ist = fg->inputs[i]->ist; + InputStream *ist = ifp_from_ifilter(fg->inputs[i])->ist; if (ist->sub2video.sub_queue && ist->sub2video.frame) { AVSubtitle tmp; while (av_fifo_read(ist->sub2video.sub_queue, &tmp, 1) >= 0) { @@ -1561,7 +1563,9 @@ int ifilter_send_eof(InputFilter *ifilter, int64_t pts, AVRational tb) } if (ifp->format < 0 && (ifilter->type == AVMEDIA_TYPE_AUDIO || ifilter->type == AVMEDIA_TYPE_VIDEO)) { - av_log(NULL, AV_LOG_ERROR, "Cannot determine format of input stream %d:%d after EOF\n", ifilter->ist->file_index, ifilter->ist->st->index); + av_log(NULL, AV_LOG_ERROR, + "Cannot determine format of input stream %d:%d after EOF\n", + ifp->ist->file_index, ifp->ist->st->index); return AVERROR_INVALIDDATA; } } @@ -1579,7 +1583,7 @@ int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame, int keep_reference) /* determine if the parameters for this input changed */ need_reinit = ifp->format != frame->format; - switch (ifilter->ist->par->codec_type) { + switch (ifp->ist->par->codec_type) { case AVMEDIA_TYPE_AUDIO: need_reinit |= ifp->sample_rate != frame->sample_rate || av_channel_layout_compare(&ifp->ch_layout, &frame->ch_layout); @@ -1590,7 +1594,7 @@ int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame, int keep_reference) break; } - if (!ifilter->ist->reinit_filters && fg->graph) + if (!ifp->ist->reinit_filters && fg->graph) need_reinit = 0; if (!!ifp->hw_frames_ctx != !!frame->hw_frames_ctx || @@ -1686,8 +1690,8 @@ int fg_transcode_step(FilterGraph *graph, InputStream **best_ist) for (int i = 0; i < graph->nb_inputs; i++) { InputFilter *ifilter = graph->inputs[i]; InputFilterPriv *ifp = ifp_from_ifilter(ifilter); - if (!ifilter->ist->got_output && !ifp->eof) { - *best_ist = ifilter->ist; + if (!ifp->ist->got_output && !ifp->eof) { + *best_ist = ifp->ist; return 0; } } @@ -1717,7 +1721,7 @@ int fg_transcode_step(FilterGraph *graph, InputStream **best_ist) InputFilter *ifilter = graph->inputs[i]; InputFilterPriv *ifp = ifp_from_ifilter(ifilter); - ist = ifilter->ist; + ist = ifp->ist; if (input_files[ist->file_index]->eagain || ifp->eof) continue; nb_requests = av_buffersrc_get_nb_failed_requests(ifilter->filter); From patchwork Wed May 17 10:20:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41674 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1079130pzb; Wed, 17 May 2023 03:23:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7X851hnqWSCyP5HP98qi7ihHgPSZgU9iOM8UBXJMGgTB9FvneaWCZ78IFsd33EnaePdv+Y X-Received: by 2002:a17:906:ef09:b0:95e:d3f5:3d47 with SMTP id f9-20020a170906ef0900b0095ed3f53d47mr34936969ejs.48.1684319013552; Wed, 17 May 2023 03:23:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684319013; cv=none; d=google.com; s=arc-20160816; b=n6T8E/vGXMzuQXVkxcIqokjSk5/Jxd2Q3gNBLYODju95ZpDDeRAmcKYUwT2FiSn1Kt od8XJRlQbWRTR4CZ7u5t9bsC71p5ZYbIEq/tIYsIPrJC51cFUv0NdNFtN6lKvl2SvEsG AneysCbfkaPdDv0rCwNoUY1wNjSJpQmXoNANpw/HoTg2pcfN1lXFJM286adFeoce+jj5 Qqq17Qbha0gygt5pj+kYgrwn5zQmXQnJhVGL4cZ1oCuKHrJj4CmY8hI2EqleHoyaxHAe vNKOTSZLCKJ3zuykLIv8S0OMMb3fqbgYhv+ioEbn6TF8xuLibJ9AZtD3oN4Kby7aWkFE LzrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=V8H9IWA+4dtWzUdb3qdnVSN0HfBCo4HG+LvidMZEtpQ=; b=OI+E80iB8uNRgLWSyU3ke6KeN0LySEYIQp82IlvfE920NZec1mByaOJ/T7dVpBsop1 /B9ZP2FvlqeIA1S4/qGHoOJYFwwS2IM48N27pwiVD1h2wb3g2NHncUJFOYsBS37QeCzG uPhOVisX5dTu2W2AAVWh2xgCSML8Hv2xR8dzmHqtel3DTG8AlPyasIh60cnASMCtvEWU OHmmMKRNlt4MuVMvugz7EbnFfJy/g47AnuujfEnrlVViAkMjx+ZDSeBu4jOT3LPh1GJB 9tRM60NDqzIHXuoYulgwI0nnfIE4eHzzcknfWsdMpA95m5oZLnhiGX33H7gojSkxlv7e qX0g== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id b26-20020aa7d49a000000b0050bcd68af88si926980edr.441.2023.05.17.03.23.33; Wed, 17 May 2023 03:23:33 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9A7A568C1A9; Wed, 17 May 2023 13:21:10 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A9D1E68C144 for ; Wed, 17 May 2023 13:20:57 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id D1205240D03 for ; Wed, 17 May 2023 12:20:56 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id C-4TkkPs11WN for ; Wed, 17 May 2023 12:20:56 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 49033240D1E for ; Wed, 17 May 2023 12:20:46 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 3276F3A1AF0 for ; Wed, 17 May 2023 12:20:40 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 May 2023 12:20:11 +0200 Message-Id: <20230517102029.541-18-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517102029.541-1-anton@khirnov.net> References: <20230517102029.541-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 18/36] fftools/ffmpeg_filter: move InputFilter.type to private data 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 6svn4Q1U58ra It is not accessed outside of ffmpeg_filter. --- fftools/ffmpeg.h | 1 - fftools/ffmpeg_filter.c | 12 +++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index c33e537faa..04c41a5311 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -281,7 +281,6 @@ typedef struct InputFilter { AVFilterContext *filter; struct FilterGraph *graph; uint8_t *name; - enum AVMediaType type; // AVMEDIA_TYPE_SUBTITLE for sub2video } InputFilter; typedef struct OutputFilter { diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index e6e9e00985..5656fa87df 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -60,6 +60,9 @@ typedef struct InputFilterPriv { // used to hold submitted input AVFrame *frame; + // AVMEDIA_TYPE_SUBTITLE for sub2video + enum AVMediaType type; + int eof; // parameters configured for this input @@ -264,6 +267,7 @@ static InputFilter *ifilter_alloc(FilterGraph *fg, InputStream *ist) ifp->format = -1; ifp->fallback.format = -1; ifp->ist = ist; + ifp->type = ist->st->codecpar->codec_type; ifp->frame_queue = av_fifo_alloc2(8, sizeof(AVFrame*), AV_FIFO_FLAG_AUTO_GROW); if (!ifp->frame_queue) @@ -440,8 +444,6 @@ static void init_input_filter(FilterGraph *fg, AVFilterInOut *in) av_assert0(ist); ifilter = ifilter_alloc(fg, ist); - - ifilter->type = ist->st->codecpar->codec_type; ifilter->name = describe_filter_link(fg, in, 1); ret = ist_filter_add(ist, ifilter, 0); @@ -1457,8 +1459,8 @@ int ifilter_has_all_input_formats(FilterGraph *fg) int i; for (i = 0; i < fg->nb_inputs; i++) { InputFilterPriv *ifp = ifp_from_ifilter(fg->inputs[i]); - if (ifp->format < 0 && (fg->inputs[i]->type == AVMEDIA_TYPE_AUDIO || - fg->inputs[i]->type == AVMEDIA_TYPE_VIDEO)) + if (ifp->format < 0 && (ifp->type == AVMEDIA_TYPE_AUDIO || + ifp->type == AVMEDIA_TYPE_VIDEO)) return 0; } return 1; @@ -1562,7 +1564,7 @@ int ifilter_send_eof(InputFilter *ifilter, int64_t pts, AVRational tb) } } - if (ifp->format < 0 && (ifilter->type == AVMEDIA_TYPE_AUDIO || ifilter->type == AVMEDIA_TYPE_VIDEO)) { + if (ifp->format < 0 && (ifp->type == AVMEDIA_TYPE_AUDIO || ifp->type == AVMEDIA_TYPE_VIDEO)) { av_log(NULL, AV_LOG_ERROR, "Cannot determine format of input stream %d:%d after EOF\n", ifp->ist->file_index, ifp->ist->st->index); From patchwork Wed May 17 10:20:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41678 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1079511pzb; Wed, 17 May 2023 03:24:19 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7purN/6nkybq2xnoO7KFmlFhLPfFvUMi+aZRy0AVP8xnOOQJaJ6CdxPE/r6QM4nQDg/C85 X-Received: by 2002:a17:907:7b92:b0:94e:edf3:dccd with SMTP id ne18-20020a1709077b9200b0094eedf3dccdmr39328434ejc.0.1684319059044; Wed, 17 May 2023 03:24:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684319059; cv=none; d=google.com; s=arc-20160816; b=T9lJtayzJnDT0pRZl6IFX0fAcObY90inI82jKELVItasd0d3bQID795sXXylWy23JJ /uXMFz/KkYLjSbxvSkVXzaxoDn3wWspQaNlS6fBN3571ruw9fwICZn180Loyl8a5aNok LD5voyGD0uJ3M8cpcOeOzxcq2SAOC2XiW8bE5LUwsRQm5gglE3hXhw+HYqzYkkgWYw8g tx2KfddxaTNrYdyc1DZCt7++E+32zyEyeEK+T5g/iNAWRA9s7pCs0gM/4+v1QV9pDtf/ Qg62ciQYo6tHENwvwkM0Q84pnTODch9TaMbSvD3b5qyQZizUGZqxc0Tv9eeaSPDc3G/6 pf8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=F1bUsXyv+4YpNK3lJEj927QFwny3sXOBzgNAkT2+bn0=; b=F3mCEXwR+OhtF7IsMn8q9Yz7juXND3HTfs1BWAMwnltp/gZ/axq6lor8XmKohl283z JA8LDuFGIjzerF7bTclQzDYoGnk261uApxdtHLkPTWxKCqbbEjJv1ffVc5GhCbijp1Tl PNA5k6o4U8lZNjKEiPxtNcLjZlVQeZUuNS5XnY2OwyXSUmd96RedZ92nG3mYWCm6egOv zxHcaxcBk5MWd89ehL8i94Dj+kOQPLoA0rr+iNJ+9OzGMmOjn69j9X3Nr0FSEo9Yypr6 bQOZnCmYDaMhVEEjytDI0HoeGUHRoIPvUzk90Xsb7W6RJEqhkBo0EXjb8Xt2tT9pyHO4 l87Q== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id d13-20020a17090648cd00b009662eab40basi15384777ejt.415.2023.05.17.03.24.18; Wed, 17 May 2023 03:24:19 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 893A068C1BC; Wed, 17 May 2023 13:21:15 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3BFD268C131 for ; Wed, 17 May 2023 13:20:53 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id A46122405F9 for ; Wed, 17 May 2023 12:20:51 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id y5-VCsWyRTiN for ; Wed, 17 May 2023 12:20:51 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 1B6A12406CD for ; Wed, 17 May 2023 12:20:46 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 3DE1D3A1AF1 for ; Wed, 17 May 2023 12:20:40 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 May 2023 12:20:12 +0200 Message-Id: <20230517102029.541-19-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517102029.541-1-anton@khirnov.net> References: <20230517102029.541-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 19/36] fftools/ffmpeg_filter: keep track of the real filter input type 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 1TiEmfI2lvSQ Avoid extracting it from various remote sources. --- fftools/ffmpeg_filter.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 5656fa87df..c699431831 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -60,8 +60,11 @@ typedef struct InputFilterPriv { // used to hold submitted input AVFrame *frame; - // AVMEDIA_TYPE_SUBTITLE for sub2video + // filter data type enum AVMediaType type; + // source data type: AVMEDIA_TYPE_SUBTITLE for sub2video, + // same as type otherwise + enum AVMediaType type_src; int eof; @@ -267,7 +270,9 @@ static InputFilter *ifilter_alloc(FilterGraph *fg, InputStream *ist) ifp->format = -1; ifp->fallback.format = -1; ifp->ist = ist; - ifp->type = ist->st->codecpar->codec_type; + ifp->type_src = ist->st->codecpar->codec_type; + ifp->type = ifp->type_src == AVMEDIA_TYPE_SUBTITLE ? + AVMEDIA_TYPE_VIDEO : ifp->type_src; ifp->frame_queue = av_fifo_alloc2(8, sizeof(AVFrame*), AV_FIFO_FLAG_AUTO_GROW); if (!ifp->frame_queue) @@ -1205,7 +1210,7 @@ static int configure_input_audio_filter(FilterGraph *fg, InputFilter *ifilter, static int configure_input_filter(FilterGraph *fg, InputFilter *ifilter, AVFilterInOut *in) { - switch (avfilter_pad_get_type(in->filter_ctx->input_pads, in->pad_idx)) { + switch (ifp_from_ifilter(ifilter)->type) { case AVMEDIA_TYPE_VIDEO: return configure_input_video_filter(fg, ifilter, in); case AVMEDIA_TYPE_AUDIO: return configure_input_audio_filter(fg, ifilter, in); default: av_assert0(0); return 0; @@ -1459,8 +1464,8 @@ int ifilter_has_all_input_formats(FilterGraph *fg) int i; for (i = 0; i < fg->nb_inputs; i++) { InputFilterPriv *ifp = ifp_from_ifilter(fg->inputs[i]); - if (ifp->format < 0 && (ifp->type == AVMEDIA_TYPE_AUDIO || - ifp->type == AVMEDIA_TYPE_VIDEO)) + if (ifp->format < 0 && (ifp->type_src == AVMEDIA_TYPE_AUDIO || + ifp->type_src == AVMEDIA_TYPE_VIDEO)) return 0; } return 1; @@ -1564,7 +1569,9 @@ int ifilter_send_eof(InputFilter *ifilter, int64_t pts, AVRational tb) } } - if (ifp->format < 0 && (ifp->type == AVMEDIA_TYPE_AUDIO || ifp->type == AVMEDIA_TYPE_VIDEO)) { + if (ifp->format < 0 && + (ifp->type_src == AVMEDIA_TYPE_AUDIO || + ifp->type_src == AVMEDIA_TYPE_VIDEO)) { av_log(NULL, AV_LOG_ERROR, "Cannot determine format of input stream %d:%d after EOF\n", ifp->ist->file_index, ifp->ist->st->index); @@ -1585,7 +1592,7 @@ int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame, int keep_reference) /* determine if the parameters for this input changed */ need_reinit = ifp->format != frame->format; - switch (ifp->ist->par->codec_type) { + switch (ifp->type) { case AVMEDIA_TYPE_AUDIO: need_reinit |= ifp->sample_rate != frame->sample_rate || av_channel_layout_compare(&ifp->ch_layout, &frame->ch_layout); From patchwork Wed May 17 10:20:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41670 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1078804pzb; Wed, 17 May 2023 03:22:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ63Q5cDUfYZDk/QjQ/RVul4SoJvKe3VW5DF/sidzIAZ5f+mNlEaum7o944wayfYPLbE+CZg X-Received: by 2002:a17:907:25c7:b0:94a:7da2:d339 with SMTP id ae7-20020a17090725c700b0094a7da2d339mr35952858ejc.26.1684318979046; Wed, 17 May 2023 03:22:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684318979; cv=none; d=google.com; s=arc-20160816; b=uGOvUtWgA47idwZNIO+XFKz4NLzVzvC8v5S7+NshuibOxJmGOGHCSUQ4HU2CLpLRKm PaRmNFwozP3u4hFQ7ixoYRJJsp2OtIojMoCz5UF3dwApo13Jc+aq75K1pXCyO1IwhCFg PSmsUvPdedMCwZIWDQus5rXuB2jufbof07WvdAsKzQXV0fHmwIDrAgcyNbmGmRb7Q4vm d+LRt8miwctL8uhNoA2Kx7N5fcO3VLmzE3zp0iJZDMeLBXN/Qlc3uL5KuMwZ4EANroZ8 h2RjEFX6GvF6HPGAfUCS61VGZugPsIIgBHQunzpw/efkLZ2MCfa+MA8Lj5jc3GfPXWSm eBrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=aUCLQjO0pbxjXouODrcBy0OJ93Y6ig+UECHL+0m8bfU=; b=wLayUrS9LHCmgjHnKVKpeXMoQQBK0mlCj6aRL3TGY3BeZRi+2/q7BK/MBwhY26/ysO 6oW0FKixtXty9PoWeG1CPXuHDq5VsIXu7Csu6M+OaDMnxc31YY0EUbH3HOsFBYcI1JD9 2M5tX+VSHINnLClfRC6TV6W/huiPo8PsyxX2tCAi8SULlZHmfT7iexDAmnxGHYHKkDwQ qsgq42kS1p/gBuBfz56afKSOn2zQD7o5+FoDFRGuG5qxdiHNpiiLvRwDMfoIxEcKGqOL oE8V5pYWyoIW2vccKZrJGUhbjLq4pp/YNj6oUSMpFGDH89gtADtBtDsu5Xy2sBDaFB4i 82fA== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id sg6-20020a170907a40600b0096a9187ebf0si12288742ejc.579.2023.05.17.03.22.58; Wed, 17 May 2023 03:22:59 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 731CA68C182; Wed, 17 May 2023 13:21:07 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A58B868C12D for ; Wed, 17 May 2023 13:20:57 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id A392D240706 for ; Wed, 17 May 2023 12:20:55 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id e3vsu4w6-3ci for ; Wed, 17 May 2023 12:20:52 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 2D30A240705 for ; Wed, 17 May 2023 12:20:46 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 498113A1B20 for ; Wed, 17 May 2023 12:20:40 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 May 2023 12:20:13 +0200 Message-Id: <20230517102029.541-20-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517102029.541-1-anton@khirnov.net> References: <20230517102029.541-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 20/36] fftools/ffmpeg_filter: embed displaymatrix into private context 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: e2bY98OOYbPZ It has a small fixed size, so it is better to embed it rather than deal with dynamic allocation. --- fftools/ffmpeg_filter.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index c699431831..6f842f6b46 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -83,7 +83,8 @@ typedef struct InputFilterPriv { AVBufferRef *hw_frames_ctx; - int32_t *displaymatrix; + int displaymatrix_present; + int32_t displaymatrix[9]; // fallback parameters to use when no input is ever sent struct { @@ -302,7 +303,6 @@ void fg_free(FilterGraph **pfg) av_frame_free(&frame); av_fifo_freep2(&ifp->frame_queue); } - av_freep(&ifp->displaymatrix); if (ist->sub2video.sub_queue) { AVSubtitle sub; while (av_fifo_read(ist->sub2video.sub_queue, &sub, 1) >= 0) @@ -1094,7 +1094,7 @@ static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter, int32_t *displaymatrix = ifp->displaymatrix; double theta; - if (!displaymatrix) + if (!ifp->displaymatrix_present) displaymatrix = (int32_t *)av_stream_get_side_data(ist->st, AV_PKT_DATA_DISPLAYMATRIX, NULL); theta = get_rotation(displaymatrix); @@ -1450,10 +1450,10 @@ static int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *fr if (ret < 0) return ret; - av_freep(&ifp->displaymatrix); sd = av_frame_get_side_data(frame, AV_FRAME_DATA_DISPLAYMATRIX); if (sd) - ifp->displaymatrix = av_memdup(sd->data, sizeof(int32_t) * 9); + memcpy(ifp->displaymatrix, sd->data, sizeof(ifp->displaymatrix)); + ifp->displaymatrix_present = !!sd; return 0; } @@ -1611,9 +1611,10 @@ int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame, int keep_reference) need_reinit = 1; if (sd = av_frame_get_side_data(frame, AV_FRAME_DATA_DISPLAYMATRIX)) { - if (!ifp->displaymatrix || memcmp(sd->data, ifp->displaymatrix, sizeof(int32_t) * 9)) + if (!ifp->displaymatrix_present || + memcmp(sd->data, ifp->displaymatrix, sizeof(ifp->displaymatrix))) need_reinit = 1; - } else if (ifp->displaymatrix) + } else if (ifp->displaymatrix_present) need_reinit = 1; if (need_reinit) { From patchwork Wed May 17 10:20:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41665 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1078456pzb; Wed, 17 May 2023 03:22:16 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5SaCPd3IIzomXLyE8WUjr6U4TgyacJNEEvWo4O1C+U6tVOMyIJfDW9bY+KLHkhJTtyYdvk X-Received: by 2002:a17:907:6d10:b0:96a:eb2:9c5e with SMTP id sa16-20020a1709076d1000b0096a0eb29c5emr25724901ejc.63.1684318935988; Wed, 17 May 2023 03:22:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684318935; cv=none; d=google.com; s=arc-20160816; b=Sl5hcRw94/xdNC/1wJfyOFX9BusfdqSanE3/0tbTlALY3P2E2Z1lYe1+kcsvfotm2/ 9x1Onr1r/uRvwYdMYcsbxvbISLrJd/knrwJ4UBVNHuSPNicN0ylZvQKFW9IVXvql7dTr QiyQU/ILAtTkzXKDYSL6NrA+OHyyhZrOh9njDwcC8L2OdG8xKv+xlFQfyXBO2rfwyH5k zXgNYBFESbi82XYlVFU7FMG7+UHlVUJMvk+M6BdZpDI4xh1mj5QG1Ytx6Ke04xpCj1nu BwFT39aAKsgaj2KLX7m1rpvwkK3vnQkiTc+kth71NhGXVy/Vv+RB+lg0yq3mPQa1CezO Y0jQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=Jr1U5cTEsQwwbR3/bDt89RGPdGRpfRX7JssjHaGcid0=; b=dqK3D6OVsixzWRDasRBcKrqqUKO4V8QSkfD37Fnjj4nkJw3rPRGYWjNNlnSk0Mv+8a TcvYzMSf+40FGlAZ7jMKFc+S9Coz7JBoU46Y9R4UzljYg/pQzNc4tn4ONVSLRZcHpFEp WqT1tUBho8/BFD3HxTy/hzMJyQyBl8hePEqZul5UxvjU3qd8nXPLa+TndvynWBWAJ/AP DzS9JkltGMe65Qe6WNbe06rH7jrQ1BdDgOwAoCazBl3qIDUFKZUtMadVtGwI0Zb2muk3 yRgkib+RFHrHxCCQDAnGblC1iq8brjwEIsiZefwqJ78jHzrmq42S5IxGt58DjUkRwUJH 6Auw== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id qb31-20020a1709077e9f00b0096a90bba2ddsi11256955ejc.29.2023.05.17.03.22.15; Wed, 17 May 2023 03:22:15 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BC1AE68C186; Wed, 17 May 2023 13:21:01 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6F4F368C10F for ; Wed, 17 May 2023 13:20:57 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 8C9602406CE for ; Wed, 17 May 2023 12:20:52 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 4bYcsS9ZGo8R for ; Wed, 17 May 2023 12:20:52 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 2D03F2406D0 for ; Wed, 17 May 2023 12:20:46 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 555663A1E22 for ; Wed, 17 May 2023 12:20:40 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 May 2023 12:20:14 +0200 Message-Id: <20230517102029.541-21-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517102029.541-1-anton@khirnov.net> References: <20230517102029.541-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 21/36] fftools/cmdutils: constify the argument of get_rotation() 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: XT1LXZce9945 --- fftools/cmdutils.c | 2 +- fftools/cmdutils.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index a1de621d1c..9ec00add30 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -994,7 +994,7 @@ void *allocate_array_elem(void *ptr, size_t elem_size, int *nb_elems) return new_elem; } -double get_rotation(int32_t *displaymatrix) +double get_rotation(const int32_t *displaymatrix) { double theta = 0; if (displaymatrix) diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h index 4496221983..0115940225 100644 --- a/fftools/cmdutils.h +++ b/fftools/cmdutils.h @@ -461,6 +461,6 @@ void *allocate_array_elem(void *array, size_t elem_size, int *nb_elems); char name[16];\ snprintf(name, sizeof(name), "%d", rate); -double get_rotation(int32_t *displaymatrix); +double get_rotation(const int32_t *displaymatrix); #endif /* FFTOOLS_CMDUTILS_H */ From patchwork Wed May 17 10:20:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41681 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1079783pzb; Wed, 17 May 2023 03:24:53 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6vsEUv22un+Swc1TpTXeB36b0aiMMKaHgUwDSJgF6npBF2waK7jqt/Czt6Q52LqSmAdsOA X-Received: by 2002:a17:907:3fa6:b0:966:6035:c81e with SMTP id hr38-20020a1709073fa600b009666035c81emr34893375ejc.52.1684319092880; Wed, 17 May 2023 03:24:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684319092; cv=none; d=google.com; s=arc-20160816; b=exiwtnjOyBIF1yL/SRS+fmoMd6HwveOrfqD+ZGlCROV0COfX65/6Dup4MZUNgc+S6F wVpkTbmP3dmhyC5vILqnEwj0cFm2l+0NYSKStsKBmC/1ZuaQj1k8su2Li9ORGWhVyzTL u5mWI/Rvc02VcRrytWOiUBQdVBp0yjfdx/Q5JWjTN+c+1xrH0JUq2CHzf5kcFbGYRIc2 n+EQQC99AcMrsOHWFZ/16/Xcctu4CdE7YuX5ikbvx1QH+iFnfnl2IM3zeNDEbm8CgiGV ugleZ+3ZsbmMioGJOk7t5bnmcVHxEBfe60A1/Q2TMmqdE7ZUeVV59hpsrVEmkCsj6S4i ZN5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=0aax72gHAFvHdvT+XoOhVAIMrO57vmDEwzXESv/FxnI=; b=Z1qcg7d7YNvHGHpscMvPqh4lcXqmSal1uV2XMm1AScKouu+MOCR2bz5Ja2Qcs2oglr 6mwsqxyg95ku2dBAPZJnVp+xnPOYt/gxx4uU3S7UoCoxXI2Mm4t1KBB4sWQAfbwlzt36 jTQhGd2a18G6uMloYuLxMT6IRnUVR9X+VJyK0AMYC05/ZeD2Kul7YBpmrfy5jp4Avfwz /1946DHSyC2Ig8292iJCcciND3D8yYqoOFqpGtAzIGolwf+zox1hLf8odtTqbLWnYifI bWPLukgDESrUlt+0YyV3lC1dgSpET8b1ghqmjMe3uX82JvB5MfTkQUpIui428S5m1qQN m1Ig== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id fy25-20020a170906b7d900b00946c265cf23si15410756ejb.838.2023.05.17.03.24.51; Wed, 17 May 2023 03:24:52 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B2C0968C1E0; Wed, 17 May 2023 13:21:19 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A152068C157 for ; Wed, 17 May 2023 13:20:53 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 1BF7F2406CC for ; Wed, 17 May 2023 12:20:52 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id cWjdBkhNx77e for ; Wed, 17 May 2023 12:20:51 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 2CD382406CE for ; Wed, 17 May 2023 12:20:46 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 60EA73A1EBB for ; Wed, 17 May 2023 12:20:40 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 May 2023 12:20:15 +0200 Message-Id: <20230517102029.541-22-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517102029.541-1-anton@khirnov.net> References: <20230517102029.541-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 22/36] fftools/ffmpeg: drop an obsolete hack 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: +wGpxyRAmnQE This special handling for decoder flushing has not been needed since af1761f7b5, as the filtergraph actually is drained after that commit. --- fftools/ffmpeg.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 9d554e2fb0..49313edebc 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1418,17 +1418,6 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo if (!got_output) break; - // During draining, we might get multiple output frames in this loop. - // ffmpeg.c does not drain the filter chain on configuration changes, - // which means if we send multiple frames at once to the filters, and - // one of those frames changes configuration, the buffered frames will - // be lost. This can upset certain FATE tests. - // Decode only 1 frame per call on EOF to appease these FATE tests. - // The ideal solution would be to rewrite decoding to use the new - // decoding API in a better way. - if (!pkt) - break; - repeating = 1; } From patchwork Wed May 17 10:20:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41682 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1079859pzb; Wed, 17 May 2023 03:25:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7rMO0AWDfYXVtBpLqXnkZ3kizQJGoHpB2ZLzZCmjlCfOfwvCTSAISGelknNVmygB+SI/UL X-Received: by 2002:a17:906:fd8d:b0:94f:3521:394 with SMTP id xa13-20020a170906fd8d00b0094f35210394mr36813025ejb.51.1684319100470; Wed, 17 May 2023 03:25:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684319100; cv=none; d=google.com; s=arc-20160816; b=sB0kbeGDesJsQ5f50RBT7NKWV5K7G7RTGABa6pJ/e1u86r4CydnC52Ei6SmcwOvrVp QmikIKn56cgHeIHX9Bhy7kgO0+g0PyMvV6HNRElEDnLBEHSeiEXqp0CL7kEUiF0VFJfA caLKzj20sgdKwWcVh7C2ar8Ka9VPBU1qtAqYppZWbGHQ3yKCPI1Zv/7pCTG56i8J87UP 1SFOdRtujolOlUFbexodAyw4mDB+Q9Y5r68hlLqBcPebjbdeHX6D8cw1LEvcWVdV9iSE QfRrTEfnV9FoTKyXFRqx80ay2ERU1lycW4+QYeaRYav+6HNcVpgHmLK51IXgVjnHjlen taCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=DIhGtSoZp7Nob6PGLjlR7bNxyZ/1fgiDndlXnPAuUy0=; b=h1R66b+D9VEjvqt9DRjBR8tIJuuoChHkANra9jp6g4b3TUdpoVIctNYCgzZl6kjiB5 /u+ST5MXS1MJzyDbeZGP2ZmpaZt3+6zionMOqv0qW+xWleYSXmJJYk9mRgaD3xWdero4 oE/+gLRcizFY23VNXeuNRZIv2TiB58cnIUioalf5SewqBPfuKcfQsWWc5Gt0+Un+5413 C3KWxvyapCxI3JoY//89QfD6eeqXqBKP3gmbKyzp8hjacGEivQQ2oRQFZlD/nyd4jrbf 6PqNdn2ctnolB3Hi99lKcfmu/MrU/7Zmz+CKPnAxApoVi0pS+Wgq/wReS2hdHNE244Wp sDwQ== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id y12-20020a17090629cc00b00965bdbe6dc0si10896596eje.61.2023.05.17.03.25.00; Wed, 17 May 2023 03:25:00 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B3CBF68C1E4; Wed, 17 May 2023 13:21:20 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 18CF468C140 for ; Wed, 17 May 2023 13:20:59 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id CAB45240177 for ; Wed, 17 May 2023 12:20:58 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id mRsiQ2kaKuiD for ; Wed, 17 May 2023 12:20:58 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 65C17240D27 for ; Wed, 17 May 2023 12:20:46 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 6CD983A1EFC for ; Wed, 17 May 2023 12:20:40 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 May 2023 12:20:16 +0200 Message-Id: <20230517102029.541-23-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517102029.541-1-anton@khirnov.net> References: <20230517102029.541-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 23/36] fftools/ffmpeg: eliminate InputStream.got_output 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: dKIpK2g1GrHx It tracks whether the decoder for this stream ever produced any frames and its only use is for checking whether a filter input ever received a frame - those that did not are prioritized by the scheduler. This is awkward and unnecessarily complicated - checking whether the filtergraph input format is valid works just as well and does not require maintaining an extra variable. --- fftools/ffmpeg.c | 3 --- fftools/ffmpeg.h | 2 -- fftools/ffmpeg_filter.c | 2 +- 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 49313edebc..62620bacce 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1412,9 +1412,6 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo break; } - if (got_output) - ist->got_output = 1; - if (!got_output) break; diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 04c41a5311..3a332768df 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -413,8 +413,6 @@ typedef struct InputStream { // number of frames/samples retrieved from the decoder uint64_t frames_decoded; uint64_t samples_decoded; - - int got_output; } InputStream; typedef struct LastFrameDuration { diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 6f842f6b46..640ecec067 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -1700,7 +1700,7 @@ int fg_transcode_step(FilterGraph *graph, InputStream **best_ist) for (int i = 0; i < graph->nb_inputs; i++) { InputFilter *ifilter = graph->inputs[i]; InputFilterPriv *ifp = ifp_from_ifilter(ifilter); - if (!ifp->ist->got_output && !ifp->eof) { + if (ifp->format < 0 && !ifp->eof) { *best_ist = ifp->ist; return 0; } From patchwork Wed May 17 10:20:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41661 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1079727pzb; Wed, 17 May 2023 03:24:43 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5poVoY1OXS+WZUooxzjjEkzfUoxefCuOYtPJu9boq/sJxp6go8ZGql+9GMO7MBIul4GfrY X-Received: by 2002:a17:907:961d:b0:966:6056:a7c1 with SMTP id gb29-20020a170907961d00b009666056a7c1mr35260225ejc.74.1684319083531; Wed, 17 May 2023 03:24:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684319083; cv=none; d=google.com; s=arc-20160816; b=h6rsEm1EoAt5VXiwdUY/Z1nB2vG7sz8LHYK7dqdYx8sCnDMxha/cbuwgYXlnOOlfQJ CSjSMoITmKFrCvemXu5hYLkSChr6LZ0AKE4xls27wM/UAQu0R4lXEnumBdGnmFQk3+nv AZzvDEkixlMKT20zVJ5I1y7+BrhRv1esb01oeLpgz3VlE/DtTsaGYg9jqZ8DsfiFAzNK HfgO0FvrTWwuW7BEGDXMPuYLPgINy5ijK0uzzyi07XYMhjSNyLCrmBsozQC0wNSCcje5 feQPIP0gw07TWkQDLG1kU2rIyboFZIa/o6nmIl2wm4ozPp/JEIdg09odiQtakFVWHAGf voUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=CIlAwTKMSf3B1VKiXLf06Ho3zdTNynqoQQkWOSkD7aY=; b=INrhWeFpR8FtRt++exVpopUs+sOc9rLaNJE4EvQW5TD8nLVBSiUPBF9mQVfU19EaLV KFe9ET4ukZCxYEGh/yf/Xh5zQtT5DzD+tJuwF9y9jcfPju/fVqJ7z/EPrChtrsJHQAQh xu4DWu4fsNhTfXiOoNe94qxNceG7XqubuFnpKtlW/SVSi7i5RE+JxlCxRy3yFMr0SHBb lUwSSJdl6Cq+dAF66z9OPtc/N+u6Mxu4dnUlnzRGYW9zd06U7VqgTNU83UIGVE/IexM2 hAXVhVbwx9CKwe0vS58orIKUlt7tuNoASJqf3rwDHSlLrLHL/SVhjN2ty86ntqXRVIZS ilnA== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id ju23-20020a17090798b700b0096628b28a04si14963423ejc.780.2023.05.17.03.24.43; Wed, 17 May 2023 03:24:43 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9825068C112; Wed, 17 May 2023 13:21:18 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A3D6768C158 for ; Wed, 17 May 2023 13:20:53 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 6B5B82404EC for ; Wed, 17 May 2023 12:20:52 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id P-G4GVmVI2U8 for ; Wed, 17 May 2023 12:20:52 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 2CFA92406CF for ; Wed, 17 May 2023 12:20:46 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 785EC3A1F51 for ; Wed, 17 May 2023 12:20:40 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 May 2023 12:20:17 +0200 Message-Id: <20230517102029.541-24-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517102029.541-1-anton@khirnov.net> References: <20230517102029.541-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 24/36] fftools/ffmpeg: replace an unreachable return with av_assert0(0) 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: mO4IJkvQXIgq This cannot be reached, because initialization will fail if decoding is requested for a stream but no decoder can be found. --- fftools/ffmpeg.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 62620bacce..1fcabd123a 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1390,8 +1390,7 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo ret = AVERROR_EOF; av_packet_unref(avpkt); break; - default: - return -1; + default: av_assert0(0); } if (ret == AVERROR_EOF) { From patchwork Wed May 17 10:20:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41655 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1079198pzb; Wed, 17 May 2023 03:23:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5YNrdFAz0kefY1UioP91Fs2/PRSLPVjtBOhicmGiX3dBYXNf8VO5BvraRktL16H0DfPr46 X-Received: by 2002:a17:907:982:b0:965:7fba:6bcf with SMTP id bf2-20020a170907098200b009657fba6bcfmr35798789ejc.67.1684319022465; Wed, 17 May 2023 03:23:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684319022; cv=none; d=google.com; s=arc-20160816; b=FoF0RYvAFd86IEa/UTumZEXMYYDB4OaFOF/fRq+LiTaoRVenYUvGyT4Ai7e3ViyM6x mlpY6+RhzfM5NDkSeVvXi+n9WsZmf81VypviQuDjPj2Bx1J+OwnYrYUhP3druoofEeww /+yMZ4isVvjYCbg6Cq7okqgZfHZmLYrDbPjKHFlhw3vjCgu2r0U9NCQmnurdIb53yDXw kLmsJ/BnvqUrAXcVVY3PSDMwIvVwVotSMjjLGDdYFxTAtGvWkWAL3xJFCqauQ7Obcnf3 Mpq0JPqCZo0M9vI1sZIIAvSyutXsPFDEMuMPEq41j0v5dLIGGoVFCHDH4+Sp4w3a7eHk OdXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=ya1nHF39mH22jcq0kM4UXfEDvMfsc4btfQG5qqbEZ7U=; b=v+7si5nSEUvdkAfcPCgKg6NScaAvDdQRpccvCHyUOt3AhKlkxetSXT84u+bRbIktDp o2kxy3yRl6Wj3kiDrlUlGxkFKCTASgPZuusdOy5cbz6r37QuTE3+ox8cUdiV4g/psZQ4 lXNrmowSrP3WpUHUv8PzEBgwvJQiwo+nk5SzCikuacF8tAUnDjnXiVcSFE4vPQN/Ovot cHeA8lvDTe0q+8z89EuM1MxF20/NeLZOpMkk8LjQS3HTMYnu6LECiH1IGRlE2fboqwzB DzcAQo8N0wjqyHo6L+G+H1xnYlAluzim53IiH91PWEV4Ngj/9SbhmFmZVwHyeAdN8m5L 09ew== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id n20-20020a170906841400b0094f8f46c1b1si15754677ejx.646.2023.05.17.03.23.42; Wed, 17 May 2023 03:23:42 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 966CC68C17C; Wed, 17 May 2023 13:21:11 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CA92168C13B for ; Wed, 17 May 2023 13:20:57 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 92E54240177 for ; Wed, 17 May 2023 12:20:57 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id b9TPC3Y6pfCB for ; Wed, 17 May 2023 12:20:57 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 5F9E7240D21 for ; Wed, 17 May 2023 12:20:46 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 842793A20E0 for ; Wed, 17 May 2023 12:20:40 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 May 2023 12:20:18 +0200 Message-Id: <20230517102029.541-25-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517102029.541-1-anton@khirnov.net> References: <20230517102029.541-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 25/36] fftools/ffmpeg: deobfuscate check_decode_result() call 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 1pWdtfbpoNy6 Passing ist=NULL is currently used to identify stream types that do not decode into AVFrames, i.e. subtitles. That is highly non-obvious - always pass a non-NULL InputStream and just check the type explicitly. --- fftools/ffmpeg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 1fcabd123a..537f287637 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -777,7 +777,7 @@ static void check_decode_result(InputStream *ist, int *got_output, int ret) if (ret < 0 && exit_on_error) exit_program(1); - if (*got_output && ist) { + if (*got_output && ist->dec_ctx->codec_type != AVMEDIA_TYPE_SUBTITLE) { if (ist->decoded_frame->decode_error_flags || (ist->decoded_frame->flags & AV_FRAME_FLAG_CORRUPT)) { av_log(ist, exit_on_error ? AV_LOG_FATAL : AV_LOG_WARNING, "corrupt decoded frame\n"); @@ -1317,7 +1317,7 @@ static int transcode_subtitles(InputStream *ist, const AVPacket *pkt, int ret = avcodec_decode_subtitle2(ist->dec_ctx, &subtitle, got_output, pkt); - check_decode_result(NULL, got_output, ret); + check_decode_result(ist, got_output, ret); if (ret < 0 || !*got_output) { *decode_failed = 1; From patchwork Wed May 17 10:20:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41685 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1080065pzb; Wed, 17 May 2023 03:25:28 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6a6g6F3n2XtFvoWGr3nxCiYibeIiTiZCdkQt6LMJuZnCY1wKm6Fin0E84VyfTbBReMHf7r X-Received: by 2002:a17:907:96a0:b0:96a:1022:eca0 with SMTP id hd32-20020a17090796a000b0096a1022eca0mr27117583ejc.23.1684319128636; Wed, 17 May 2023 03:25:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684319128; cv=none; d=google.com; s=arc-20160816; b=HxxGBAogSVOoTv8L2V2gyRNX8HhRJAHTEe/EpVghavMUpGm/ZhGAZFby5hcEszGPPu PaV4uEGlBq8KFQez6C9GiQxo+HLgMaq7rhS4rcU+9SETdJJfl1adq47iH57zV8WgkNu4 6aDS7yXGmzoJCCaW5M8G02T7tEABp1aXEgkRkWH4RGzBUZ/DhmAw7gXF9vfH28pF2o5Y SiveZ8ZlfSjnNMvGkKXxES0ZFx/gLM3G8KBnEYi3RTqSwpV2EMldLvOFwS+6AgM3Qo6C 1QhK2S+OfU/QIGT6IR43lXWr6JE37sLByXKYwcm/JmWprRpSadiSOxUnvbTJGzjIQd/m 0wKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=LdkPYrCCCfMNqwVoEn0q7UNZlHNzLLGmLRFzdEnh7CM=; b=QyarWsFfHF/NXo6dpseE5UDbqB3z4039KMbDoE7DcUrjvVRP+wJRkqF9rbGToLaCJb OUBl6XoFBhBojHUhs5E0Qt7j42recHSs5YoGS3fn0m9n9xU1tN5Iyt5CXKkMf9X7nLPa KY/UqKneC9QYcQzBXugTLVxLzCum9Lx/x4699cLn3kmWp2Tru2Y5smfO4kAC6z6fTUuC RXAhXV7oIIlYnUqa5NaSQFGu2hpF6yqpxieNHS/LMaG0kS0cjQQ4rsXUjZgxfQvGb2iA ZN/7kaK6QJPnVwvSb6rvnWO7QhxEPwJW8WzX8KnsCIeGUEyjGb5n4ZFbGibqGRPYyuP3 6xZg== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id u19-20020aa7d993000000b0050d8caa68fdsi16869504eds.159.2023.05.17.03.25.28; Wed, 17 May 2023 03:25:28 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CD87A68C1F8; Wed, 17 May 2023 13:21:23 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id ED3AE68C17F for ; Wed, 17 May 2023 13:21:00 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id BB413240177 for ; Wed, 17 May 2023 12:21:00 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id wq8eCwcqZHZW for ; Wed, 17 May 2023 12:21:00 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 5DBDE240D20 for ; Wed, 17 May 2023 12:20:46 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 8FA283A210F for ; Wed, 17 May 2023 12:20:40 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 May 2023 12:20:19 +0200 Message-Id: <20230517102029.541-26-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517102029.541-1-anton@khirnov.net> References: <20230517102029.541-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 26/36] fftools/ffmpeg: rework handling -max_error_rate 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: lW8834zgwsGU Replace the decode_error_stat global with a per-input-stream variable. Also, print an error message when the error rate is exceeded. --- fftools/ffmpeg.c | 28 ++++++++++++++++------------ fftools/ffmpeg.h | 1 + fftools/ffmpeg_demux.c | 5 +++-- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 537f287637..2e9a2b940a 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -121,7 +121,6 @@ static int64_t getmaxrss(void); int64_t nb_frames_dup = 0; int64_t nb_frames_drop = 0; -static int64_t decode_error_stat[2]; unsigned nb_output_dumped = 0; static BenchmarkTimeStamps current_time; @@ -771,8 +770,8 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti static void check_decode_result(InputStream *ist, int *got_output, int ret) { - if (*got_output || ret<0) - decode_error_stat[ret<0] ++; + if (ret < 0) + ist->decode_errors++; if (ret < 0 && exit_on_error) exit_program(1); @@ -1807,14 +1806,15 @@ static int transcode_step(OutputStream *ost) /* * The following code is the main loop of the file converter */ -static int transcode(void) +static int transcode(int *err_rate_exceeded) { - int ret, i; + int ret = 0, i; InputStream *ist; int64_t timer_start; print_stream_maps(); + *err_rate_exceeded = 0; atomic_store(&transcode_init_done, 1); if (stdin_interaction) { @@ -1858,6 +1858,12 @@ static int transcode(void) if (!input_files[ist->file_index]->eof_reached) { process_input_packet(ist, NULL, 0); } + + if ((ist->frames_decoded + ist->decode_errors) * max_error_rate < ist->decode_errors) { + av_log(ist, AV_LOG_FATAL, "Maximum error rate %g exceeded\n", max_error_rate); + *err_rate_exceeded = 1; + } + } enc_flush(); @@ -1921,7 +1927,7 @@ static int64_t getmaxrss(void) int main(int argc, char **argv) { - int ret; + int ret, err_rate_exceeded; BenchmarkTimeStamps ti; init_dynload(); @@ -1958,7 +1964,7 @@ int main(int argc, char **argv) } current_time = ti = get_benchmark_time_stamps(); - ret = transcode(); + ret = transcode(&err_rate_exceeded); if (ret >= 0 && do_benchmark) { int64_t utime, stime, rtime; current_time = get_benchmark_time_stamps(); @@ -1969,12 +1975,10 @@ int main(int argc, char **argv) "bench: utime=%0.3fs stime=%0.3fs rtime=%0.3fs\n", utime / 1000000.0, stime / 1000000.0, rtime / 1000000.0); } - av_log(NULL, AV_LOG_DEBUG, "%"PRIu64" frames successfully decoded, %"PRIu64" decoding errors\n", - decode_error_stat[0], decode_error_stat[1]); - if ((decode_error_stat[0] + decode_error_stat[1]) * max_error_rate < decode_error_stat[1]) - exit_program(69); - ret = received_nb_signals ? 255 : ret; + ret = received_nb_signals ? 255 : + err_rate_exceeded ? 69 : ret; + exit_program(ret); return ret; } diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 3a332768df..87e684a147 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -413,6 +413,7 @@ typedef struct InputStream { // number of frames/samples retrieved from the decoder uint64_t frames_decoded; uint64_t samples_decoded; + uint64_t decode_errors; } InputStream; typedef struct LastFrameDuration { diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index df87e0f30a..401ae1f850 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -786,8 +786,9 @@ static void demux_final_stats(Demuxer *d) ds->nb_packets, ds->data_size); if (ist->decoding_needed) { - av_log(f, AV_LOG_VERBOSE, "%"PRIu64" frames decoded", - ist->frames_decoded); + av_log(f, AV_LOG_VERBOSE, + "%"PRIu64" frames decoded; %"PRIu64" decode errors", + ist->frames_decoded, ist->decode_errors); if (type == AVMEDIA_TYPE_AUDIO) av_log(f, AV_LOG_VERBOSE, " (%"PRIu64" samples)", ist->samples_decoded); av_log(f, AV_LOG_VERBOSE, "; "); From patchwork Wed May 17 10:20:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41683 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1079973pzb; Wed, 17 May 2023 03:25:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7RcD/rKGK2MsjveMqkEx0mABf3c365sX9CUJgxCwOA5RzJkdVPlnbrqPtnVWaozpA3YEFF X-Received: by 2002:a50:ef04:0:b0:510:47a3:e775 with SMTP id m4-20020a50ef04000000b0051047a3e775mr1668995eds.41.1684319114433; Wed, 17 May 2023 03:25:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684319114; cv=none; d=google.com; s=arc-20160816; b=X+ZsFyQwOCmT9G2hZ8qxp8xzwk3G/+XygF9n2ED/iHsuUlzcq9L0zFkvZRz1oTo51F 8Ml6f6VNKzOoWvCwIM0uX/q6eD3QUC5UEWZ9AwWUBFdMzBfO8Idza3lcs4BHZ94lSN4N HxihB9JDwgoWC8hVM6yIVUqCCm9kunS4fvqYaBAlugtsnrlTAXSkQssVd7In29Sg0Ac4 +hJ1T+5stWIyKJkejuNpQw1Q3uv4j0bLY55AEeYFZRptAFIH9VRRML1HRZvOggSDnz+U yKnQJ/I160KUxtgHIzJaFa65hGp05cjAjIFm4W5Md6cep/IOqE/ZvcDyOT1WOPbIhqHX oLyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=3thTJrcX0fz2Eu/GbjLm65+gsGQCgsj7q+e+itfepUA=; b=BUmRFDwp44MLs/LE7o+QQW1CMaJTiVfJ78KZ4UZtKD74UXuiueWX3d/hYe1GrWxq0I 6oTK4itGht5+AgnRwhbAlXHByesqHeQ+Jp8UIOKLZkxjKl/XsmzTaZ7SaB6f+28ir394 jqXKYAgrU0d42LOyv7MFanhzAfwNG87ZeTMBJmBI+KLJFNWBHwLHURiXhjiLXY6zfA7p 3O66Wpwki3iyd0pIqBvuC9qVJ9fhQN91H1GhevxHaNTo47oJ0wGBpeWpf2wWWHEEo/CX mu+TtO+uObWXLXSgZjGET7B3aAW9Ki+E8ANqqCp5OUrs+YIriPiioR7CTkyPjh323BKZ +1Sw== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id f12-20020aa7d84c000000b0050bd5e5d7a8si14048428eds.223.2023.05.17.03.25.08; Wed, 17 May 2023 03:25:14 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CC07E68C1E9; Wed, 17 May 2023 13:21:21 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 88ACF68C155 for ; Wed, 17 May 2023 13:20:59 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 57017240177 for ; Wed, 17 May 2023 12:20:59 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id NOeeqPG6a0uG for ; Wed, 17 May 2023 12:20:58 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 6270F240D23 for ; Wed, 17 May 2023 12:20:46 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 9A8183A2122 for ; Wed, 17 May 2023 12:20:40 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 May 2023 12:20:20 +0200 Message-Id: <20230517102029.541-27-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517102029.541-1-anton@khirnov.net> References: <20230517102029.541-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 27/36] fftools/ffmpeg: move a block to a more appropriate place 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: eLVvySKcj6BG New placement requires fewer explicit conditions and is easier to understand. The logic should be exactly equivalent, since this is the only place where eof_reached is set for decoding. --- fftools/ffmpeg.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 2e9a2b940a..4cf8b54dc0 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1393,6 +1393,16 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo } if (ret == AVERROR_EOF) { + /* after flushing, send an EOF on all the filter inputs attached to the stream */ + /* except when looping we need to flush but not to send an EOF */ + if (!no_eof) { + ret = send_filter_eof(ist); + if (ret < 0) { + av_log(NULL, AV_LOG_FATAL, "Error marking filters as finished\n"); + exit_program(1); + } + } + eof_reached = 1; break; } @@ -1416,16 +1426,6 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo repeating = 1; } - /* after flushing, send an EOF on all the filter inputs attached to the stream */ - /* except when looping we need to flush but not to send an EOF */ - if (!pkt && ist->decoding_needed && eof_reached && !no_eof) { - int ret = send_filter_eof(ist); - if (ret < 0) { - av_log(NULL, AV_LOG_FATAL, "Error marking filters as finished\n"); - exit_program(1); - } - } - if (!pkt && !ist->decoding_needed) eof_reached = 1; From patchwork Wed May 17 10:20:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41664 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1078383pzb; Wed, 17 May 2023 03:22:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4JDmID19FIaIYfen5U3jibnZ4wfZt0zrJB6zHuiOBWdQQ7KzdEIfIed025KwW4SHQN3yWk X-Received: by 2002:a05:6402:128d:b0:509:d476:3a12 with SMTP id w13-20020a056402128d00b00509d4763a12mr1326516edv.34.1684318927503; Wed, 17 May 2023 03:22:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684318927; cv=none; d=google.com; s=arc-20160816; b=0s8/mBgRn4W5ZncgS8Rpt6QMBAP5Vid7xyGdadjO8I6jqEci8bJKpKEc9CXP6gXkgw VccRptPEt5WjVdN2VVJJuRVqVXoZpVS0oaVobQzBljT/9aLHszXms/KZYH7RwOLUBNrm KhrNIya8Xi1bm5BK37u1dRzfBdTM5dnSid1vcGeb5U9r75iO7K8s2kkQ/bHeMsoOJ33E 9nCtxwIGwXcfq9NEVnCMYpsacslOloZiwh1jzZ9ak0xMBMcfNopxl4rC3tx9mSSo3VXQ AJJ2oLK4S7TrOsGPci/QFaELETjLODJX1zFt2977lKHH97aC8jzbEfBJeQErP5itn1gZ fe0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=X4kc92iFtsm5gO+eP9Vy+9gr8FLuKtvi7iIuWqkcNP0=; b=RqotV5zVmyp3vvWbxTP0K2c0a4M3jW7zi6S2LdU7ypCVKlaB9EWeFl262jUZX/KrrD k0Jf7QGG1zWTRBCtSsZmLZoGK23qRJmo814A+gY+3GUmiv4Nt8MfJs/n7ouEHiowYLOE CVbYjrArOaGb3jNbGFQl3U6pv+lm0YO1MilZzdqLOUhWaUtF8TaUz/ffK8nfprWD7LGh SnVcuu6fh3cBSzC4HAN7XiwwjV0Q5gcUiNDJxUws5KuYgKbqCbIcVgxR2nt6A3Bn43Dz a54oJQhiN69xPPDzvB+RMnJzrchxDjkkuTQDQr+kFTTS7JyxSfPkdEkus9ozocZfvqmp R8WQ== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id n23-20020a056402515700b0050bd245d39asi1612778edd.160.2023.05.17.03.22.06; Wed, 17 May 2023 03:22:07 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BE01B68C17E; Wed, 17 May 2023 13:21:00 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6F76568C12D for ; Wed, 17 May 2023 13:20:57 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 340C02406CF for ; Wed, 17 May 2023 12:20:54 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 5M9_yiwKw_XR for ; Wed, 17 May 2023 12:20:53 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 38529240D0E for ; Wed, 17 May 2023 12:20:46 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id A64573A2125 for ; Wed, 17 May 2023 12:20:40 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 May 2023 12:20:21 +0200 Message-Id: <20230517102029.541-28-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517102029.541-1-anton@khirnov.net> References: <20230517102029.541-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 28/36] fftools/ffmpeg: split decoding loop out of process_input_packet() 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 6PRtIbJ3zi17 process_input_packet() contains two non-interacting pieces of nontrivial size and complexity - decoding and streamcopy. Separating them makes the code easier to read. --- fftools/ffmpeg.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 4cf8b54dc0..e84add50e5 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1344,18 +1344,10 @@ static int send_filter_eof(InputStream *ist) return 0; } -/* pkt = NULL means EOF (needed to flush decoder buffers) */ -static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eof) +static int dec_packet(InputStream *ist, const AVPacket *pkt, int no_eof) { - InputFile *f = input_files[ist->file_index]; - const AVCodecParameters *par = ist->par; - int64_t dts_est = AV_NOPTS_VALUE; - int ret = 0; - int repeating = 0; - int eof_reached = 0; - int duration_exceeded; - AVPacket *avpkt = ist->pkt; + int ret, repeating = 0; if (pkt) { av_packet_unref(avpkt); @@ -1365,11 +1357,11 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo } // while we have more to decode or while the decoder did output something on EOF - while (ist->decoding_needed) { + while (1) { int got_output = 0; int decode_failed = 0; - switch (par->codec_type) { + switch (ist->par->codec_type) { case AVMEDIA_TYPE_AUDIO: ret = decode_audio (ist, repeating ? NULL : avpkt, &got_output, &decode_failed); @@ -1403,8 +1395,7 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo } } - eof_reached = 1; - break; + return AVERROR_EOF; } if (ret < 0) { @@ -1417,16 +1408,28 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo } if (!decode_failed || exit_on_error) exit_program(1); - break; + return ret; } if (!got_output) - break; + return 0; repeating = 1; } +} + +/* pkt = NULL means EOF (needed to flush decoder buffers) */ +static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eof) +{ + InputFile *f = input_files[ist->file_index]; + int64_t dts_est = AV_NOPTS_VALUE; + int ret = 0; + int eof_reached = 0; + int duration_exceeded; - if (!pkt && !ist->decoding_needed) + if (ist->decoding_needed) + ret = dec_packet(ist, pkt, no_eof); + if (ret == AVERROR_EOF || (!pkt && !ist->decoding_needed)) eof_reached = 1; if (pkt && pkt->opaque_ref) { From patchwork Wed May 17 10:20:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41684 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1080011pzb; Wed, 17 May 2023 03:25:19 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7FxZg6H6s5nBjdWdZrDm+lrRBbf2Oo5zvz03mZxyMg6ahuAPLUgkbWzBeUZSFupdTpFEYd X-Received: by 2002:a17:907:9606:b0:932:7f5c:4bb2 with SMTP id gb6-20020a170907960600b009327f5c4bb2mr39712685ejc.75.1684319119160; Wed, 17 May 2023 03:25:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684319119; cv=none; d=google.com; s=arc-20160816; b=ztiILtIzLJQ4Nov3CUXlArTOKN4PiVNklYBcOiXbdR7e8zdHEB26dglD1dxbKpaA5j e66zukaNlw0D90l/UJIs9AfN36ZuSb2b3ffJsLFGlYyMm9f2tAvNEtg8XJte42u52awd BDgOuKw8ctMDBiRml0mWyhvLpn2gfDkj7cG9WX6MWO753BBPWtucLaPfSaVvYMD6HOdk tXDEVZv/yTt0Ag6JrsYEqh5gdxRJZ77EGfQKQoy0YOgO0s62w4Ppf2z1kXFKpI3uMihM Ooy4YDszSsGUI258ntVuV8o0xqDddDJM1Zmgk3d2m0ppN+7+8mqjm95hSbKPZJJHkW7X TtHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=OCWfDnhZZdvlRrChpfh3HMlrk9NjceXROglIYIUkwU4=; b=sIGjaaq1FrF2Jb3jWALw5RpuJ4PpKBPYxp/Rq8CvOuoSpUNJ1736Ie6PewezWz33Kp 406Ns6Aaz/5pGn1YrhlTihhHbkSAzR9J/wXuUrcJrrrosxU/N9VWCbN9xz5NEO/BsSv8 PTl/R6vOiVdEDQeujhgn4z4kWY3A0bvL6RNqLNj1u4Ko9VWryb6GyIlaTlnXfZ55G69Q XZRa5+ey5nMuM41EaHzlFmOUfon9iZQrtQBCcgX/RdFrnHBJbSvh6wRfpPdKYjOXyVKE n7CsWkvZJpu3u/l3AB3GjQbPGQZMts0oCZ4HMOdLOZ8Fula6YgYpkYEJCUkyanXz12OA A1aw== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id w19-20020a1709064a1300b00965c55d9e9csi16527657eju.670.2023.05.17.03.25.18; Wed, 17 May 2023 03:25:19 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DECF568C1F1; Wed, 17 May 2023 13:21:22 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 53E4468C178 for ; Wed, 17 May 2023 13:21:00 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 109CC240177 for ; Wed, 17 May 2023 12:21:00 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 16Embgjl6x8M for ; Wed, 17 May 2023 12:20:57 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 39FC4240D1A for ; Wed, 17 May 2023 12:20:46 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id B27D23A21C7 for ; Wed, 17 May 2023 12:20:40 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 May 2023 12:20:22 +0200 Message-Id: <20230517102029.541-29-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517102029.541-1-anton@khirnov.net> References: <20230517102029.541-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 29/36] fftools/ffmpeg: move decoding code to ffmpeg_dec 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: PBgM0jAL7zhc --- fftools/ffmpeg.c | 534 ------------------------------------------ fftools/ffmpeg.h | 12 + fftools/ffmpeg_dec.c | 538 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 550 insertions(+), 534 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index e84add50e5..baa2f95f5d 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -283,20 +283,6 @@ static void sub2video_heartbeat(InputStream *ist, int64_t pts) } } -static void sub2video_flush(InputStream *ist) -{ - int i; - int ret; - - if (ist->sub2video.end_pts < INT64_MAX) - sub2video_update(ist, INT64_MAX, NULL); - for (i = 0; i < ist->nb_filters; i++) { - ret = av_buffersrc_add_frame(ist->filters[i]->filter, NULL); - if (ret != AVERROR_EOF && ret < 0) - av_log(NULL, AV_LOG_WARNING, "Flush the frame error.\n"); - } -} - /* end of sub2video hack */ static void term_exit_sigsafe(void) @@ -768,417 +754,6 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti first_report = 0; } -static void check_decode_result(InputStream *ist, int *got_output, int ret) -{ - if (ret < 0) - ist->decode_errors++; - - if (ret < 0 && exit_on_error) - exit_program(1); - - if (*got_output && ist->dec_ctx->codec_type != AVMEDIA_TYPE_SUBTITLE) { - if (ist->decoded_frame->decode_error_flags || (ist->decoded_frame->flags & AV_FRAME_FLAG_CORRUPT)) { - av_log(ist, exit_on_error ? AV_LOG_FATAL : AV_LOG_WARNING, - "corrupt decoded frame\n"); - if (exit_on_error) - exit_program(1); - } - } -} - -// This does not quite work like avcodec_decode_audio4/avcodec_decode_video2. -// There is the following difference: if you got a frame, you must call -// it again with pkt=NULL. pkt==NULL is treated differently from pkt->size==0 -// (pkt==NULL means get more output, pkt->size==0 is a flush/drain packet) -static int decode(InputStream *ist, AVCodecContext *avctx, - AVFrame *frame, int *got_frame, const AVPacket *pkt) -{ - int ret; - - *got_frame = 0; - - if (pkt) { - ret = avcodec_send_packet(avctx, pkt); - // In particular, we don't expect AVERROR(EAGAIN), because we read all - // decoded frames with avcodec_receive_frame() until done. - if (ret < 0 && ret != AVERROR_EOF) - return ret; - } - - ret = avcodec_receive_frame(avctx, frame); - if (ret < 0 && ret != AVERROR(EAGAIN)) - return ret; - if (ret >= 0) { - if (ist->want_frame_data) { - FrameData *fd; - - av_assert0(!frame->opaque_ref); - frame->opaque_ref = av_buffer_allocz(sizeof(*fd)); - if (!frame->opaque_ref) { - av_frame_unref(frame); - return AVERROR(ENOMEM); - } - fd = (FrameData*)frame->opaque_ref->data; - fd->pts = frame->pts; - fd->tb = avctx->pkt_timebase; - fd->idx = avctx->frame_num - 1; - } - - frame->time_base = avctx->pkt_timebase; - - *got_frame = 1; - } - - return 0; -} - -static int send_frame_to_filters(InputStream *ist, AVFrame *decoded_frame) -{ - int i, ret; - - av_assert1(ist->nb_filters > 0); /* ensure ret is initialized */ - for (i = 0; i < ist->nb_filters; i++) { - ret = ifilter_send_frame(ist->filters[i], decoded_frame, i < ist->nb_filters - 1); - if (ret == AVERROR_EOF) - ret = 0; /* ignore */ - if (ret < 0) { - av_log(NULL, AV_LOG_ERROR, - "Failed to inject frame into filter network: %s\n", av_err2str(ret)); - break; - } - } - return ret; -} - -static AVRational audio_samplerate_update(InputStream *ist, const AVFrame *frame) -{ - const int prev = ist->last_frame_tb.den; - const int sr = frame->sample_rate; - - AVRational tb_new; - int64_t gcd; - - if (frame->sample_rate == ist->last_frame_sample_rate) - goto finish; - - gcd = av_gcd(prev, sr); - - if (prev / gcd >= INT_MAX / sr) { - av_log(ist, AV_LOG_WARNING, - "Audio timestamps cannot be represented exactly after " - "sample rate change: %d -> %d\n", prev, sr); - - // LCM of 192000, 44100, allows to represent all common samplerates - tb_new = (AVRational){ 1, 28224000 }; - } else - tb_new = (AVRational){ 1, prev / gcd * sr }; - - // keep the frame timebase if it is strictly better than - // the samplerate-defined one - if (frame->time_base.num == 1 && frame->time_base.den > tb_new.den && - !(frame->time_base.den % tb_new.den)) - tb_new = frame->time_base; - - if (ist->last_frame_pts != AV_NOPTS_VALUE) - ist->last_frame_pts = av_rescale_q(ist->last_frame_pts, - ist->last_frame_tb, tb_new); - ist->last_frame_duration_est = av_rescale_q(ist->last_frame_duration_est, - ist->last_frame_tb, tb_new); - - ist->last_frame_tb = tb_new; - ist->last_frame_sample_rate = frame->sample_rate; - -finish: - return ist->last_frame_tb; -} - -static void audio_ts_process(InputStream *ist, AVFrame *frame) -{ - AVRational tb_filter = (AVRational){1, frame->sample_rate}; - AVRational tb; - int64_t pts_pred; - - // on samplerate change, choose a new internal timebase for timestamp - // generation that can represent timestamps from all the samplerates - // seen so far - tb = audio_samplerate_update(ist, frame); - pts_pred = ist->last_frame_pts == AV_NOPTS_VALUE ? 0 : - ist->last_frame_pts + ist->last_frame_duration_est; - - if (frame->pts == AV_NOPTS_VALUE) { - frame->pts = pts_pred; - frame->time_base = tb; - } else if (ist->last_frame_pts != AV_NOPTS_VALUE && - frame->pts > av_rescale_q_rnd(pts_pred, tb, frame->time_base, - AV_ROUND_UP)) { - // there was a gap in timestamps, reset conversion state - ist->filter_in_rescale_delta_last = AV_NOPTS_VALUE; - } - - frame->pts = av_rescale_delta(frame->time_base, frame->pts, - tb, frame->nb_samples, - &ist->filter_in_rescale_delta_last, tb); - - ist->last_frame_pts = frame->pts; - ist->last_frame_duration_est = av_rescale_q(frame->nb_samples, - tb_filter, tb); - - // finally convert to filtering timebase - frame->pts = av_rescale_q(frame->pts, tb, tb_filter); - frame->duration = frame->nb_samples; - frame->time_base = tb_filter; -} - -static int decode_audio(InputStream *ist, const AVPacket *pkt, int *got_output, - int *decode_failed) -{ - AVFrame *decoded_frame = ist->decoded_frame; - AVCodecContext *avctx = ist->dec_ctx; - int ret, err = 0; - - update_benchmark(NULL); - ret = decode(ist, avctx, decoded_frame, got_output, pkt); - update_benchmark("decode_audio %d.%d", ist->file_index, ist->st->index); - if (ret < 0) - *decode_failed = 1; - - if (ret != AVERROR_EOF) - check_decode_result(ist, got_output, ret); - - if (!*got_output || ret < 0) - return ret; - - ist->samples_decoded += decoded_frame->nb_samples; - ist->frames_decoded++; - - audio_ts_process(ist, decoded_frame); - - ist->nb_samples = decoded_frame->nb_samples; - err = send_frame_to_filters(ist, decoded_frame); - - av_frame_unref(decoded_frame); - return err < 0 ? err : ret; -} - -static int64_t video_duration_estimate(const InputStream *ist, const AVFrame *frame) -{ - const InputFile *ifile = input_files[ist->file_index]; - int64_t codec_duration = 0; - - // XXX lavf currently makes up frame durations when they are not provided by - // the container. As there is no way to reliably distinguish real container - // durations from the fake made-up ones, we use heuristics based on whether - // the container has timestamps. Eventually lavf should stop making up - // durations, then this should be simplified. - - // prefer frame duration for containers with timestamps - if (frame->duration > 0 && (!ifile->format_nots || ist->framerate.num)) - return frame->duration; - - if (ist->dec_ctx->framerate.den && ist->dec_ctx->framerate.num) { - int fields = frame->repeat_pict + 2; - AVRational field_rate = av_mul_q(ist->dec_ctx->framerate, - (AVRational){ 2, 1 }); - codec_duration = av_rescale_q(fields, av_inv_q(field_rate), - frame->time_base); - } - - // prefer codec-layer duration for containers without timestamps - if (codec_duration > 0 && ifile->format_nots) - return codec_duration; - - // when timestamps are available, repeat last frame's actual duration - // (i.e. pts difference between this and last frame) - if (frame->pts != AV_NOPTS_VALUE && ist->last_frame_pts != AV_NOPTS_VALUE && - frame->pts > ist->last_frame_pts) - return frame->pts - ist->last_frame_pts; - - // try frame/codec duration - if (frame->duration > 0) - return frame->duration; - if (codec_duration > 0) - return codec_duration; - - // try average framerate - if (ist->st->avg_frame_rate.num && ist->st->avg_frame_rate.den) { - int64_t d = av_rescale_q(1, av_inv_q(ist->st->avg_frame_rate), - frame->time_base); - if (d > 0) - return d; - } - - // last resort is last frame's estimated duration, and 1 - return FFMAX(ist->last_frame_duration_est, 1); -} - -static int decode_video(InputStream *ist, const AVPacket *pkt, int *got_output, - int eof, int *decode_failed) -{ - AVFrame *frame = ist->decoded_frame; - int ret = 0, err = 0; - - // With fate-indeo3-2, we're getting 0-sized packets before EOF for some - // reason. This seems like a semi-critical bug. Don't trigger EOF, and - // skip the packet. - if (!eof && pkt && pkt->size == 0) - return 0; - - update_benchmark(NULL); - ret = decode(ist, ist->dec_ctx, frame, got_output, pkt); - update_benchmark("decode_video %d.%d", ist->file_index, ist->st->index); - if (ret < 0) - *decode_failed = 1; - - // The following line may be required in some cases where there is no parser - // or the parser does not has_b_frames correctly - if (ist->par->video_delay < ist->dec_ctx->has_b_frames) { - if (ist->dec_ctx->codec_id == AV_CODEC_ID_H264) { - ist->par->video_delay = ist->dec_ctx->has_b_frames; - } else - av_log(ist->dec_ctx, AV_LOG_WARNING, - "video_delay is larger in decoder than demuxer %d > %d.\n" - "If you want to help, upload a sample " - "of this file to https://streams.videolan.org/upload/ " - "and contact the ffmpeg-devel mailing list. (ffmpeg-devel@ffmpeg.org)\n", - ist->dec_ctx->has_b_frames, - ist->par->video_delay); - } - - if (ret != AVERROR_EOF) - check_decode_result(ist, got_output, ret); - - if (*got_output && ret >= 0) { - if (ist->dec_ctx->width != frame->width || - ist->dec_ctx->height != frame->height || - ist->dec_ctx->pix_fmt != frame->format) { - av_log(NULL, AV_LOG_DEBUG, "Frame parameters mismatch context %d,%d,%d != %d,%d,%d\n", - frame->width, - frame->height, - frame->format, - ist->dec_ctx->width, - ist->dec_ctx->height, - ist->dec_ctx->pix_fmt); - } - } - - if (!*got_output || ret < 0) - return ret; - - if(ist->top_field_first>=0) - frame->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST; - - ist->frames_decoded++; - - if (ist->hwaccel_retrieve_data && frame->format == ist->hwaccel_pix_fmt) { - err = ist->hwaccel_retrieve_data(ist->dec_ctx, frame); - if (err < 0) - goto fail; - } - - frame->pts = frame->best_effort_timestamp; - - // forced fixed framerate - if (ist->framerate.num) { - frame->pts = AV_NOPTS_VALUE; - frame->duration = 1; - frame->time_base = av_inv_q(ist->framerate); - } - - // no timestamp available - extrapolate from previous frame duration - if (frame->pts == AV_NOPTS_VALUE) - frame->pts = ist->last_frame_pts == AV_NOPTS_VALUE ? 0 : - ist->last_frame_pts + ist->last_frame_duration_est; - - // update timestamp history - ist->last_frame_duration_est = video_duration_estimate(ist, frame); - ist->last_frame_pts = frame->pts; - ist->last_frame_tb = frame->time_base; - - if (debug_ts) { - av_log(ist, AV_LOG_INFO, - "decoder -> pts:%s pts_time:%s " - "pkt_dts:%s pkt_dts_time:%s " - "duration:%s duration_time:%s " - "keyframe:%d frame_type:%d time_base:%d/%d\n", - av_ts2str(frame->pts), - av_ts2timestr(frame->pts, &frame->time_base), - av_ts2str(frame->pkt_dts), - av_ts2timestr(frame->pkt_dts, &frame->time_base), - av_ts2str(frame->duration), - av_ts2timestr(frame->duration, &frame->time_base), - !!(frame->flags & AV_FRAME_FLAG_KEY), frame->pict_type, - frame->time_base.num, frame->time_base.den); - } - - if (ist->st->sample_aspect_ratio.num) - frame->sample_aspect_ratio = ist->st->sample_aspect_ratio; - - err = send_frame_to_filters(ist, frame); - -fail: - av_frame_unref(frame); - return err < 0 ? err : ret; -} - -static int process_subtitle(InputStream *ist, AVSubtitle *subtitle, int *got_output) -{ - int ret = 0; - int free_sub = 1; - - if (ist->fix_sub_duration) { - int end = 1; - if (ist->prev_sub.got_output) { - end = av_rescale(subtitle->pts - ist->prev_sub.subtitle.pts, - 1000, AV_TIME_BASE); - if (end < ist->prev_sub.subtitle.end_display_time) { - av_log(NULL, AV_LOG_DEBUG, - "Subtitle duration reduced from %"PRId32" to %d%s\n", - ist->prev_sub.subtitle.end_display_time, end, - end <= 0 ? ", dropping it" : ""); - ist->prev_sub.subtitle.end_display_time = end; - } - } - FFSWAP(int, *got_output, ist->prev_sub.got_output); - FFSWAP(int, ret, ist->prev_sub.ret); - FFSWAP(AVSubtitle, *subtitle, ist->prev_sub.subtitle); - if (end <= 0) - goto out; - } - - if (!*got_output) - return ret; - - if (ist->sub2video.frame) { - sub2video_update(ist, INT64_MIN, subtitle); - } else if (ist->nb_filters) { - if (!ist->sub2video.sub_queue) - ist->sub2video.sub_queue = av_fifo_alloc2(8, sizeof(AVSubtitle), AV_FIFO_FLAG_AUTO_GROW); - if (!ist->sub2video.sub_queue) - report_and_exit(AVERROR(ENOMEM)); - - ret = av_fifo_write(ist->sub2video.sub_queue, subtitle, 1); - if (ret < 0) - exit_program(1); - free_sub = 0; - } - - if (!subtitle->num_rects) - goto out; - - for (int oidx = 0; oidx < ist->nb_outputs; oidx++) { - OutputStream *ost = ist->outputs[oidx]; - if (!ost->enc || ost->type != AVMEDIA_TYPE_SUBTITLE) - continue; - - enc_subtitle(output_files[ost->file_index], ost, subtitle); - } - -out: - if (free_sub) - avsubtitle_free(subtitle); - return ret; -} - static int copy_av_subtitle(AVSubtitle *dst, AVSubtitle *src) { int ret = AVERROR_BUG; @@ -1309,115 +884,6 @@ int trigger_fix_sub_duration_heartbeat(OutputStream *ost, const AVPacket *pkt) return 0; } -static int transcode_subtitles(InputStream *ist, const AVPacket *pkt, - int *got_output, int *decode_failed) -{ - AVSubtitle subtitle; - int ret = avcodec_decode_subtitle2(ist->dec_ctx, - &subtitle, got_output, pkt); - - check_decode_result(ist, got_output, ret); - - if (ret < 0 || !*got_output) { - *decode_failed = 1; - if (!pkt->size) - sub2video_flush(ist); - return ret; - } - - ist->frames_decoded++; - - return process_subtitle(ist, &subtitle, got_output); -} - -static int send_filter_eof(InputStream *ist) -{ - int i, ret; - - for (i = 0; i < ist->nb_filters; i++) { - int64_t end_pts = ist->last_frame_pts == AV_NOPTS_VALUE ? AV_NOPTS_VALUE : - ist->last_frame_pts + ist->last_frame_duration_est; - ret = ifilter_send_eof(ist->filters[i], end_pts, ist->last_frame_tb); - if (ret < 0) - return ret; - } - return 0; -} - -static int dec_packet(InputStream *ist, const AVPacket *pkt, int no_eof) -{ - AVPacket *avpkt = ist->pkt; - int ret, repeating = 0; - - if (pkt) { - av_packet_unref(avpkt); - ret = av_packet_ref(avpkt, pkt); - if (ret < 0) - return ret; - } - - // while we have more to decode or while the decoder did output something on EOF - while (1) { - int got_output = 0; - int decode_failed = 0; - - switch (ist->par->codec_type) { - case AVMEDIA_TYPE_AUDIO: - ret = decode_audio (ist, repeating ? NULL : avpkt, &got_output, - &decode_failed); - av_packet_unref(avpkt); - break; - case AVMEDIA_TYPE_VIDEO: - ret = decode_video (ist, repeating ? NULL : avpkt, &got_output, !pkt, - &decode_failed); - - av_packet_unref(avpkt); - break; - case AVMEDIA_TYPE_SUBTITLE: - if (repeating) - break; - ret = transcode_subtitles(ist, avpkt, &got_output, &decode_failed); - if (!pkt && ret >= 0) - ret = AVERROR_EOF; - av_packet_unref(avpkt); - break; - default: av_assert0(0); - } - - if (ret == AVERROR_EOF) { - /* after flushing, send an EOF on all the filter inputs attached to the stream */ - /* except when looping we need to flush but not to send an EOF */ - if (!no_eof) { - ret = send_filter_eof(ist); - if (ret < 0) { - av_log(NULL, AV_LOG_FATAL, "Error marking filters as finished\n"); - exit_program(1); - } - } - - return AVERROR_EOF; - } - - if (ret < 0) { - if (decode_failed) { - av_log(NULL, AV_LOG_ERROR, "Error while decoding stream #%d:%d: %s\n", - ist->file_index, ist->st->index, av_err2str(ret)); - } else { - av_log(NULL, AV_LOG_FATAL, "Error while processing the decoded " - "data for stream #%d:%d\n", ist->file_index, ist->st->index); - } - if (!decode_failed || exit_on_error) - exit_program(1); - return ret; - } - - if (!got_output) - return 0; - - repeating = 1; - } -} - /* pkt = NULL means EOF (needed to flush decoder buffers) */ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eof) { diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 87e684a147..45be3b1823 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -811,6 +811,17 @@ int hwaccel_decode_init(AVCodecContext *avctx); int dec_open(InputStream *ist); +/** + * Submit a packet for decoding + * + * When pkt==NULL and no_eof=0, there will be no more input. Flush decoders and + * mark all downstreams as finished. + * + * When pkt==NULL and no_eof=1, the stream was reset (e.g. after a seek). Flush + * decoders and await further input. + */ +int dec_packet(InputStream *ist, const AVPacket *pkt, int no_eof); + int enc_alloc(Encoder **penc, const AVCodec *codec); void enc_free(Encoder **penc); @@ -885,6 +896,7 @@ OutputStream *ost_iter(OutputStream *prev); void close_output_stream(OutputStream *ost); int trigger_fix_sub_duration_heartbeat(OutputStream *ost, const AVPacket *pkt); +int process_subtitle(InputStream *ist, AVSubtitle *subtitle, int *got_output); void update_benchmark(const char *fmt, ...); /** diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c index 658e7418e9..30fe75d8a6 100644 --- a/fftools/ffmpeg_dec.c +++ b/fftools/ffmpeg_dec.c @@ -16,17 +16,555 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/avassert.h" #include "libavutil/dict.h" #include "libavutil/error.h" #include "libavutil/log.h" #include "libavutil/pixdesc.h" #include "libavutil/pixfmt.h" +#include "libavutil/timestamp.h" #include "libavcodec/avcodec.h" #include "libavcodec/codec.h" +#include "libavfilter/buffersrc.h" + #include "ffmpeg.h" +static void check_decode_result(InputStream *ist, int *got_output, int ret) +{ + if (ret < 0) + ist->decode_errors++; + + if (ret < 0 && exit_on_error) + exit_program(1); + + if (*got_output && ist->dec_ctx->codec_type != AVMEDIA_TYPE_SUBTITLE) { + if (ist->decoded_frame->decode_error_flags || (ist->decoded_frame->flags & AV_FRAME_FLAG_CORRUPT)) { + av_log(ist, exit_on_error ? AV_LOG_FATAL : AV_LOG_WARNING, + "corrupt decoded frame\n"); + if (exit_on_error) + exit_program(1); + } + } +} + +// This does not quite work like avcodec_decode_audio4/avcodec_decode_video2. +// There is the following difference: if you got a frame, you must call +// it again with pkt=NULL. pkt==NULL is treated differently from pkt->size==0 +// (pkt==NULL means get more output, pkt->size==0 is a flush/drain packet) +static int decode(InputStream *ist, AVCodecContext *avctx, + AVFrame *frame, int *got_frame, const AVPacket *pkt) +{ + int ret; + + *got_frame = 0; + + if (pkt) { + ret = avcodec_send_packet(avctx, pkt); + // In particular, we don't expect AVERROR(EAGAIN), because we read all + // decoded frames with avcodec_receive_frame() until done. + if (ret < 0 && ret != AVERROR_EOF) + return ret; + } + + ret = avcodec_receive_frame(avctx, frame); + if (ret < 0 && ret != AVERROR(EAGAIN)) + return ret; + if (ret >= 0) { + if (ist->want_frame_data) { + FrameData *fd; + + av_assert0(!frame->opaque_ref); + frame->opaque_ref = av_buffer_allocz(sizeof(*fd)); + if (!frame->opaque_ref) { + av_frame_unref(frame); + return AVERROR(ENOMEM); + } + fd = (FrameData*)frame->opaque_ref->data; + fd->pts = frame->pts; + fd->tb = avctx->pkt_timebase; + fd->idx = avctx->frame_num - 1; + } + + frame->time_base = avctx->pkt_timebase; + + *got_frame = 1; + } + + return 0; +} + +static int send_frame_to_filters(InputStream *ist, AVFrame *decoded_frame) +{ + int i, ret; + + av_assert1(ist->nb_filters > 0); /* ensure ret is initialized */ + for (i = 0; i < ist->nb_filters; i++) { + ret = ifilter_send_frame(ist->filters[i], decoded_frame, i < ist->nb_filters - 1); + if (ret == AVERROR_EOF) + ret = 0; /* ignore */ + if (ret < 0) { + av_log(NULL, AV_LOG_ERROR, + "Failed to inject frame into filter network: %s\n", av_err2str(ret)); + break; + } + } + return ret; +} + +static AVRational audio_samplerate_update(InputStream *ist, const AVFrame *frame) +{ + const int prev = ist->last_frame_tb.den; + const int sr = frame->sample_rate; + + AVRational tb_new; + int64_t gcd; + + if (frame->sample_rate == ist->last_frame_sample_rate) + goto finish; + + gcd = av_gcd(prev, sr); + + if (prev / gcd >= INT_MAX / sr) { + av_log(ist, AV_LOG_WARNING, + "Audio timestamps cannot be represented exactly after " + "sample rate change: %d -> %d\n", prev, sr); + + // LCM of 192000, 44100, allows to represent all common samplerates + tb_new = (AVRational){ 1, 28224000 }; + } else + tb_new = (AVRational){ 1, prev / gcd * sr }; + + // keep the frame timebase if it is strictly better than + // the samplerate-defined one + if (frame->time_base.num == 1 && frame->time_base.den > tb_new.den && + !(frame->time_base.den % tb_new.den)) + tb_new = frame->time_base; + + if (ist->last_frame_pts != AV_NOPTS_VALUE) + ist->last_frame_pts = av_rescale_q(ist->last_frame_pts, + ist->last_frame_tb, tb_new); + ist->last_frame_duration_est = av_rescale_q(ist->last_frame_duration_est, + ist->last_frame_tb, tb_new); + + ist->last_frame_tb = tb_new; + ist->last_frame_sample_rate = frame->sample_rate; + +finish: + return ist->last_frame_tb; +} + +static void audio_ts_process(InputStream *ist, AVFrame *frame) +{ + AVRational tb_filter = (AVRational){1, frame->sample_rate}; + AVRational tb; + int64_t pts_pred; + + // on samplerate change, choose a new internal timebase for timestamp + // generation that can represent timestamps from all the samplerates + // seen so far + tb = audio_samplerate_update(ist, frame); + pts_pred = ist->last_frame_pts == AV_NOPTS_VALUE ? 0 : + ist->last_frame_pts + ist->last_frame_duration_est; + + if (frame->pts == AV_NOPTS_VALUE) { + frame->pts = pts_pred; + frame->time_base = tb; + } else if (ist->last_frame_pts != AV_NOPTS_VALUE && + frame->pts > av_rescale_q_rnd(pts_pred, tb, frame->time_base, + AV_ROUND_UP)) { + // there was a gap in timestamps, reset conversion state + ist->filter_in_rescale_delta_last = AV_NOPTS_VALUE; + } + + frame->pts = av_rescale_delta(frame->time_base, frame->pts, + tb, frame->nb_samples, + &ist->filter_in_rescale_delta_last, tb); + + ist->last_frame_pts = frame->pts; + ist->last_frame_duration_est = av_rescale_q(frame->nb_samples, + tb_filter, tb); + + // finally convert to filtering timebase + frame->pts = av_rescale_q(frame->pts, tb, tb_filter); + frame->duration = frame->nb_samples; + frame->time_base = tb_filter; +} + +static int decode_audio(InputStream *ist, const AVPacket *pkt, int *got_output, + int *decode_failed) +{ + AVFrame *decoded_frame = ist->decoded_frame; + AVCodecContext *avctx = ist->dec_ctx; + int ret, err = 0; + + update_benchmark(NULL); + ret = decode(ist, avctx, decoded_frame, got_output, pkt); + update_benchmark("decode_audio %d.%d", ist->file_index, ist->st->index); + if (ret < 0) + *decode_failed = 1; + + if (ret != AVERROR_EOF) + check_decode_result(ist, got_output, ret); + + if (!*got_output || ret < 0) + return ret; + + ist->samples_decoded += decoded_frame->nb_samples; + ist->frames_decoded++; + + audio_ts_process(ist, decoded_frame); + + ist->nb_samples = decoded_frame->nb_samples; + err = send_frame_to_filters(ist, decoded_frame); + + av_frame_unref(decoded_frame); + return err < 0 ? err : ret; +} + +static int64_t video_duration_estimate(const InputStream *ist, const AVFrame *frame) +{ + const InputFile *ifile = input_files[ist->file_index]; + int64_t codec_duration = 0; + + // XXX lavf currently makes up frame durations when they are not provided by + // the container. As there is no way to reliably distinguish real container + // durations from the fake made-up ones, we use heuristics based on whether + // the container has timestamps. Eventually lavf should stop making up + // durations, then this should be simplified. + + // prefer frame duration for containers with timestamps + if (frame->duration > 0 && (!ifile->format_nots || ist->framerate.num)) + return frame->duration; + + if (ist->dec_ctx->framerate.den && ist->dec_ctx->framerate.num) { + int fields = frame->repeat_pict + 2; + AVRational field_rate = av_mul_q(ist->dec_ctx->framerate, + (AVRational){ 2, 1 }); + codec_duration = av_rescale_q(fields, av_inv_q(field_rate), + frame->time_base); + } + + // prefer codec-layer duration for containers without timestamps + if (codec_duration > 0 && ifile->format_nots) + return codec_duration; + + // when timestamps are available, repeat last frame's actual duration + // (i.e. pts difference between this and last frame) + if (frame->pts != AV_NOPTS_VALUE && ist->last_frame_pts != AV_NOPTS_VALUE && + frame->pts > ist->last_frame_pts) + return frame->pts - ist->last_frame_pts; + + // try frame/codec duration + if (frame->duration > 0) + return frame->duration; + if (codec_duration > 0) + return codec_duration; + + // try average framerate + if (ist->st->avg_frame_rate.num && ist->st->avg_frame_rate.den) { + int64_t d = av_rescale_q(1, av_inv_q(ist->st->avg_frame_rate), + frame->time_base); + if (d > 0) + return d; + } + + // last resort is last frame's estimated duration, and 1 + return FFMAX(ist->last_frame_duration_est, 1); +} + +static int decode_video(InputStream *ist, const AVPacket *pkt, int *got_output, + int eof, int *decode_failed) +{ + AVFrame *frame = ist->decoded_frame; + int ret = 0, err = 0; + + // With fate-indeo3-2, we're getting 0-sized packets before EOF for some + // reason. This seems like a semi-critical bug. Don't trigger EOF, and + // skip the packet. + if (!eof && pkt && pkt->size == 0) + return 0; + + update_benchmark(NULL); + ret = decode(ist, ist->dec_ctx, frame, got_output, pkt); + update_benchmark("decode_video %d.%d", ist->file_index, ist->st->index); + if (ret < 0) + *decode_failed = 1; + + // The following line may be required in some cases where there is no parser + // or the parser does not has_b_frames correctly + if (ist->par->video_delay < ist->dec_ctx->has_b_frames) { + if (ist->dec_ctx->codec_id == AV_CODEC_ID_H264) { + ist->par->video_delay = ist->dec_ctx->has_b_frames; + } else + av_log(ist->dec_ctx, AV_LOG_WARNING, + "video_delay is larger in decoder than demuxer %d > %d.\n" + "If you want to help, upload a sample " + "of this file to https://streams.videolan.org/upload/ " + "and contact the ffmpeg-devel mailing list. (ffmpeg-devel@ffmpeg.org)\n", + ist->dec_ctx->has_b_frames, + ist->par->video_delay); + } + + if (ret != AVERROR_EOF) + check_decode_result(ist, got_output, ret); + + if (*got_output && ret >= 0) { + if (ist->dec_ctx->width != frame->width || + ist->dec_ctx->height != frame->height || + ist->dec_ctx->pix_fmt != frame->format) { + av_log(NULL, AV_LOG_DEBUG, "Frame parameters mismatch context %d,%d,%d != %d,%d,%d\n", + frame->width, + frame->height, + frame->format, + ist->dec_ctx->width, + ist->dec_ctx->height, + ist->dec_ctx->pix_fmt); + } + } + + if (!*got_output || ret < 0) + return ret; + + if(ist->top_field_first>=0) + frame->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST; + + ist->frames_decoded++; + + if (ist->hwaccel_retrieve_data && frame->format == ist->hwaccel_pix_fmt) { + err = ist->hwaccel_retrieve_data(ist->dec_ctx, frame); + if (err < 0) + goto fail; + } + + frame->pts = frame->best_effort_timestamp; + + // forced fixed framerate + if (ist->framerate.num) { + frame->pts = AV_NOPTS_VALUE; + frame->duration = 1; + frame->time_base = av_inv_q(ist->framerate); + } + + // no timestamp available - extrapolate from previous frame duration + if (frame->pts == AV_NOPTS_VALUE) + frame->pts = ist->last_frame_pts == AV_NOPTS_VALUE ? 0 : + ist->last_frame_pts + ist->last_frame_duration_est; + + // update timestamp history + ist->last_frame_duration_est = video_duration_estimate(ist, frame); + ist->last_frame_pts = frame->pts; + ist->last_frame_tb = frame->time_base; + + if (debug_ts) { + av_log(ist, AV_LOG_INFO, + "decoder -> pts:%s pts_time:%s " + "pkt_dts:%s pkt_dts_time:%s " + "duration:%s duration_time:%s " + "keyframe:%d frame_type:%d time_base:%d/%d\n", + av_ts2str(frame->pts), + av_ts2timestr(frame->pts, &frame->time_base), + av_ts2str(frame->pkt_dts), + av_ts2timestr(frame->pkt_dts, &frame->time_base), + av_ts2str(frame->duration), + av_ts2timestr(frame->duration, &frame->time_base), + !!(frame->flags & AV_FRAME_FLAG_KEY), frame->pict_type, + frame->time_base.num, frame->time_base.den); + } + + if (ist->st->sample_aspect_ratio.num) + frame->sample_aspect_ratio = ist->st->sample_aspect_ratio; + + err = send_frame_to_filters(ist, frame); + +fail: + av_frame_unref(frame); + return err < 0 ? err : ret; +} + +static void sub2video_flush(InputStream *ist) +{ + int i; + int ret; + + if (ist->sub2video.end_pts < INT64_MAX) + sub2video_update(ist, INT64_MAX, NULL); + for (i = 0; i < ist->nb_filters; i++) { + ret = av_buffersrc_add_frame(ist->filters[i]->filter, NULL); + if (ret != AVERROR_EOF && ret < 0) + av_log(NULL, AV_LOG_WARNING, "Flush the frame error.\n"); + } +} + +int process_subtitle(InputStream *ist, AVSubtitle *subtitle, int *got_output) +{ + int ret = 0; + int free_sub = 1; + + if (ist->fix_sub_duration) { + int end = 1; + if (ist->prev_sub.got_output) { + end = av_rescale(subtitle->pts - ist->prev_sub.subtitle.pts, + 1000, AV_TIME_BASE); + if (end < ist->prev_sub.subtitle.end_display_time) { + av_log(NULL, AV_LOG_DEBUG, + "Subtitle duration reduced from %"PRId32" to %d%s\n", + ist->prev_sub.subtitle.end_display_time, end, + end <= 0 ? ", dropping it" : ""); + ist->prev_sub.subtitle.end_display_time = end; + } + } + FFSWAP(int, *got_output, ist->prev_sub.got_output); + FFSWAP(int, ret, ist->prev_sub.ret); + FFSWAP(AVSubtitle, *subtitle, ist->prev_sub.subtitle); + if (end <= 0) + goto out; + } + + if (!*got_output) + return ret; + + if (ist->sub2video.frame) { + sub2video_update(ist, INT64_MIN, subtitle); + } else if (ist->nb_filters) { + if (!ist->sub2video.sub_queue) + ist->sub2video.sub_queue = av_fifo_alloc2(8, sizeof(AVSubtitle), AV_FIFO_FLAG_AUTO_GROW); + if (!ist->sub2video.sub_queue) + report_and_exit(AVERROR(ENOMEM)); + + ret = av_fifo_write(ist->sub2video.sub_queue, subtitle, 1); + if (ret < 0) + exit_program(1); + free_sub = 0; + } + + if (!subtitle->num_rects) + goto out; + + for (int oidx = 0; oidx < ist->nb_outputs; oidx++) { + OutputStream *ost = ist->outputs[oidx]; + if (!ost->enc || ost->type != AVMEDIA_TYPE_SUBTITLE) + continue; + + enc_subtitle(output_files[ost->file_index], ost, subtitle); + } + +out: + if (free_sub) + avsubtitle_free(subtitle); + return ret; +} + +static int transcode_subtitles(InputStream *ist, const AVPacket *pkt, + int *got_output, int *decode_failed) +{ + AVSubtitle subtitle; + int ret = avcodec_decode_subtitle2(ist->dec_ctx, + &subtitle, got_output, pkt); + + check_decode_result(ist, got_output, ret); + + if (ret < 0 || !*got_output) { + *decode_failed = 1; + if (!pkt->size) + sub2video_flush(ist); + return ret; + } + + ist->frames_decoded++; + + return process_subtitle(ist, &subtitle, got_output); +} + +static int send_filter_eof(InputStream *ist) +{ + int i, ret; + + for (i = 0; i < ist->nb_filters; i++) { + int64_t end_pts = ist->last_frame_pts == AV_NOPTS_VALUE ? AV_NOPTS_VALUE : + ist->last_frame_pts + ist->last_frame_duration_est; + ret = ifilter_send_eof(ist->filters[i], end_pts, ist->last_frame_tb); + if (ret < 0) + return ret; + } + return 0; +} + +int dec_packet(InputStream *ist, const AVPacket *pkt, int no_eof) +{ + AVPacket *avpkt = ist->pkt; + int ret, repeating = 0; + + if (pkt) { + av_packet_unref(avpkt); + ret = av_packet_ref(avpkt, pkt); + if (ret < 0) + return ret; + } + + // while we have more to decode or while the decoder did output something on EOF + while (1) { + int got_output = 0; + int decode_failed = 0; + + switch (ist->par->codec_type) { + case AVMEDIA_TYPE_AUDIO: + ret = decode_audio (ist, repeating ? NULL : avpkt, &got_output, + &decode_failed); + av_packet_unref(avpkt); + break; + case AVMEDIA_TYPE_VIDEO: + ret = decode_video (ist, repeating ? NULL : avpkt, &got_output, !pkt, + &decode_failed); + + av_packet_unref(avpkt); + break; + case AVMEDIA_TYPE_SUBTITLE: + if (repeating) + break; + ret = transcode_subtitles(ist, avpkt, &got_output, &decode_failed); + if (!pkt && ret >= 0) + ret = AVERROR_EOF; + av_packet_unref(avpkt); + break; + default: av_assert0(0); + } + + if (ret == AVERROR_EOF) { + /* after flushing, send an EOF on all the filter inputs attached to the stream */ + /* except when looping we need to flush but not to send an EOF */ + if (!no_eof) { + ret = send_filter_eof(ist); + if (ret < 0) { + av_log(NULL, AV_LOG_FATAL, "Error marking filters as finished\n"); + exit_program(1); + } + } + + return AVERROR_EOF; + } + + if (ret < 0) { + if (decode_failed) { + av_log(NULL, AV_LOG_ERROR, "Error while decoding stream #%d:%d: %s\n", + ist->file_index, ist->st->index, av_err2str(ret)); + } else { + av_log(NULL, AV_LOG_FATAL, "Error while processing the decoded " + "data for stream #%d:%d\n", ist->file_index, ist->st->index); + } + if (!decode_failed || exit_on_error) + exit_program(1); + return ret; + } + + if (!got_output) + return 0; + + repeating = 1; + } +} + static enum AVPixelFormat get_format(AVCodecContext *s, const enum AVPixelFormat *pix_fmts) { InputStream *ist = s->opaque; From patchwork Wed May 17 10:20:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41689 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1082917pzb; Wed, 17 May 2023 03:30:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7totnxPwWQ+9fThDGuo/0d0PdoxMoIZxG13cDJhJnga84Uqo6YXT53pq/7N0p+/pqUMq31 X-Received: by 2002:a17:906:eec5:b0:94b:cd7c:59f4 with SMTP id wu5-20020a170906eec500b0094bcd7c59f4mr32920853ejb.16.1684319426280; Wed, 17 May 2023 03:30:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684319426; cv=none; d=google.com; s=arc-20160816; b=mH8YcTiz3zniYicPIXnAqVpUZDbUTtWQwED+a/ZBJ7YXJ/Vek8qkRAPNPMjIwa/SZC 41cTtdLCsJNXYxUKpfkbd0AZWLp7JzRzsxdx4KgaDi/5uxxFfpB1IsfBeMuIfM8jf2Xg XXDEfNAM8NGQqC40EOg0xip4l00vZokdvBEr5oGTZtZ1w65Kw7pT1Fs/1eWCvZfPoZkf 11h4F9pk6yA9ws/RQAhhpRf20ek3iZ7wOBgc6uX1Lv+3iQVK50Yc/kUafv/kFHJQSjfm D1kC9ZuoqERekHegsdXGbSJf2K8FG3guIUhAQOjBdM6L/iIhJwlK5kVIUfwGFlzSzre1 1UAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=ob8Lz6HuQpv64i7AL+ITy3iX7s4ePt+W4nA5prXCK0M=; b=uW5EymEkx1pXavor5BVixEsu3C5aJxIXSbhfbpWM7zOcNgYpH7/lDQ7VAu7rt8F6JZ 4jMUdqyXsGYjklLBCX/BqByOb4hunDteQXZ8G/8SMzHxyRiR8wQ9dGx8hhc/pZWIwpuK dqSAVRsYuLB1Lv9Jv23zbNWW9U9LXMRByvDeklAp5/UR6w//4nRaIHjOtnKU2WD45zOt /jNsBXQiWljT+UuFJAE7fZQnmVY42C/mY0gzXNkvqtKc9t3pmzqG4hm0PgSDsSDb+Joo DYDJVQ3JHtSjY5xayWQvit5KhKATGAxqMACXVx5WEixr76y+Gzfogc/m2BmXVtRgH/DR JMPw== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id un3-20020a170907cb8300b0094f69923e90si18635173ejc.1.2023.05.17.03.30.25; Wed, 17 May 2023 03:30:26 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3686E68C164; Wed, 17 May 2023 13:30:07 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1822C68BD58 for ; Wed, 17 May 2023 13:30:00 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 9EB282404EE for ; Wed, 17 May 2023 12:29:59 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id fiey4h7fEf5C for ; Wed, 17 May 2023 12:29:59 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id E98C22404F5 for ; Wed, 17 May 2023 12:29:57 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id BFE573A2226 for ; Wed, 17 May 2023 12:20:40 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 May 2023 12:20:23 +0200 Message-Id: <20230517102029.541-30-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517102029.541-1-anton@khirnov.net> References: <20230517102029.541-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 30/36] fftools/ffmpeg_dec: deobfuscate subtitle decoding 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: EFeEkg4sg6Z8 It is currently handled in the same loop as audio and video, but this obscures the actual flow, because only one iteration is ever performed for subtitles. Also, avoid a pointless packet reference. --- fftools/ffmpeg_dec.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c index 30fe75d8a6..646b587f9e 100644 --- a/fftools/ffmpeg_dec.c +++ b/fftools/ffmpeg_dec.c @@ -456,25 +456,31 @@ out: return ret; } -static int transcode_subtitles(InputStream *ist, const AVPacket *pkt, - int *got_output, int *decode_failed) +static int transcode_subtitles(InputStream *ist, const AVPacket *pkt) { AVSubtitle subtitle; + int got_output; int ret = avcodec_decode_subtitle2(ist->dec_ctx, - &subtitle, got_output, pkt); + &subtitle, &got_output, pkt); - check_decode_result(ist, got_output, ret); + if (ret < 0) { + av_log(ist, AV_LOG_ERROR, "Error decoding subtitles: %s\n", + av_err2str(ret)); + if (exit_on_error) + exit_program(1); + } - if (ret < 0 || !*got_output) { - *decode_failed = 1; + check_decode_result(ist, &got_output, ret); + + if (ret < 0 || !got_output) { if (!pkt->size) sub2video_flush(ist); - return ret; + return ret < 0 ? ret : AVERROR_EOF; } ist->frames_decoded++; - return process_subtitle(ist, &subtitle, got_output); + return process_subtitle(ist, &subtitle, &got_output); } static int send_filter_eof(InputStream *ist) @@ -493,9 +499,13 @@ static int send_filter_eof(InputStream *ist) int dec_packet(InputStream *ist, const AVPacket *pkt, int no_eof) { + AVCodecContext *dec = ist->dec_ctx; AVPacket *avpkt = ist->pkt; int ret, repeating = 0; + if (dec->codec_type == AVMEDIA_TYPE_SUBTITLE) + return transcode_subtitles(ist, pkt ? pkt : ist->pkt); + if (pkt) { av_packet_unref(avpkt); ret = av_packet_ref(avpkt, pkt); @@ -520,14 +530,6 @@ int dec_packet(InputStream *ist, const AVPacket *pkt, int no_eof) av_packet_unref(avpkt); break; - case AVMEDIA_TYPE_SUBTITLE: - if (repeating) - break; - ret = transcode_subtitles(ist, avpkt, &got_output, &decode_failed); - if (!pkt && ret >= 0) - ret = AVERROR_EOF; - av_packet_unref(avpkt); - break; default: av_assert0(0); } From patchwork Wed May 17 10:20:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41672 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1078972pzb; Wed, 17 May 2023 03:23:16 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ53+TUTh1OpyK51L4/ta1mq9sTAhLofoWNuW2H9W+Sni9htnbrAtxaSTXKJt79yDM24ITP0 X-Received: by 2002:a17:907:7d9e:b0:969:f54c:dee2 with SMTP id oz30-20020a1709077d9e00b00969f54cdee2mr27159843ejc.26.1684318996501; Wed, 17 May 2023 03:23:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684318996; cv=none; d=google.com; s=arc-20160816; b=TQvlWT3Hei8XqxM0cVZKdBKZ81+lD7yVF0djJ4vjKJ5RI9kCf8xTRB14EytKhF1HVi 4VGzniww4NlUuuCg8OsOIYIq4cVOxjn7ZJcRSjw9EfulHb3jXTds2EL35kFd9oKXEIsq btVEX1X8mFYFfiEyY2pPX29X/FpCagDLlSY7qb7S00hb0+QmKoO5G2iO9/YSqbOzKq+P x59oKkpRUiQV4aSAqfTuI0o7wG1mCi9Z9v+sIt6e9nd0dbzoT3S5NcEbbA17Ptt86MME Ah4cZUxojrXvMgJon7/vdXSj1M4TjHJttFYAkydWSZs77cymTNWs3lD0EHZudQhPca3O /czg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=kZzWF9uPZTRpKf/zo/UTg8xZJGn35+/PQWtJ27hBScM=; b=w1B+0yj8AgWnc7VQtcp0l84WX+A+ML6LE4Mn0n3ylC79w1zoUWgvFqEZA3NH5f51YL G1jxWg77CVMjbY6hhUZnfexO1KYhsfH6mm2VTfd6sp0klGf4nBLK8/DjLU6IXv1kg/aG f65q2vLSijKLyKYIxp/HntHuUaFSK3WDWTmHrseEnmN5mV8UAEFMHRQwhVtAjPLqSH5X IMJzZIPwwPnl94h38bmzwrxnF5x9ETWjRgWt6Sv4yX+c0WPx5zbTJhNk42tvgls32aRK cZPPzI67ucbITJdI+/MByt5X8xJrCoAOewOpMYjO/OLh22pE5VpMlr2t0P+ryy4NGUPf yIDQ== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id gy16-20020a170906f25000b009598cbe557csi14466616ejb.69.2023.05.17.03.23.16; Wed, 17 May 2023 03:23:16 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F418868C1A3; Wed, 17 May 2023 13:21:08 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A776C68C141 for ; Wed, 17 May 2023 13:20:57 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 1DD3F2406D0 for ; Wed, 17 May 2023 12:20:55 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id v_6SEbvPRBf7 for ; Wed, 17 May 2023 12:20:54 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 3A28D240D1B for ; Wed, 17 May 2023 12:20:46 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id CB8D53A222D for ; Wed, 17 May 2023 12:20:40 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 May 2023 12:20:24 +0200 Message-Id: <20230517102029.541-31-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517102029.541-1-anton@khirnov.net> References: <20230517102029.541-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 31/36] fftools/ffmpeg_dec: restructure audio/video decoding loop 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: sJHj8L1lg+8b It currently emulates the long-removed avcodec_decode_audio4/avcodec_decode_video2 APIs, which obfuscates the actual decoding flow. Restructure the decoding calls so that they naturally follow the new avcodec_send_packet()/avcodec_receive_frame() design. This is not only significantly easier to read, but also shorter. --- fftools/ffmpeg_dec.c | 187 ++++++++++++++----------------------------- 1 file changed, 61 insertions(+), 126 deletions(-) diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c index 646b587f9e..73f826c76a 100644 --- a/fftools/ffmpeg_dec.c +++ b/fftools/ffmpeg_dec.c @@ -31,7 +31,7 @@ #include "ffmpeg.h" -static void check_decode_result(InputStream *ist, int *got_output, int ret) +static void check_decode_result(InputStream *ist, int got_output, int ret) { if (ret < 0) ist->decode_errors++; @@ -39,7 +39,7 @@ static void check_decode_result(InputStream *ist, int *got_output, int ret) if (ret < 0 && exit_on_error) exit_program(1); - if (*got_output && ist->dec_ctx->codec_type != AVMEDIA_TYPE_SUBTITLE) { + if (got_output && ist->dec_ctx->codec_type != AVMEDIA_TYPE_SUBTITLE) { if (ist->decoded_frame->decode_error_flags || (ist->decoded_frame->flags & AV_FRAME_FLAG_CORRUPT)) { av_log(ist, exit_on_error ? AV_LOG_FATAL : AV_LOG_WARNING, "corrupt decoded frame\n"); @@ -49,52 +49,6 @@ static void check_decode_result(InputStream *ist, int *got_output, int ret) } } -// This does not quite work like avcodec_decode_audio4/avcodec_decode_video2. -// There is the following difference: if you got a frame, you must call -// it again with pkt=NULL. pkt==NULL is treated differently from pkt->size==0 -// (pkt==NULL means get more output, pkt->size==0 is a flush/drain packet) -static int decode(InputStream *ist, AVCodecContext *avctx, - AVFrame *frame, int *got_frame, const AVPacket *pkt) -{ - int ret; - - *got_frame = 0; - - if (pkt) { - ret = avcodec_send_packet(avctx, pkt); - // In particular, we don't expect AVERROR(EAGAIN), because we read all - // decoded frames with avcodec_receive_frame() until done. - if (ret < 0 && ret != AVERROR_EOF) - return ret; - } - - ret = avcodec_receive_frame(avctx, frame); - if (ret < 0 && ret != AVERROR(EAGAIN)) - return ret; - if (ret >= 0) { - if (ist->want_frame_data) { - FrameData *fd; - - av_assert0(!frame->opaque_ref); - frame->opaque_ref = av_buffer_allocz(sizeof(*fd)); - if (!frame->opaque_ref) { - av_frame_unref(frame); - return AVERROR(ENOMEM); - } - fd = (FrameData*)frame->opaque_ref->data; - fd->pts = frame->pts; - fd->tb = avctx->pkt_timebase; - fd->idx = avctx->frame_num - 1; - } - - frame->time_base = avctx->pkt_timebase; - - *got_frame = 1; - } - - return 0; -} - static int send_frame_to_filters(InputStream *ist, AVFrame *decoded_frame) { int i, ret; @@ -192,25 +146,10 @@ static void audio_ts_process(InputStream *ist, AVFrame *frame) frame->time_base = tb_filter; } -static int decode_audio(InputStream *ist, const AVPacket *pkt, int *got_output, - int *decode_failed) +static int decode_audio(InputStream *ist, AVFrame *decoded_frame) { - AVFrame *decoded_frame = ist->decoded_frame; - AVCodecContext *avctx = ist->dec_ctx; int ret, err = 0; - update_benchmark(NULL); - ret = decode(ist, avctx, decoded_frame, got_output, pkt); - update_benchmark("decode_audio %d.%d", ist->file_index, ist->st->index); - if (ret < 0) - *decode_failed = 1; - - if (ret != AVERROR_EOF) - check_decode_result(ist, got_output, ret); - - if (!*got_output || ret < 0) - return ret; - ist->samples_decoded += decoded_frame->nb_samples; ist->frames_decoded++; @@ -274,24 +213,10 @@ static int64_t video_duration_estimate(const InputStream *ist, const AVFrame *fr return FFMAX(ist->last_frame_duration_est, 1); } -static int decode_video(InputStream *ist, const AVPacket *pkt, int *got_output, - int eof, int *decode_failed) +static int decode_video(InputStream *ist, AVFrame *frame) { - AVFrame *frame = ist->decoded_frame; int ret = 0, err = 0; - // With fate-indeo3-2, we're getting 0-sized packets before EOF for some - // reason. This seems like a semi-critical bug. Don't trigger EOF, and - // skip the packet. - if (!eof && pkt && pkt->size == 0) - return 0; - - update_benchmark(NULL); - ret = decode(ist, ist->dec_ctx, frame, got_output, pkt); - update_benchmark("decode_video %d.%d", ist->file_index, ist->st->index); - if (ret < 0) - *decode_failed = 1; - // The following line may be required in some cases where there is no parser // or the parser does not has_b_frames correctly if (ist->par->video_delay < ist->dec_ctx->has_b_frames) { @@ -307,10 +232,6 @@ static int decode_video(InputStream *ist, const AVPacket *pkt, int *got_output, ist->par->video_delay); } - if (ret != AVERROR_EOF) - check_decode_result(ist, got_output, ret); - - if (*got_output && ret >= 0) { if (ist->dec_ctx->width != frame->width || ist->dec_ctx->height != frame->height || ist->dec_ctx->pix_fmt != frame->format) { @@ -322,10 +243,6 @@ static int decode_video(InputStream *ist, const AVPacket *pkt, int *got_output, ist->dec_ctx->height, ist->dec_ctx->pix_fmt); } - } - - if (!*got_output || ret < 0) - return ret; if(ist->top_field_first>=0) frame->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST; @@ -470,7 +387,7 @@ static int transcode_subtitles(InputStream *ist, const AVPacket *pkt) exit_program(1); } - check_decode_result(ist, &got_output, ret); + check_decode_result(ist, got_output, ret); if (ret < 0 || !got_output) { if (!pkt->size) @@ -500,40 +417,44 @@ static int send_filter_eof(InputStream *ist) int dec_packet(InputStream *ist, const AVPacket *pkt, int no_eof) { AVCodecContext *dec = ist->dec_ctx; - AVPacket *avpkt = ist->pkt; - int ret, repeating = 0; + const char *type_desc = av_get_media_type_string(dec->codec_type); + int ret; if (dec->codec_type == AVMEDIA_TYPE_SUBTITLE) return transcode_subtitles(ist, pkt ? pkt : ist->pkt); - if (pkt) { - av_packet_unref(avpkt); - ret = av_packet_ref(avpkt, pkt); - if (ret < 0) - return ret; + // With fate-indeo3-2, we're getting 0-sized packets before EOF for some + // reason. This seems like a semi-critical bug. Don't trigger EOF, and + // skip the packet. + if (pkt && pkt->size == 0) + return 0; + + ret = avcodec_send_packet(dec, pkt); + if (ret < 0 && !(ret == AVERROR_EOF && !pkt)) { + // In particular, we don't expect AVERROR(EAGAIN), because we read all + // decoded frames with avcodec_receive_frame() until done. + av_log(ist, AV_LOG_ERROR, "Error submitting %s to decoder: %s\n", + pkt ? "packet" : "EOF", av_err2str(ret)); + if (exit_on_error) + exit_program(1); + return ret; } - // while we have more to decode or while the decoder did output something on EOF while (1) { - int got_output = 0; - int decode_failed = 0; - - switch (ist->par->codec_type) { - case AVMEDIA_TYPE_AUDIO: - ret = decode_audio (ist, repeating ? NULL : avpkt, &got_output, - &decode_failed); - av_packet_unref(avpkt); - break; - case AVMEDIA_TYPE_VIDEO: - ret = decode_video (ist, repeating ? NULL : avpkt, &got_output, !pkt, - &decode_failed); + AVFrame *frame = ist->decoded_frame; - av_packet_unref(avpkt); - break; - default: av_assert0(0); - } + update_benchmark(NULL); + ret = avcodec_receive_frame(dec, frame); + update_benchmark("decode_%s %d.%d", type_desc, + ist->file_index, ist->st->index); - if (ret == AVERROR_EOF) { + if (ret != AVERROR_EOF && ret != AVERROR(EAGAIN)) + check_decode_result(ist, ret >= 0, ret); + + if (ret == AVERROR(EAGAIN)) { + av_assert0(pkt); // should never happen during flushing + return 0; + } else if (ret == AVERROR_EOF) { /* after flushing, send an EOF on all the filter inputs attached to the stream */ /* except when looping we need to flush but not to send an EOF */ if (!no_eof) { @@ -545,25 +466,39 @@ int dec_packet(InputStream *ist, const AVPacket *pkt, int no_eof) } return AVERROR_EOF; + } else if (ret < 0) { + av_log(ist, AV_LOG_ERROR, "Decoding error: %s\n", av_err2str(ret)); + if (exit_on_error) + exit_program(1); + return ret; } - if (ret < 0) { - if (decode_failed) { - av_log(NULL, AV_LOG_ERROR, "Error while decoding stream #%d:%d: %s\n", - ist->file_index, ist->st->index, av_err2str(ret)); - } else { - av_log(NULL, AV_LOG_FATAL, "Error while processing the decoded " - "data for stream #%d:%d\n", ist->file_index, ist->st->index); + if (ist->want_frame_data) { + FrameData *fd; + + av_assert0(!frame->opaque_ref); + frame->opaque_ref = av_buffer_allocz(sizeof(*fd)); + if (!frame->opaque_ref) { + av_frame_unref(frame); + report_and_exit(AVERROR(ENOMEM)); } - if (!decode_failed || exit_on_error) - exit_program(1); - return ret; + fd = (FrameData*)frame->opaque_ref->data; + fd->pts = frame->pts; + fd->tb = dec->pkt_timebase; + fd->idx = dec->frame_num - 1; } - if (!got_output) - return 0; + frame->time_base = dec->pkt_timebase; + + ret = dec->codec_type == AVMEDIA_TYPE_AUDIO ? + decode_audio(ist, frame) : + decode_video(ist, frame); - repeating = 1; + if (ret < 0) { + av_log(NULL, AV_LOG_FATAL, "Error while processing the decoded " + "data for stream #%d:%d\n", ist->file_index, ist->st->index); + exit_program(1); + } } } From patchwork Wed May 17 10:20:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41687 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1082650pzb; Wed, 17 May 2023 03:30:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5xpfxG03SkYgjk1XDfGl81h9f7YTqkZ0dzJLJiztmOlvwPd3/oCF0T4RMCP76Q2hMkuPNl X-Received: by 2002:a17:907:26c8:b0:965:9f86:4fe4 with SMTP id bp8-20020a17090726c800b009659f864fe4mr33716123ejc.56.1684319408770; Wed, 17 May 2023 03:30:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684319408; cv=none; d=google.com; s=arc-20160816; b=aQNRoQ/s0tDyZY9KThB2eRsCtGZgTIQdiTAyDO9jFyRWfYnNJnYVHNs9Y/UKaiOadh +GEcZK0G8TOglIK7MKjeb9Q+0OKAuHeaecfzA+DUMqCwVK7L66NCjFtHymLldoYBuz9V jv8+U9GBzqfoxgUo9okagyxtGOxZ1+QRv8m8re0N+smeg5g+oDlyUUPgYh3VlWZL72h0 zk1lMAXj0C7Te0+ixojdIi4MNEeKcsNS68i00+rxnM9xbo289nGc5jAnL1YiMmpNtYXZ Gfbc2+37RvGwzwcjH6u7wbKTsUkCNZBmzgTwQYdssI2dIl3ApQvJmI3ONcG5G+4NhqdD EEZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=yAk3NP6zN/ZGcK3TU8HWvVAnovE0QTOveeU72Bc4O2k=; b=fLA4U4ebK+1fk30e1T7tWmt5PZYAkiatC4MSwXSbzXvuwyyfh2wlZNG3NuyIIbB37L d3oGeZ5eX6tMUXRpeNNW0U/AEt6T259+zjS4o6IPhNxdvDDBJ2N5WjA6HO/LbozVRPde Ql2m4l5sWt/9efysXqIobvTuV80arBJWr9oay38PTGP75+4CtgPw7HrBgZUZgs/Pk5vv mJE7tuhd1sP32AuJ7MYGSmrLRKLT+jOHxQzxiY9yy65wWxobnViSrl+iWE2dMz5uATuV bxrCeSk1o1cZi877VRTw1EaTJEX+xpPTyJU/I5x3C+ssdsRwn7y9Bs6cg9EoldanbR3r i4Lg== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id lw28-20020a170906bcdc00b0094f4ba4bcf6si14439647ejb.582.2023.05.17.03.30.08; Wed, 17 May 2023 03:30:08 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 08B2A68B157; Wed, 17 May 2023 13:30:05 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A415868BD58 for ; Wed, 17 May 2023 13:29:58 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 6680D2404F8 for ; Wed, 17 May 2023 12:29:58 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id u6WFsNeGdAMt for ; Wed, 17 May 2023 12:29:57 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id DBB3B240177 for ; Wed, 17 May 2023 12:29:57 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id D6DDD3A222F for ; Wed, 17 May 2023 12:20:40 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 May 2023 12:20:25 +0200 Message-Id: <20230517102029.541-32-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517102029.541-1-anton@khirnov.net> References: <20230517102029.541-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 32/36] fftools/ffmpeg: reindent after previous commit 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 2QwOGxKmjcIX --- fftools/ffmpeg_dec.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c index 73f826c76a..58bb7a7344 100644 --- a/fftools/ffmpeg_dec.c +++ b/fftools/ffmpeg_dec.c @@ -232,17 +232,17 @@ static int decode_video(InputStream *ist, AVFrame *frame) ist->par->video_delay); } - if (ist->dec_ctx->width != frame->width || - ist->dec_ctx->height != frame->height || - ist->dec_ctx->pix_fmt != frame->format) { - av_log(NULL, AV_LOG_DEBUG, "Frame parameters mismatch context %d,%d,%d != %d,%d,%d\n", - frame->width, - frame->height, - frame->format, - ist->dec_ctx->width, - ist->dec_ctx->height, - ist->dec_ctx->pix_fmt); - } + if (ist->dec_ctx->width != frame->width || + ist->dec_ctx->height != frame->height || + ist->dec_ctx->pix_fmt != frame->format) { + av_log(NULL, AV_LOG_DEBUG, "Frame parameters mismatch context %d,%d,%d != %d,%d,%d\n", + frame->width, + frame->height, + frame->format, + ist->dec_ctx->width, + ist->dec_ctx->height, + ist->dec_ctx->pix_fmt); + } if(ist->top_field_first>=0) frame->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST; From patchwork Wed May 17 10:20:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41690 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1083002pzb; Wed, 17 May 2023 03:30:34 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6XS6GYt3crcR1JJ9mXgu1y+oH1g1JfyY9VaCyQjO7sNsw1SwLd80inNcdhJt5cv+xd9qYn X-Received: by 2002:a17:906:6a16:b0:966:eb8:2f12 with SMTP id qw22-20020a1709066a1600b009660eb82f12mr38425074ejc.11.1684319434233; Wed, 17 May 2023 03:30:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684319434; cv=none; d=google.com; s=arc-20160816; b=qW/2DvEgdeUUxw8CaOxaw6J68toJNpLpezstAYNdcx7/s2SBn5Uf8AAmhDhEIT9idx 3HSqxctEXKag/3vMeNalzEuLiWmPHVwRvCvngQi7BTke+sXs9E53COx0m0M28xYmuwDw W1J01/SP+q1hZmhM3fyQIK5yOmn/1PewJTTjRYxEW+gXCJNr6R4sgz+BZdsT3IkwG7lz dQ78MY/SFJnmcD1e2+vkSRsBtM9QJBGoemgkGQ728DwevFbeZpGbUd39qyM7DoOy2aoF kV3ypbkHwm9aUa0tl4rv9SiPl1MNPYurUIr4Dx5d+8g2pJhRvIvWM6uqEwQn7oLywYRW zmmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=C1JWvo9VWaq48J3hcNApaPGBPSlvZjUgyvwkw2JFFeU=; b=vawXgsrI1elWgjQcGTzzjDpP9s5gkEPVFBj/K6Mn83KOINkiw6QVleAxYaT8UeBEKm D2/CS4u4iIKIUzluGt+5F7tbkjEOBjaYHH6memheyKtGw+mt7SWOhbFTjejJl+fIQ2xl LualPiSfJUQAMA3Eijfjxi07thfnHnzf/1Ltd1QmHCGuyPIExpTKP5W6o2KflyZgmvAt dAfbSY/Dk7Cib9heHyFQRDRc5NB4zMLwY66CDdz6oFW3SyrazIbRbKu4tCUTJP2RBWJ5 lqKd79RIAv/6y235x/O2Q7IiDoyQTSgA7BUm+NdVi8CEtG0GaBNUc56fsjhjPUYMXAJ9 8c7Q== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id w26-20020a170906481a00b0096aa5385806si9828033ejq.794.2023.05.17.03.30.33; Wed, 17 May 2023 03:30:34 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4459E68C16E; Wed, 17 May 2023 13:30:08 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3835968BFFD for ; Wed, 17 May 2023 13:30:00 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id D3F812404F5 for ; Wed, 17 May 2023 12:29:59 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id LL0Vvai5hjoT for ; Wed, 17 May 2023 12:29:57 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id E3F392404EC for ; Wed, 17 May 2023 12:29:57 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id E1D523A2243 for ; Wed, 17 May 2023 12:20:40 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 May 2023 12:20:26 +0200 Message-Id: <20230517102029.541-33-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517102029.541-1-anton@khirnov.net> References: <20230517102029.541-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 33/36] fftools/ffmpeg_dec: merge check_decode_result() into its callers 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: TFUJMeMQRIQY Not only is this easier to read, this also makes the code shorter. --- fftools/ffmpeg_dec.c | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c index 58bb7a7344..79e9c04fc1 100644 --- a/fftools/ffmpeg_dec.c +++ b/fftools/ffmpeg_dec.c @@ -31,24 +31,6 @@ #include "ffmpeg.h" -static void check_decode_result(InputStream *ist, int got_output, int ret) -{ - if (ret < 0) - ist->decode_errors++; - - if (ret < 0 && exit_on_error) - exit_program(1); - - if (got_output && ist->dec_ctx->codec_type != AVMEDIA_TYPE_SUBTITLE) { - if (ist->decoded_frame->decode_error_flags || (ist->decoded_frame->flags & AV_FRAME_FLAG_CORRUPT)) { - av_log(ist, exit_on_error ? AV_LOG_FATAL : AV_LOG_WARNING, - "corrupt decoded frame\n"); - if (exit_on_error) - exit_program(1); - } - } -} - static int send_frame_to_filters(InputStream *ist, AVFrame *decoded_frame) { int i, ret; @@ -385,10 +367,9 @@ static int transcode_subtitles(InputStream *ist, const AVPacket *pkt) av_err2str(ret)); if (exit_on_error) exit_program(1); + ist->decode_errors++; } - check_decode_result(ist, got_output, ret); - if (ret < 0 || !got_output) { if (!pkt->size) sub2video_flush(ist); @@ -448,9 +429,6 @@ int dec_packet(InputStream *ist, const AVPacket *pkt, int no_eof) update_benchmark("decode_%s %d.%d", type_desc, ist->file_index, ist->st->index); - if (ret != AVERROR_EOF && ret != AVERROR(EAGAIN)) - check_decode_result(ist, ret >= 0, ret); - if (ret == AVERROR(EAGAIN)) { av_assert0(pkt); // should never happen during flushing return 0; @@ -470,9 +448,17 @@ int dec_packet(InputStream *ist, const AVPacket *pkt, int no_eof) av_log(ist, AV_LOG_ERROR, "Decoding error: %s\n", av_err2str(ret)); if (exit_on_error) exit_program(1); + ist->decode_errors++; return ret; } + if (frame->decode_error_flags || (frame->flags & AV_FRAME_FLAG_CORRUPT)) { + av_log(ist, exit_on_error ? AV_LOG_FATAL : AV_LOG_WARNING, + "corrupt decoded frame\n"); + if (exit_on_error) + exit_program(1); + } + if (ist->want_frame_data) { FrameData *fd; From patchwork Wed May 17 10:20:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41688 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1082848pzb; Wed, 17 May 2023 03:30:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ45EaDY7Ql+m+RXRvnYr7AYE/E4mXWkEjRzdeJXpocTJwG1MvUMWvBa8d8IG+fFqpWb5sTj X-Received: by 2002:a17:907:3faa:b0:966:17b2:5b15 with SMTP id hr42-20020a1709073faa00b0096617b25b15mr39235439ejc.7.1684319417960; Wed, 17 May 2023 03:30:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684319417; cv=none; d=google.com; s=arc-20160816; b=nAJwcLPEYnrzrHiI6cAJE/jBOgLR1zO11+HhdqiiWgO7P1b39DqPk+yIwACG2EM5jN oeA0MoWdBpoLay0uiW5SoSiprtbAlRkeXPrSIxAA7mK2HV8wcDw9VdxWYorJqG1z9EOU EVgOvjLSDJKv6KEIAfukOtWqNDOsw0UdwTmaIAj9i9HjsbghQUMWe9k0M2MQnJQkxZZV SbIWVSlz9A88I0lrcofJQbBVqf1oGcPgmWucYRGMy/QEun0CjaJPi4xtfSKSK3wjqY1l 6U7OppJkBAGESm6HtPSpPJL3hRWP+uWp3pRvNAQE2JnKI2TACaVfSE1cDdiCZvKOUqZo lbCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=K3IQfM2EQUka7dEJPBe8/BIZZousAkS4AI1UIleG1iI=; b=L0OoIA7QG/3/svqbXMwAAp7Ud1yaRPS7DGszO+eq15HPCZY+E+0bJc0rNvR1iC0L7M 4cEb2b2Q+6yLrc5Rdy49k2xsv3gloumOKdooObQWOgQ6ZBy9qJrYLjY8qnhbmELDh7TH LYFSN7povSWSfF5apSSAkhmCRjZAm3/ePbBhgbn8kiAkqSGgPhaIeJ1JuV/KE6EJchKw FCD4Li9rg/6PwFfslMNgzWyi6tfiWiZu3GjDyz4sZrcO4DoFyp+UaDleeOtTJIbgBULi wKLBIZ1QxLa6ABJ6PUEy8jXbcPrE79QT2S77V++2dD/tT4zo2FhleM8ogn+IuFmgn/pr vUZA== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id kw24-20020a170907771800b0096ee562f0d5si1958805ejc.559.2023.05.17.03.30.16; Wed, 17 May 2023 03:30: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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2A43C68C142; Wed, 17 May 2023 13:30:06 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 425B068BE3E for ; Wed, 17 May 2023 13:29:59 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 0B9BF240177 for ; Wed, 17 May 2023 12:29:59 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 1zla6LF-wfXZ for ; Wed, 17 May 2023 12:29:58 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id E812A2404EE for ; Wed, 17 May 2023 12:29:57 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id ED8C43A2278 for ; Wed, 17 May 2023 12:20:40 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 May 2023 12:20:27 +0200 Message-Id: <20230517102029.541-34-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517102029.541-1-anton@khirnov.net> References: <20230517102029.541-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 34/36] fftools/ffmpeg_dec: deduplicate code in decode_audio/video() 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: HAfJq0em/oeX --- fftools/ffmpeg_dec.c | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c index 79e9c04fc1..4662d0a265 100644 --- a/fftools/ffmpeg_dec.c +++ b/fftools/ffmpeg_dec.c @@ -130,18 +130,13 @@ static void audio_ts_process(InputStream *ist, AVFrame *frame) static int decode_audio(InputStream *ist, AVFrame *decoded_frame) { - int ret, err = 0; - ist->samples_decoded += decoded_frame->nb_samples; - ist->frames_decoded++; audio_ts_process(ist, decoded_frame); ist->nb_samples = decoded_frame->nb_samples; - err = send_frame_to_filters(ist, decoded_frame); - av_frame_unref(decoded_frame); - return err < 0 ? err : ret; + return 0; } static int64_t video_duration_estimate(const InputStream *ist, const AVFrame *frame) @@ -197,8 +192,6 @@ static int64_t video_duration_estimate(const InputStream *ist, const AVFrame *fr static int decode_video(InputStream *ist, AVFrame *frame) { - int ret = 0, err = 0; - // The following line may be required in some cases where there is no parser // or the parser does not has_b_frames correctly if (ist->par->video_delay < ist->dec_ctx->has_b_frames) { @@ -229,12 +222,10 @@ static int decode_video(InputStream *ist, AVFrame *frame) if(ist->top_field_first>=0) frame->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST; - ist->frames_decoded++; - if (ist->hwaccel_retrieve_data && frame->format == ist->hwaccel_pix_fmt) { - err = ist->hwaccel_retrieve_data(ist->dec_ctx, frame); + int err = ist->hwaccel_retrieve_data(ist->dec_ctx, frame); if (err < 0) - goto fail; + return err; } frame->pts = frame->best_effort_timestamp; @@ -275,11 +266,7 @@ static int decode_video(InputStream *ist, AVFrame *frame) if (ist->st->sample_aspect_ratio.num) frame->sample_aspect_ratio = ist->st->sample_aspect_ratio; - err = send_frame_to_filters(ist, frame); - -fail: - av_frame_unref(frame); - return err < 0 ? err : ret; + return 0; } static void sub2video_flush(InputStream *ist) @@ -485,6 +472,13 @@ int dec_packet(InputStream *ist, const AVPacket *pkt, int no_eof) "data for stream #%d:%d\n", ist->file_index, ist->st->index); exit_program(1); } + + ist->frames_decoded++; + + ret = send_frame_to_filters(ist, frame); + av_frame_unref(frame); + if (ret < 0) + exit_program(1); } } From patchwork Wed May 17 10:20:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41673 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1079053pzb; Wed, 17 May 2023 03:23:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6wYWIldzSqGBxq0VEEtedpIRuUejsYwHTT1ADkk6tUJ0efW4w1pTo0qcyi72gP5PxpAjyg X-Received: by 2002:a17:907:940c:b0:960:ddba:e5bb with SMTP id dk12-20020a170907940c00b00960ddbae5bbmr38402642ejc.43.1684319004950; Wed, 17 May 2023 03:23:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684319004; cv=none; d=google.com; s=arc-20160816; b=elkbJ88yNl0LqJIkBdhvNchpOH/nAB33hwefLAHGLLfTmgwPkns8xY4ow+c6DWU8i1 gRUBifmjJxf+/0JveATWz6RNaw5K0OoI/RCMYaO1VGVfmcRyI4Yu4xPUaEAzecapdpJP M/TQiTMzyDu87NMrD1QJlcpVzzAIhMNowd45Yrl6BJ6LfosSeoVebyyi76XlBAFD6plM w6EA1zz30Ar6yvETa5EY6FC2gVetzROnN2EArst77xz5OSFRAvBM6wLZCf7t1/+RlDq3 6HETYzy/KjB1MWEXmexxchKKPzPVXNibnQmlTzOloTqnHrTVb4a60odh712To5foQ2Bq rvjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=2LqaV9BTtbrTFGQWTcBPV1bpXnsRTNrABakmuPV/44o=; b=tn6VZHU3sq/bX9nYM1FUJMa441Yz9H+ynMJRrWjE/wzwba+iXmSqOPMJeqQEAi51m8 3rek1R54q2+/65rY2mqdbeFErQ8YbqWgXAZAirbzICj8Uyrr5AdgGSNVwFuADwyrQo8/ LldHtP0e7UWObe5HZGjnSVon8DDjwkiE3MJsNIupc4RIJAvevhjtEIM8fFWxWsXjkhao hRAiqKwrjDNwyMBW81wjxqDFsP+iA3BCRn2V6U0IA7sHrb7aMd2n0fARXMCLrMVLUbYf ZxEYdiOUjpp1+gC/u2kamove2qmIGYQ601FnhMweuULwdSgJpzBB2QnI6WsdBoeFoUz4 2F8w== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id h10-20020aa7c60a000000b0050bc6c617a1si15463650edq.113.2023.05.17.03.23.24; Wed, 17 May 2023 03:23:24 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C1ABD68C144; Wed, 17 May 2023 13:21:09 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A99CD68C142 for ; Wed, 17 May 2023 13:20:57 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 1A994240D0E for ; Wed, 17 May 2023 12:20:57 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id fExiW33WJwka for ; Wed, 17 May 2023 12:20:55 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 48161240D1C for ; Wed, 17 May 2023 12:20:46 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 051C13A228B for ; Wed, 17 May 2023 12:20:41 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 May 2023 12:20:28 +0200 Message-Id: <20230517102029.541-35-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517102029.541-1-anton@khirnov.net> References: <20230517102029.541-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 35/36] fftools/ffmpeg_dec: inline decode_audio() into dec_packet() 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: coiJGjbb086p The former function is now trivial - it has 3 lines and cannot fail. --- fftools/ffmpeg_dec.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c index 4662d0a265..c8f9ba0f0c 100644 --- a/fftools/ffmpeg_dec.c +++ b/fftools/ffmpeg_dec.c @@ -128,17 +128,6 @@ static void audio_ts_process(InputStream *ist, AVFrame *frame) frame->time_base = tb_filter; } -static int decode_audio(InputStream *ist, AVFrame *decoded_frame) -{ - ist->samples_decoded += decoded_frame->nb_samples; - - audio_ts_process(ist, decoded_frame); - - ist->nb_samples = decoded_frame->nb_samples; - - return 0; -} - static int64_t video_duration_estimate(const InputStream *ist, const AVFrame *frame) { const InputFile *ifile = input_files[ist->file_index]; @@ -463,14 +452,18 @@ int dec_packet(InputStream *ist, const AVPacket *pkt, int no_eof) frame->time_base = dec->pkt_timebase; - ret = dec->codec_type == AVMEDIA_TYPE_AUDIO ? - decode_audio(ist, frame) : - decode_video(ist, frame); + if (dec->codec_type == AVMEDIA_TYPE_AUDIO) { + ist->samples_decoded += frame->nb_samples; + ist->nb_samples = frame->nb_samples; - if (ret < 0) { - av_log(NULL, AV_LOG_FATAL, "Error while processing the decoded " - "data for stream #%d:%d\n", ist->file_index, ist->st->index); - exit_program(1); + audio_ts_process(ist, frame); + } else { + ret = decode_video(ist, frame); + if (ret < 0) { + av_log(NULL, AV_LOG_FATAL, "Error while processing the decoded " + "data for stream #%d:%d\n", ist->file_index, ist->st->index); + exit_program(1); + } } ist->frames_decoded++; From patchwork Wed May 17 10:20:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41671 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ba91:b0:105:feb:71f2 with SMTP id fb17csp1078885pzb; Wed, 17 May 2023 03:23:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4Oa8XlAH2fJ1LaCJ56Yz3Cy2myGkOUcu9JFllqvIP2zpHhuCZqu9op7etECnScUnRM0Dnk X-Received: by 2002:a05:6402:707:b0:50b:d18c:620a with SMTP id w7-20020a056402070700b0050bd18c620amr1447273edx.25.1684318987438; Wed, 17 May 2023 03:23:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684318987; cv=none; d=google.com; s=arc-20160816; b=lJmic2UL0wyFb2sLb/8FZmJRT/4otv8ixiC/zS+6CSl47+OmfC9gm13zE6JpbeATtS Y8hRMbS2oQhFcU09HuQoxWiiYy41gN4wd3Ivle/BzjC0pmXVwD28IdtgjOYvM/eTN0TB NN3Lz3UM82d5IA/eNZzrsDk5N+cqz/7oOipTYzDdTkyeVrEuWmpqUTNqaPE4x/KkmENc 50PvCA3L2fzi7CqAmUbLozw3ycRm619ov3RXBUhTOZTNmfG30e65RJpOSE5OMeH5nhej 0HCYJsWssIpEiFGMpF1bow6nTe52yaI3TpgjoUQtGE4ZOSTdRnD0wN6tuzHbM2wfuwvu u4jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=rrqm6R46W1q9DhkjgamcXs1u//K+GXjCPjZDKeBL1Hw=; b=mEz0Y34XHZ4cM+patE7UOXjxUnZtIiwm4oX0YuE1oPT/HGsJPxJuJE1jvJknQDgMZT hx/93TggkTeRqU6D0pu5GEGzzZRY6G3+Sh1ppn3s3Z0pj/JQG68JLZ5c4QHnLbBkH5Cv YaLdMvq8YVB/DkKT1ljN7C3LExeBlaXctpYT4wUtmx78D/e2tcQH6yJDtRpFTJf/1EhI H5R/LRAwSgok8mMGbROIAYo+2GIjDmWmzQgGFiVrVtX6Rzkw5odKGak4a1zTU32lnjM4 DOk1pi9SOtngXFWc2a8nKK3qRsagzKPaVPZdaVRi5EU21FXnoJpuEVpKlqxkPgGYJv/k K+jA== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id m22-20020aa7c496000000b0050c061ddcb3si14424185edq.222.2023.05.17.03.23.07; Wed, 17 May 2023 03:23:07 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3470B68C199; Wed, 17 May 2023 13:21:08 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A6C8068C140 for ; Wed, 17 May 2023 13:20:57 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 2E19B240705 for ; Wed, 17 May 2023 12:20:56 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id iRpJCqt30s_x for ; Wed, 17 May 2023 12:20:55 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 5DB88240D1F for ; Wed, 17 May 2023 12:20:46 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 10DCE3A22E3 for ; Wed, 17 May 2023 12:20:41 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 May 2023 12:20:29 +0200 Message-Id: <20230517102029.541-36-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517102029.541-1-anton@khirnov.net> References: <20230517102029.541-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 36/36] fftools/ffmpeg_dec: rename decode_video() to video_frame_process() 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: nv1GQx743UPE This function does not do any decoding anymore. --- fftools/ffmpeg_dec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c index c8f9ba0f0c..b541d30214 100644 --- a/fftools/ffmpeg_dec.c +++ b/fftools/ffmpeg_dec.c @@ -179,7 +179,7 @@ static int64_t video_duration_estimate(const InputStream *ist, const AVFrame *fr return FFMAX(ist->last_frame_duration_est, 1); } -static int decode_video(InputStream *ist, AVFrame *frame) +static int video_frame_process(InputStream *ist, AVFrame *frame) { // The following line may be required in some cases where there is no parser // or the parser does not has_b_frames correctly @@ -458,7 +458,7 @@ int dec_packet(InputStream *ist, const AVPacket *pkt, int no_eof) audio_ts_process(ist, frame); } else { - ret = decode_video(ist, frame); + ret = video_frame_process(ist, frame); if (ret < 0) { av_log(NULL, AV_LOG_FATAL, "Error while processing the decoded " "data for stream #%d:%d\n", ist->file_index, ist->st->index);