From patchwork Thu Aug 11 07:45:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 37235 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3d0d:b0:8d:a68e:8a0e with SMTP id y13csp204338pzi; Thu, 11 Aug 2022 00:46:00 -0700 (PDT) X-Google-Smtp-Source: AA6agR6DAixbKMXVc2VkNZ/h7olDQSdZtJ3cMaBSTe2gJfN2nV3iQovvhdhSuymqbLTwVzJT7F6r X-Received: by 2002:a17:907:3e86:b0:6f5:917:10cc with SMTP id hs6-20020a1709073e8600b006f5091710ccmr23498722ejc.53.1660203960375; Thu, 11 Aug 2022 00:46:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660203960; cv=none; d=google.com; s=arc-20160816; b=SDUPetM3QaMTk4hNlXroo+nse3HF7U9hpoyOJ1hBtvXVG+5mmP3bgbBjcihPn3g8js KCefjzm6Xy8IjTWVcINTZNOxtT48ONQhh3mqW/Y9pjM0zVRxrMAJXXZ/hSnFyk9I/Uiq kjHj4sA9RlY/CJDXlZ8SMY7I8hSV8aFN00wRaeHEi72rhbKrHy9G7TR4+dDD6P31tzlE pmVUChd/pwySOIQvw4FHl6zSH68WUC1hdOLkqo9+a3Ztpy8P+cc7hDgEHVH11PeEzLUF O9TpKZelNlVoS56U3OpVJkSqMOVay/faLUxxAHH9FxTmjzuuxAJ4jZ4ov1umCeD+ovfS ig0w== 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=LZgFzYkN79nQaeevb4uV2Nmv8KG4wCK/m3h1hQvAB1w=; b=OQVua3Mquh51L7aCuWVulEgagcxXzMoYWX+q1R1A4yfiuojDMVkRXz7p9FSSFfHA4m k2kUPto55Hw2yn1r/2ele4SS/pIieozgogQy8H+5Sf66rrVZILvBs/ramn8wdUX/9Ooc inOMqx1rYNHjM6if5IATFN7Y7hHmMF6+MpG52i5C/extU6iCBlxLVw0tg8Gv2eOCbzRU Ls9LR0z1xw9meL/ZsS+b6C9LElG0wSJI9vyqjy4gZTaiMNw/qPlxK82fQPN0ufPClOq8 xUplKPxZCEg/NEvb3Rzsn+cbnohbDG4bCL9CFbH89NUjzWPlkwJm64ZyrHJzOuI6ip70 /Stw== 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 ww6-20020a170907084600b00734bc2f6bb1si192021ejb.801.2022.08.11.00.45.59; Thu, 11 Aug 2022 00:46: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 11C1968B8D9; Thu, 11 Aug 2022 10:45: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 3203C68B636 for ; Thu, 11 Aug 2022 10:45:51 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 7793B240179 for ; Thu, 11 Aug 2022 09:45:50 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 3lISJjXF_hYI for ; Thu, 11 Aug 2022 09:45: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 DCCFA2400F5 for ; Thu, 11 Aug 2022 09:45:49 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id F2C9C3A03EF; Thu, 11 Aug 2022 09:45:49 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 11 Aug 2022 09:45:48 +0200 Message-Id: <20220811074548.11810-1-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220810223303.GD2088045@pb2> References: <20220810223303.GD2088045@pb2> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] fftools/ffmpeg: move stream-dependent starttime correction to transcode_init() 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: Hmp4VS6msN7S Currently this code is located in the discontinuity handling block, where it does not belong. --- Now with previously missed 'is->start_time != AV_NOPTS_VALUE' check --- fftools/ffmpeg.c | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 16b1ba8af7..2e04b2ae81 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -3313,6 +3313,28 @@ static int transcode_init(void) input_streams[j + ifile->ist_index]->start = av_gettime_relative(); } + // Correct starttime based on the enabled streams + for (i = 0; i < nb_input_files; i++) { + InputFile *ifile = input_files[i]; + AVFormatContext *is = ifile->ctx; + int64_t new_start_time = INT64_MAX; + + if (is->start_time == AV_NOPTS_VALUE || + !(is->iformat->flags & AVFMT_TS_DISCONT)) + continue; + + for (int j = 0; j < is->nb_streams; j++) { + AVStream *st = is->streams[j]; + if(st->discard == AVDISCARD_ALL || st->start_time == AV_NOPTS_VALUE) + continue; + new_start_time = FFMIN(new_start_time, av_rescale_q(st->start_time, st->time_base, AV_TIME_BASE_Q)); + } + if (new_start_time > is->start_time) { + av_log(is, AV_LOG_VERBOSE, "Correcting start time by %"PRId64"\n", new_start_time - is->start_time); + ifile->ts_offset = -new_start_time; + } + } + /* init input streams */ for (i = 0; i < nb_input_streams; i++) if ((ret = init_input_stream(i, error, sizeof(error))) < 0) @@ -3752,24 +3774,6 @@ static int process_input(int file_index) if(!ist->wrap_correction_done && is->start_time != AV_NOPTS_VALUE && ist->st->pts_wrap_bits < 64){ int64_t stime, stime2; - // Correcting starttime based on the enabled streams - // FIXME this ideally should be done before the first use of starttime but we do not know which are the enabled streams at that point. - // so we instead do it here as part of discontinuity handling - if ( ist->next_dts == AV_NOPTS_VALUE - && ifile->ts_offset == -is->start_time - && (is->iformat->flags & AVFMT_TS_DISCONT)) { - int64_t new_start_time = INT64_MAX; - for (i=0; inb_streams; i++) { - AVStream *st = is->streams[i]; - if(st->discard == AVDISCARD_ALL || st->start_time == AV_NOPTS_VALUE) - continue; - new_start_time = FFMIN(new_start_time, av_rescale_q(st->start_time, st->time_base, AV_TIME_BASE_Q)); - } - if (new_start_time > is->start_time) { - av_log(is, AV_LOG_VERBOSE, "Correcting start time by %"PRId64"\n", new_start_time - is->start_time); - ifile->ts_offset = -new_start_time; - } - } stime = av_rescale_q(is->start_time, AV_TIME_BASE_Q, ist->st->time_base); stime2= stime + (1ULL<st->pts_wrap_bits);