From patchwork Sun Jan 29 21:33:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 40170 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3ca3:b0:b9:1511:ac2c with SMTP id b35csp2967034pzj; Sun, 29 Jan 2023 13:35:09 -0800 (PST) X-Google-Smtp-Source: AMrXdXu1VLajkL1xDjQkM36ScynKubW18+kJ4aJCmNG4ahoNTwgmhrOCfhqh+Q9btmDU8oyxwN8p X-Received: by 2002:a05:6402:3214:b0:496:37c9:b8e6 with SMTP id g20-20020a056402321400b0049637c9b8e6mr57097745eda.8.1675028109325; Sun, 29 Jan 2023 13:35:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675028109; cv=none; d=google.com; s=arc-20160816; b=xLu77Hbd5jrKijI9p8d5akoeGCnCu/TZe7aqIkTFYnTscxADUeEQu1USNZn3XJd2sg 4hU0b918SE+Xy3oZ2FLzPOwarzQASluPtnDo2J1TMpRw6/gVgX+4AmnWDLhzwvEbqhCM IqtngjBklXYK3F/s4dctib19gM/mglnZKuUtZOrl5lG3nVPFhUIwqGnZkZxfu6pLez07 pZGwGridUbUqXH9Tk9b8QcGoSWAmnS9CTGcc6gry8hZonGtYb1L9pf2s+hdfBwWKvkad rDaFRdnG8Ryjv3bCVW4NP1JkQ25vGqURQ+oDwQQzZxEsI4hY/MolHX/StZM9hRx7X4jC 0jAQ== 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=2vRX+pEfcjjUyyqanssi3kgXx0+xSkepMjmz9kpXVVE=; b=oUhFvRNc40kXkLCDAwa+Fj/93UjLh1FM2L88YA7e1tam7WHA2JF7MQHWEUuLsQb70T LguIn68vs4pjnwyD/Mu+JToYwcrR3Y4py3D6Q/qFAhIQq9o2fFbvoCsCXHT7Boc//mUW ODKZolpraREpjMiTwNugw92HzdWM9oh7KtjQm5HsY3YZ98zkgYZfRGLRKqxmyp3gCNJV Dg6KO3csE7Xt5RSJscjL0XuHnIOXA4lM9biF1xh0ZA93PbWpQNmY7xeKk8Jw5b633lHB T2RIG6gC6OkyUy1XuudDYGi5wxMV8WGDAmuEi22P/IKkyl7lLs8q09cIGYYYiDKwWJd1 NHTA== 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-20020a056402270c00b00493969bd008si16087925edd.121.2023.01.29.13.35.01; Sun, 29 Jan 2023 13:35:09 -0800 (PST) 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 0B31C68BC8C; Sun, 29 Jan 2023 23:34:49 +0200 (EET) 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 A486668B3DD for ; Sun, 29 Jan 2023 23:34:40 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 6A9B62404EC for ; Sun, 29 Jan 2023 22:34:40 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id zASpke7TOrkK for ; Sun, 29 Jan 2023 22:34:38 +0100 (CET) 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 8D7EA240178 for ; Sun, 29 Jan 2023 22:34:38 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id E98273A02AF for ; Sun, 29 Jan 2023 22:34:30 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 29 Jan 2023 22:33:51 +0100 Message-Id: <20230129213353.9351-1-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] lavu/opt: use AV_DICT_MULTIKEY in av_opt_set_dict2() 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: GSNAc0oMjPyN If the dictionary provided on input contains multiple entries for an option (relevant for flags modifying the previous value with '+' or '-') and the option is not found in the target object, only the last entry would be returned to the caller. Pass AV_DICT_MULTIKEY to av_dict_set() to make sure all such entries are returned. --- libavutil/opt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavutil/opt.c b/libavutil/opt.c index 0a909a8b22..0908751752 100644 --- a/libavutil/opt.c +++ b/libavutil/opt.c @@ -1752,7 +1752,7 @@ int av_opt_set_dict2(void *obj, AVDictionary **options, int search_flags) while ((t = av_dict_iterate(*options, t))) { ret = av_opt_set(obj, t->key, t->value, search_flags); if (ret == AVERROR_OPTION_NOT_FOUND) - ret = av_dict_set(&tmp, t->key, t->value, 0); + ret = av_dict_set(&tmp, t->key, t->value, AV_DICT_MULTIKEY); if (ret < 0) { av_log(obj, AV_LOG_ERROR, "Error setting option %s to value %s.\n", t->key, t->value); av_dict_free(&tmp); From patchwork Sun Jan 29 21:33:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 40171 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3ca3:b0:b9:1511:ac2c with SMTP id b35csp2967035pzj; Sun, 29 Jan 2023 13:35:09 -0800 (PST) X-Google-Smtp-Source: AMrXdXsTvbOPyH2WZ2bH+0Nodc3KMmYQCNssXIjD2FlKm83HLcH15YHMftml/qmxsMDaUago3UL8 X-Received: by 2002:a05:6402:27cf:b0:49e:2e15:3984 with SMTP id c15-20020a05640227cf00b0049e2e153984mr64512964ede.36.1675028109377; Sun, 29 Jan 2023 13:35:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675028109; cv=none; d=google.com; s=arc-20160816; b=GZlsz1o5hXoaLPQL6gW50dR2QDR4ju07d/qqPISo2kFGBf7/0+Rj1+LRNxkYn+TolX +iL/eeZaeT6uQewWnALgirseh/QpbFcpcbuYy5FGWfiGxWScecEo6lVVPPr5vSg3HZFW Mk9jQUZ3bY5ReJZKy++/wI6DHfChgbl51KA+h8SMefVTd5GK0saCNOVM2mx881iU5BoM UosyD7Yu98QEYUPX4xxOSHqWTPd/yCf0dSXbrGLXLiUxpAUOdU20rjR1cNf0Adl7V1nK mv0AYaUk57V6zTl64yf60FA6FBlXvFNd7bPpxQTBOz2iCiEOf9KbaQwqmH7xNpbqhnXQ Qzbg== 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=9vQzwFJ6w1SjKGnxA2IUhae2cyh0Df4XYeQXFx+ya4s=; b=LqKxkZ9Ppo7FjbWCLFQA6Bzdu2s/uCVQUOSbo4L1UcAwTeSvU/TojyirKUqDuuZEce 7uqr48lveuFbSZpnkXULxD7LS1cT/xA0bj8a6dR3i9EMIbVH4hg5QA6DNiZ3JK8fc4sH qMPNlrXA1XDEA3Lu3G8AiCHzZjzZCUf1u/pyXIPt9DP/RQG6ydy2iOgbp6eMqPh8IMWE W1wpoyACDOzLXFFSs0hgMtbh/OCY46HCqQh+0aUL++8/Ro1bzkKTFMyN+yvYXMcOEHYl E+GzMMjw7uccqUXdOGtB4xwtwn65uNeHuDfs7+4IrnZeiene+vQOIYeEHAVQNF1GyX0l ubZA== 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 fi6-20020a056402550600b0049d4fe939b9si11878817edb.434.2023.01.29.13.34.51; Sun, 29 Jan 2023 13:35:09 -0800 (PST) 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 E5CFD68B3DD; Sun, 29 Jan 2023 23:34:47 +0200 (EET) 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 5D75768B3DD for ; Sun, 29 Jan 2023 23:34:40 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 993252404F5 for ; Sun, 29 Jan 2023 22:34:39 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id AKXaYI4a4viC for ; Sun, 29 Jan 2023 22:34:38 +0100 (CET) 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 92A092404EC for ; Sun, 29 Jan 2023 22:34:38 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 02A8D3A0344 for ; Sun, 29 Jan 2023 22:34:31 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 29 Jan 2023 22:33:52 +0100 Message-Id: <20230129213353.9351-2-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230129213353.9351-1-anton@khirnov.net> References: <20230129213353.9351-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/3] fftools/ffmpeg: use correct IO context for -enc_stats_post 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: pGCH4sQ3efSl --- fftools/ffmpeg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 9884e0c6c6..3ad432ff54 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -803,7 +803,7 @@ static void update_video_stats(OutputStream *ost, const AVPacket *pkt, int write static void enc_stats_write(OutputStream *ost, EncStats *es, const AVFrame *frame, const AVPacket *pkt) { - AVIOContext *io = ost->enc_stats_pre.io; + AVIOContext *io = es->io; AVRational tb = ost->enc_ctx->time_base; int64_t pts = frame ? frame->pts : pkt->pts; From patchwork Sun Jan 29 21:33:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 40172 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3ca3:b0:b9:1511:ac2c with SMTP id b35csp2967039pzj; Sun, 29 Jan 2023 13:35:10 -0800 (PST) X-Google-Smtp-Source: AMrXdXseU+M5KtCIBr0pav00Oe/CnWwnN5XhdvyLiz+QPjDBDYFKmOr4xudGRWWiag0ZfLhaFOPy X-Received: by 2002:a50:fe87:0:b0:49b:7416:e3f9 with SMTP id d7-20020a50fe87000000b0049b7416e3f9mr50966083edt.35.1675028110097; Sun, 29 Jan 2023 13:35:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675028110; cv=none; d=google.com; s=arc-20160816; b=tq1//8MIUuE8uqLLpn2HGOC8jt+BIts1DbWqwkqmhjuir5YSbbT/1bvyiuuqhiXJ3C 1ZKXUk1cHXTZeGblJedgenQ7cwhZ/uzsLRF5So4cgkAYY0bvtyCkebUxYlIpwMrjW8WW 5SxdFdo9j7VBmhMjyBibZZx3dcP+4ID+bwY2yzQvIPFwIk4bmFqtdAjh+Zh3Cj0xJ/Jp d6j2mJTgfLQPuDJOF1vfJQ1zbsL9Dc52K8BG0AaN+tErrtDwDREtD27FkM3Ni+pr5M2b 2LTgFsxO8X/M0Zrq2R/ks/ejvzuvokF7ATqsAFYN+HOo8bIc0Q+pnmtUlWsNwBdIJdOS N+bA== 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=n7q4wM6OFJrNHEFCstCzE2Hy3/ii7NqSbltNpPuYCEU=; b=xkW6Y6aGDjYlU0EBQIqVQtHE3GCeIVOl9ZTG3FJwn5I3uwaicatkHWbL8fyE+Y6LWK LMdnY6y25ZddzH4FI6uQ5nesyar1IFNT0TIWehbxyO+NqV0uZjWQs+zpVE+vrioNU1Nk d09Gi48bKsfDG1azS8t6tRQY0ygl1TDDZxXBzdQjeENftHN/gF33tmwc+aZntvDYsjOf E6pJ40IZztHpKRg+lnNL05RfLUG7yrLxtKU7mNa5h9r8klcj37raBpVxr5BcrZel4uce EFf/IIpnF+iM3+y4rUjPyGucpO3yPZy+EkUATTBRG88DIbZhXCCkD30ebB4XesaA1Rj3 AA+g== 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 n15-20020a05640205cf00b0048ee8cf8bb8si13325941edx.53.2023.01.29.13.35.09; Sun, 29 Jan 2023 13:35:10 -0800 (PST) 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 1B67268BCA4; Sun, 29 Jan 2023 23:34:50 +0200 (EET) 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 DCBB468B3DD for ; Sun, 29 Jan 2023 23:34:40 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 9A404240178 for ; Sun, 29 Jan 2023 22:34:40 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id T51df1i1b6a1 for ; Sun, 29 Jan 2023 22:34:39 +0100 (CET) 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 951702404EE for ; Sun, 29 Jan 2023 22:34:38 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 0E0163A034A for ; Sun, 29 Jan 2023 22:34:31 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 29 Jan 2023 22:33:53 +0100 Message-Id: <20230129213353.9351-3-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230129213353.9351-1-anton@khirnov.net> References: <20230129213353.9351-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/3] fftools/ffmpeg: support input frame params in encoding stats 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: rWpKjoz3hMcZ --- doc/ffmpeg.texi | 17 ++++++++++++ fftools/ffmpeg.c | 54 ++++++++++++++++++++++++++++++++++++--- fftools/ffmpeg.h | 6 +++++ fftools/ffmpeg_mux_init.c | 21 +++++++++++++-- 4 files changed, 92 insertions(+), 6 deletions(-) diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi index 7f445022a0..81e04f6983 100644 --- a/doc/ffmpeg.texi +++ b/doc/ffmpeg.texi @@ -2082,18 +2082,35 @@ Index of the output stream in the file. Frame number. Pre-encoding: number of frames sent to the encoder so far. Post-encoding: number of packets received from the encoder so far. +@item ni +Input frame number. Index of the input frame (i.e. output by a decoder) that +corresponds to this output frame or packet. -1 if unavailable. + @item tb Encoder timebase, as a rational number @var{num/den}. Note that this may be different from the timebase used by the muxer. +@item tbi +Timebase for @var{ptsi}, as a rational number @var{num/den}. Available when +@var{ptsi} is available, @var{0/1} otherwise. + @item pts Presentation timestamp of the frame or packet, as an integer. Should be multiplied by the timebase to compute presentation time. +@item ptsi +Presentation timestamp of the input frame (see @var{ni}), as an integer. Should +be multiplied by @var{tbi} to compute presentation time. Printed as +(2^63 - 1 = 9223372036854775807) when not available. + @item t Presentation time of the frame or packet, as a decimal number. Equal to @var{pts} multiplied by @var{tb}. +@item ti +Presentation time of the input frame (see @var{ni}), as a decimal number. Equal +to @var{ptsi} multiplied by @var{tbi}. Printed as inf when not available. + @item dts Decoding timestamp of the packet, as an integer. Should be multiplied by the timebase to compute presentation time. Post-encoding only. diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 3ad432ff54..92fd61f315 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -113,6 +113,13 @@ const int program_birth_year = 2000; static FILE *vstats_file; +// optionally attached as opaque_ref to decoded AVFrames +typedef struct FrameData { + uint64_t idx; + int64_t pts; + AVRational tb; +} FrameData; + typedef struct BenchmarkTimeStamps { int64_t real_usec; int64_t user_usec; @@ -807,6 +814,17 @@ static void enc_stats_write(OutputStream *ost, EncStats *es, AVRational tb = ost->enc_ctx->time_base; int64_t pts = frame ? frame->pts : pkt->pts; + AVRational tbi = (AVRational){ 0, 1}; + int64_t ptsi = INT64_MAX; + + const FrameData *fd; + + if ((frame && frame->opaque_ref) || (pkt && pkt->opaque_ref)) { + fd = (const FrameData*)(frame ? frame->opaque_ref->data : pkt->opaque_ref->data); + tbi = fd->tb; + ptsi = fd->pts; + } + for (size_t i = 0; i < es->nb_components; i++) { const EncStatsComponent *c = &es->components[i]; @@ -815,8 +833,13 @@ static void enc_stats_write(OutputStream *ost, EncStats *es, case ENC_STATS_FILE_IDX: avio_printf(io, "%d", ost->file_index); continue; case ENC_STATS_STREAM_IDX: avio_printf(io, "%d", ost->index); continue; case ENC_STATS_TIMEBASE: avio_printf(io, "%d/%d", tb.num, tb.den); continue; + case ENC_STATS_TIMEBASE_IN: avio_printf(io, "%d/%d", tbi.num, tbi.den); continue; case ENC_STATS_PTS: avio_printf(io, "%"PRId64, pts); continue; + case ENC_STATS_PTS_IN: avio_printf(io, "%"PRId64, ptsi); continue; case ENC_STATS_PTS_TIME: avio_printf(io, "%g", pts * av_q2d(tb)); continue; + case ENC_STATS_PTS_TIME_IN: avio_printf(io, "%g", ptsi == INT64_MAX ? + INFINITY : ptsi * av_q2d(tbi)); continue; + case ENC_STATS_FRAME_NUM_IN: avio_printf(io, "%"PRIu64, fd ? fd->idx : -1); continue; } if (frame) { @@ -2034,7 +2057,8 @@ static int ifilter_send_eof(InputFilter *ifilter, int64_t pts) // 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(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt) +static int decode(InputStream *ist, AVCodecContext *avctx, + AVFrame *frame, int *got_frame, AVPacket *pkt) { int ret; @@ -2051,8 +2075,24 @@ static int decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacke ret = avcodec_receive_frame(avctx, frame); if (ret < 0 && ret != AVERROR(EAGAIN)) return ret; - if (ret >= 0) + 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_number - 1; + } + *got_frame = 1; + } return 0; } @@ -2084,7 +2124,7 @@ static int decode_audio(InputStream *ist, AVPacket *pkt, int *got_output, AVRational decoded_frame_tb; update_benchmark(NULL); - ret = decode(avctx, decoded_frame, got_output, pkt); + 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; @@ -2163,7 +2203,7 @@ static int decode_video(InputStream *ist, AVPacket *pkt, int *got_output, int64_ } update_benchmark(NULL); - ret = decode(ist->dec_ctx, decoded_frame, got_output, pkt); + ret = decode(ist, ist->dec_ctx, decoded_frame, got_output, pkt); update_benchmark("decode_video %d.%d", ist->file_index, ist->st->index); if (ret < 0) *decode_failed = 1; @@ -3017,6 +3057,12 @@ static int init_output_stream(OutputStream *ost, AVFrame *frame, if (!av_dict_get(ost->encoder_opts, "threads", NULL, 0)) av_dict_set(&ost->encoder_opts, "threads", "auto", 0); + if (codec->capabilities & AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE) { + ret = av_dict_set(&ost->encoder_opts, "flags", "+copy_opaque", AV_DICT_MULTIKEY); + if (ret < 0) + return ret; + } + ret = hw_device_setup_for_encode(ost); if (ret < 0) { snprintf(error, error_len, "Device setup failed for " diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index dddab456f7..8c976af97a 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -335,6 +335,8 @@ typedef struct InputStream { #define DECODING_FOR_OST 1 #define DECODING_FOR_FILTER 2 int processing_needed; /* non zero if the packets must be processed */ + // should attach FrameData as opaque_ref after decoding + int want_frame_data; /** * Codec parameters - to be used by the decoding/streamcopy code. @@ -493,9 +495,13 @@ enum EncStatsType { ENC_STATS_FILE_IDX, ENC_STATS_STREAM_IDX, ENC_STATS_FRAME_NUM, + ENC_STATS_FRAME_NUM_IN, ENC_STATS_TIMEBASE, + ENC_STATS_TIMEBASE_IN, ENC_STATS_PTS, ENC_STATS_PTS_TIME, + ENC_STATS_PTS_IN, + ENC_STATS_PTS_TIME_IN, ENC_STATS_DTS, ENC_STATS_DTS_TIME, ENC_STATS_SAMPLE_NUM, diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 35b115f8a6..f8ccf4a3e9 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -269,13 +269,18 @@ static int enc_stats_init(OutputStream *ost, int pre, const char *str; int pre_only:1; int post_only:1; + int need_input_data:1; } fmt_specs[] = { { ENC_STATS_FILE_IDX, "fidx" }, { ENC_STATS_STREAM_IDX, "sidx" }, { ENC_STATS_FRAME_NUM, "n" }, + { ENC_STATS_FRAME_NUM_IN, "ni", 0, 0, 1 }, { ENC_STATS_TIMEBASE, "tb" }, + { ENC_STATS_TIMEBASE_IN, "tbi", 0, 0, 1 }, { ENC_STATS_PTS, "pts" }, { ENC_STATS_PTS_TIME, "t" }, + { ENC_STATS_PTS_IN, "ptsi", 0, 0, 1 }, + { ENC_STATS_PTS_TIME_IN, "ti", 0, 0, 1 }, { ENC_STATS_DTS, "dts", 0, 1 }, { ENC_STATS_DTS_TIME, "dt", 0, 1 }, { ENC_STATS_SAMPLE_NUM, "sn", 1 }, @@ -345,6 +350,18 @@ static int enc_stats_init(OutputStream *ost, int pre, } c->type = fmt_specs[i].type; + + if (fmt_specs[i].need_input_data) { + if (ost->ist) + ost->ist->want_frame_data = 1; + else { + av_log(ost, AV_LOG_WARNING, + "Format directive '%s' is unavailable, because " + "this output stream has no associated input stream\n", + val); + } + } + break; } } @@ -428,6 +445,7 @@ static OutputStream *new_output_stream(Muxer *mux, const OptionsContext *o, ms->last_mux_dts = AV_NOPTS_VALUE; ost->st = st; + ost->ist = ist; ost->kf.ref_pts = AV_NOPTS_VALUE; st->codecpar->codec_type = type; @@ -605,8 +623,7 @@ static OutputStream *new_output_stream(Muxer *mux, const OptionsContext *o, if (ost->enc_ctx && av_get_exact_bits_per_sample(ost->enc_ctx->codec_id) == 24) av_dict_set(&ost->swr_opts, "output_sample_bits", "24", 0); - if (ist) { - ost->ist = ist; + if (ost->ist) { ost->ist->discard = 0; ost->ist->st->discard = ost->ist->user_set_discard; }