From patchwork Thu Apr 27 14:25: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: 41368 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dca6:b0:f3:34fa:f187 with SMTP id ky38csp563468pzb; Thu, 27 Apr 2023 07:27:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5t56yNLFTebcI98+k4JFJNO0OF8D04LDJPhCMVVUXZwdwUwrG9Qhyu6F0lTqo2fwG8AZdo X-Received: by 2002:a17:907:e87:b0:94f:27a1:f1d with SMTP id ho7-20020a1709070e8700b0094f27a10f1dmr2164497ejc.77.1682605632535; Thu, 27 Apr 2023 07:27:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682605632; cv=none; d=google.com; s=arc-20160816; b=w7R+gCJEufs+JQZSjXCKEUjRGhxLa3n+IHm+Xw/MM+YRDdf2CHzbdQpocIJ8a8BjF5 HyG54k8n6hLBfZkrLqJrXyvQOqg7U7tl/5EfTvLtBQOvXmmHySrdRFB7XTIgpau1yTN5 5HN9E1QyGXVTVbDlzVDnvLKi8QvhTxCUN73H2oWkfGJbvy49wPmOxwGZxMYQMgVK7kRG Hc5WK2FYYuxmrdd2NVllXEQfQ03It8zFv8Xyh/1b49PrdLR1voWVO1Y96ir4S86rmedr xNiESwUJ/8e+ET6tYkkYJVSzKLQf9ibbayoYNoRgfP+kyuAmVVadhoewLDc/JcyL1eXB RmPw== 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=L6KysXHsa5r8ZPkctAWvHhiyKbIRnMqBGNwrh5jR4kU=; b=iU2fKJrjrIITH0AMwcqrGVxNWo0Ab/kt9bml3kHkOOmZuI+y4VoK6Xv31HPsOFtlke IaNY3OENIxWcpMH4JGZXPBjuhuIHl7T7gSJRGHuSMfUM2UGr6+6ojHy+gAc2MQDDsrC9 zJQjB6IsgVSQjZBtId9brXLZ9Yte00M4nIEeTT9BpaVJtCclqIBgRz8DSrBj+E/ZYagY UCbdgit/Tt6wl1lnh0ClltO1dWV1ZVoIVvHSGdnFMy6YLmxqG4N8cYEdtPnJUmqD5hbh NYyaO/ilxc6UpuXbWhBnE+6193n7K6u0Q5BYhKQPneJcWeGCMCJn4gLo6yLSZHYIQEc8 CazQ== 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 m5-20020a17090607c500b0094f2e8d96a5si13232542ejc.985.2023.04.27.07.27.11; Thu, 27 Apr 2023 07:27:12 -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 3135668BF71; Thu, 27 Apr 2023 17:26: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 2E69C68BF4F for ; Thu, 27 Apr 2023 17:26:13 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id E1AC02406CE for ; Thu, 27 Apr 2023 16:26:11 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id y4_2MJcr9A4H for ; Thu, 27 Apr 2023 16:26:11 +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 B27292406D0 for ; Thu, 27 Apr 2023 16:26:05 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id A331B3A03E5 for ; Thu, 27 Apr 2023 16:26:05 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 27 Apr 2023 16:25:55 +0200 Message-Id: <20230427142601.2613-15-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230427142601.2613-1-anton@khirnov.net> References: <20230427142601.2613-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 15/21] fftools/ffmpeg: set AVFrame.time_base for decoded frames 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: KBUwOs1UjIU9 Makes it easier to keep track of the timebase the frames are in. --- fftools/ffmpeg.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 5913a57d16..8829a163e0 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -855,6 +855,8 @@ static int decode(InputStream *ist, AVCodecContext *avctx, fd->idx = avctx->frame_num - 1; } + frame->time_base = avctx->pkt_timebase; + *got_frame = 1; } @@ -885,7 +887,6 @@ static int decode_audio(InputStream *ist, AVPacket *pkt, int *got_output, AVFrame *decoded_frame = ist->decoded_frame; AVCodecContext *avctx = ist->dec_ctx; int ret, err = 0; - AVRational decoded_frame_tb; update_benchmark(NULL); ret = decode(ist, avctx, decoded_frame, got_output, pkt); @@ -909,23 +910,24 @@ static int decode_audio(InputStream *ist, AVPacket *pkt, int *got_output, ist->next_dts += ((int64_t)AV_TIME_BASE * decoded_frame->nb_samples) / decoded_frame->sample_rate; - if (decoded_frame->pts != AV_NOPTS_VALUE) { - decoded_frame_tb = ist->st->time_base; - }else { + if (decoded_frame->pts == AV_NOPTS_VALUE) { decoded_frame->pts = ist->dts; - decoded_frame_tb = AV_TIME_BASE_Q; + decoded_frame->time_base = AV_TIME_BASE_Q; } if (pkt && pkt->duration && ist->prev_pkt_pts != AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE && pkt->pts - ist->prev_pkt_pts > pkt->duration) ist->filter_in_rescale_delta_last = AV_NOPTS_VALUE; if (pkt) ist->prev_pkt_pts = pkt->pts; - if (decoded_frame->pts != AV_NOPTS_VALUE) - decoded_frame->pts = av_rescale_delta(decoded_frame_tb, decoded_frame->pts, - (AVRational){1, decoded_frame->sample_rate}, - decoded_frame->nb_samples, + if (decoded_frame->pts != AV_NOPTS_VALUE) { + AVRational tb_filter = (AVRational){1, decoded_frame->sample_rate}; + decoded_frame->pts = av_rescale_delta(decoded_frame->time_base, decoded_frame->pts, + tb_filter, decoded_frame->nb_samples, &ist->filter_in_rescale_delta_last, - (AVRational){1, decoded_frame->sample_rate}); + tb_filter); + decoded_frame->time_base = tb_filter; + } + ist->nb_samples = decoded_frame->nb_samples; err = send_frame_to_filters(ist, decoded_frame);