From patchwork Sun Apr 9 14:08: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: 41045 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp1590771pzb; Sun, 9 Apr 2023 07:09:38 -0700 (PDT) X-Google-Smtp-Source: AKy350aw7D4OshYoiZbiPIMVVuYIFNZdlTzMV6V9jNtG6jqMaw2z7Led9iGjk8N1F/WdSR4I0hBk X-Received: by 2002:a17:906:5fcb:b0:878:7189:a457 with SMTP id k11-20020a1709065fcb00b008787189a457mr5450292ejv.51.1681049377862; Sun, 09 Apr 2023 07:09:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681049377; cv=none; d=google.com; s=arc-20160816; b=NsNe2NxE/TayA4tTdZB/YQpqRcChFXSmHzV5BJEB0pAVRo04P8M/RUSJSTiXmtev9I Xq6tkOZyw4qz13IEDE4V551id0LTnQFGA0velxzNeNBYZ2MygEOwDj3+ArK6S+iVaSzG 3Abt7yaIBUdqhB1wmLU2kuv2OXdI9vMihT1a4ofBaabbqaNZY2wBogl6Bm0vhQIVt8x0 e7cfyJhKKyPu7/kXo67dYn5ak0JDJqOBwocRpXSUdHD10QKvu0pu95K1GWmco2/E89iq yWtOXr+ly6Y3NpkQCk0sxEcnDpNXkmU4Hnl/u9bkdUazryG1+OS/DOj1CimlYCtV/JTF aWSA== 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=4s32RF/rOFr2vpwBzYpOUxxrQPkpBAR9kTzyh6CCPVQ=; b=a+xnGcOxCdOSu762pGPHyWBVKQqEjVrPUJoAFKjUOZ/an4C0ro+fN5PDt3Yc4ajCPS eadRzu1DPO99PSrwt1NzxWJ2erDBkb/wFyjUcU1N2JZab9XN7BzI5BGxKjob/Z7gI4qr tXzzj1gWqq7Q0qsOf2Tdn4P1WmbM7s4Rdii/W4bgkBJQRtkvsw1zQp7WrUOBmx3CECRg uzJi4wRaAv5NcRNHW6zfaqGaZeZUdQv5rIFleVQ9y2x9FLhNoOpY5xgFOipiYg9C/fGi 3a3QBf3f+syqEvD9jsADJ1mxb2QFerAu9hiw1eEOZUD3KjzQOwjSNg77MudWVWfFJdx+ OUOQ== 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-20020a17090671cb00b0093d4fb59d99si3881532ejk.422.2023.04.09.07.09.37; Sun, 09 Apr 2023 07:09: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 C5A8668BCC3; Sun, 9 Apr 2023 17:09: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 C344D689CE2 for ; Sun, 9 Apr 2023 17:09:11 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 90AC12404F8 for ; Sun, 9 Apr 2023 16:09:11 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 2lihZ9vqVhRn for ; Sun, 9 Apr 2023 16:09:10 +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 0E0B82404EC for ; Sun, 9 Apr 2023 16:09:10 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id C65303A039B for ; Sun, 9 Apr 2023 16:09:09 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 9 Apr 2023 16:08:26 +0200 Message-Id: <20230409140853.28858-2-anton@khirnov.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230409140853.28858-1-anton@khirnov.net> References: <20230409140853.28858-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 02/29] fftools/ffmpeg: move OutputStream.next_pts to Encoder 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: CHYliyAMlSwy It is audio/video encoding-only and does not need to be visible outside of ffmpeg_enc.c --- fftools/ffmpeg.h | 3 --- fftools/ffmpeg_enc.c | 22 +++++++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 886124d874..e7e7d88577 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -571,9 +571,6 @@ typedef struct OutputStream { InputStream *ist; AVStream *st; /* stream in the output file */ - /* predicted pts of the next frame to be encoded - * audio/video encoding only */ - int64_t next_pts; /* dts of the last packet sent to the muxing queue, in AV_TIME_BASE_Q */ int64_t last_mux_dts; /* pts of the last frame received from the filters, in AV_TIME_BASE_Q */ diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index 5266026945..bb11cdf42a 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -44,6 +44,9 @@ #include "libavformat/avformat.h" struct Encoder { + /* predicted pts of the next frame to be encoded */ + int64_t next_pts; + AVFrame *last_frame; /* number of frames emitted by the video-encoding sync code */ int64_t vsync_frame_number; @@ -761,11 +764,12 @@ static int submit_encode_frame(OutputFile *of, OutputStream *ost, static void do_audio_out(OutputFile *of, OutputStream *ost, AVFrame *frame) { + Encoder *e = ost->enc; AVCodecContext *enc = ost->enc_ctx; int ret; if (frame->pts == AV_NOPTS_VALUE) - frame->pts = ost->next_pts; + frame->pts = e->next_pts; else { int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time; frame->pts = @@ -777,7 +781,7 @@ static void do_audio_out(OutputFile *of, OutputStream *ost, if (!check_recording_time(ost, frame->pts, frame->time_base)) return; - ost->next_pts = frame->pts + frame->nb_samples; + e->next_pts = frame->pts + frame->nb_samples; ret = submit_encode_frame(of, ost, frame); if (ret < 0 && ret != AVERROR_EOF) @@ -840,7 +844,7 @@ static void video_sync_process(OutputFile *of, OutputStream *ost, double sync_ipts = adjust_frame_pts_to_encoder_tb(of, ost, next_picture); /* delta0 is the "drift" between the input frame (next_picture) and * where it would fall in the output. */ - delta0 = sync_ipts - ost->next_pts; + delta0 = sync_ipts - e->next_pts; delta = delta0 + duration; // tracks the number of times the PREVIOUS frame should be duplicated, @@ -857,7 +861,7 @@ static void video_sync_process(OutputFile *of, OutputStream *ost, av_log(ost, AV_LOG_VERBOSE, "Past duration %f too large\n", -delta0); } else av_log(ost, AV_LOG_DEBUG, "Clipping frame in rate conversion by %f\n", -delta0); - sync_ipts = ost->next_pts; + sync_ipts = e->next_pts; duration += delta0; delta0 = 0; } @@ -868,7 +872,7 @@ static void video_sync_process(OutputFile *of, OutputStream *ost, av_log(ost, AV_LOG_DEBUG, "Not duplicating %d initial frames\n", (int)lrintf(delta0)); delta = duration; delta0 = 0; - ost->next_pts = llrint(sync_ipts); + e->next_pts = llrint(sync_ipts); } case VSYNC_CFR: // FIXME set to 0.5 after we fix some dts/pts bugs like in avidec.c @@ -887,13 +891,13 @@ static void video_sync_process(OutputFile *of, OutputStream *ost, if (delta <= -0.6) *nb_frames = 0; else if (delta > 0.6) - ost->next_pts = llrint(sync_ipts); + e->next_pts = llrint(sync_ipts); next_picture->duration = duration; break; case VSYNC_DROP: case VSYNC_PASSTHROUGH: next_picture->duration = duration; - ost->next_pts = llrint(sync_ipts); + e->next_pts = llrint(sync_ipts); break; default: av_assert0(0); @@ -1031,7 +1035,7 @@ static void do_video_out(OutputFile *of, if (!in_picture) return; - in_picture->pts = ost->next_pts; + in_picture->pts = e->next_pts; if (!check_recording_time(ost, in_picture->pts, ost->enc_ctx->time_base)) return; @@ -1045,7 +1049,7 @@ static void do_video_out(OutputFile *of, else if (ret < 0) exit_program(1); - ost->next_pts++; + e->next_pts++; e->vsync_frame_number++; }