From patchwork Thu May 6 15:57:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Shiwang.Xie" X-Patchwork-Id: 27616 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:b214:0:0:0:0:0 with SMTP id b20csp139087iof; Thu, 6 May 2021 08:57:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyRI8F4JXLfRvbgnyPGt0qZBSIEM0eRrqm9GMGZ5qum7/9bSw3JBjavzUeAUmUvNbWS6jjC X-Received: by 2002:a05:6402:c1:: with SMTP id i1mr6044879edu.315.1620316661292; Thu, 06 May 2021 08:57:41 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id n17si2657752ejj.409.2021.05.06.08.57.40; Thu, 06 May 2021 08:57: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; dkim=neutral (body hash did not verify) header.i=@outlook.com header.s=selector1 header.b=nFxRMAI4; arc=fail (body hash mismatch); 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3E2F268073F; Thu, 6 May 2021 18:57:36 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from APC01-SG2-obe.outbound.protection.outlook.com (mail-oln040092253080.outbound.protection.outlook.com [40.92.253.80]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5BAF16804AE for ; Thu, 6 May 2021 18:57:29 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BUqtWmOMYZZ9F6pKFbUSeVe+MbGuUcdHdjOc5amHFhlyRD3u2qAaRCMc2NBdxcmT6yuLe1RYmZCipxE+7X5N7d8reiyV60R0T9uMTqUB5/2w65XM2IyJ8mZOGda9JH46LCWOJmw08Swnfl+4Unw7rTX7hEB1vqKqJeGlPQfNbSjLpKtZFBVPdVdOCKwpzDJ7AXNhEjmtK+lctJc6BkKjMMIrQLLTV5p0iNF5HWtVOjbnj/z1MALy1dbzVJV8cKmwkTlCcWbUawsPu/6pQPQDJKe66yE/vy+tEa2qPaaY4dH1X9lUyW51FnaPrThGv2IaXPgrD9T54aZ2tvXwcbTVTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=d+YVF4QJRxUtCdS+GBuaQXiAh9MY1ko9NQ6uws3bPuE=; b=O1y/yUUONMzxfqww6kRuVb5WAhhr2slQxC0+ww02m5fK6V9inYLc6V5J1UeHVS2EW9LDXM8Kl/Pi9cC/IsKH1tsdSrWqG4rIUsoWHfRx7zowR5qw33cyAP1e9Q8wPCV+ol31o7cPyQX5dM10lnsgILTRQmpm8c/1Esf556waL8dWGQ+VFeqC2q2D1vFBXR1mV+pPnf6avWgn3Yc5nsZrwagaL6Ya0ok0Ivtg21jJZjHrNunH8flNPYGdf7h3lffUSDPHbxRxNkqXW25BfEIp5uVi7wL7wN78Ybl3KEOVVLR1uspnNjsWN0TE91LHVf6MdEDia+UPET5MuCacfZPerw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=d+YVF4QJRxUtCdS+GBuaQXiAh9MY1ko9NQ6uws3bPuE=; b=nFxRMAI46Y9lRrXggK4iSpiDj8qXZJd3NaD2/QQ8yEDvthQoUAmD0H8eSldeoh6Zi8CX0FGFoilZAInAtfOK3h2SJvfouW54PtJgw3KH7svKliO21C0D2yjIZOO5lBkKW05ggERPKEl6dABL9DNnJOrqRXmAAL34cCkYSGvwlnRsp/Uo3O1wcVcGJG1OR4XLRl5KkQlbuiQBGz5L72nyD1pc9Jo93tmlbhVHW7klVnPbbmyLGEKPzMTdlsIMmpAdiU/MSItsf4Y5beNFkBWb3EL9b3uZ08fpmjenyrx1efpuzJ2+Ml3VUWeeiAh2UkIKx80E97swhHAa41TZvCvg6A== Received: from SG2PR02CA0010.apcprd02.prod.outlook.com (2603:1096:3:17::22) by HK0PR01MB2914.apcprd01.prod.exchangelabs.com (2603:1096:203:a4::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4087.43; Thu, 6 May 2021 15:57:23 +0000 Received: from SG2APC01FT028.eop-APC01.prod.protection.outlook.com (2603:1096:3:17:cafe::cf) by SG2PR02CA0010.outlook.office365.com (2603:1096:3:17::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.25 via Frontend Transport; Thu, 6 May 2021 15:57:23 +0000 Received: from OS3PR01MB5573.jpnprd01.prod.outlook.com (2a01:111:e400:7ebd::4d) by SG2APC01FT028.mail.protection.outlook.com (2a01:111:e400:7ebd::196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.25 via Frontend Transport; Thu, 6 May 2021 15:57:22 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:AB23AEE79D307D084CF51E7F98A95AC4FA2C0E52B0DDF0BFF54A3D8DDEDE21F9; UpperCasedChecksum:3EF2D513070DFC18BB347C5D685C12A1101DF310393B936CA4C4849B5FE46DB0; SizeAsReceived:8509; Count:45 Received: from OS3PR01MB5573.jpnprd01.prod.outlook.com ([fe80::1833:e96b:dd3c:e5f2]) by OS3PR01MB5573.jpnprd01.prod.outlook.com ([fe80::1833:e96b:dd3c:e5f2%7]) with mapi id 15.20.4108.027; Thu, 6 May 2021 15:57:22 +0000 From: "Shiwang.Xie" To: ffmpeg-devel@ffmpeg.org Date: Thu, 6 May 2021 23:57:51 +0800 Message-ID: X-Mailer: git-send-email 2.24.3 (Apple Git-128) X-TMN: [1JfBusaXjNYCvJYIGBu34/obXSbbewDu] X-ClientProxiedBy: CH2PR10CA0014.namprd10.prod.outlook.com (2603:10b6:610:4c::24) To OS3PR01MB5573.jpnprd01.prod.outlook.com (2603:1096:604:c3::9) X-Microsoft-Original-Message-ID: <20210506155751.83747-1-shiwang.xie666@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (118.143.228.3) by CH2PR10CA0014.namprd10.prod.outlook.com (2603:10b6:610:4c::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.25 via Frontend Transport; Thu, 6 May 2021 15:57:19 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 45 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 20634c2b-71b7-4895-8b31-08d910a7a1b7 X-MS-Exchange-SLBlob-MailProps: +LiGfBxqLEvvCiDePhy3w3xQF9lO3iPJVuboyY0Nd0sb8abvfnWrl07PsDW/iW2rcAhvoveCvM9Vu/1F1XWECNRFXFYn58MZkgtk026Sly4o/3BVJ4TuHji60klvFBmJ5BeMzS0/pWEcAub1RD10SLoC5hShd0d5juYUSzRfLOukTF2lLVz03Gkfn1xiZPOMIwMta2ffj9l3xNQP3ZDCmW0Sxb6gtLgzsOr6N9jMrEm6BOOHjF/BGMTUdStD/eiRLVTcWHWxCGipIzYxKOVfYY3S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A3HvFhSM/cLfIDfROyZ4uqYPq+ZI4o8K8pbjHbQuEMMJQ7Q7xsd9w83FfwrnCgUO4nGl9DYDBwm5gV7+Oki/icO4pfHUAX9tpisQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 20634c2b-71b7-4895-8b31-08d910a7a1b7 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 May 2021 15:57:22.0874 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: SG2APC01FT028.eop-APC01.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: HK0PR01MB2914 Subject: [FFmpeg-devel] [PATCH] fftools/ffmpeg: fix -t inaccurate recording time 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 Cc: "Shiwang.Xie" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 6XVi7DhyFmEI if input start time is not 0 -t is inaccurate doing stream copy, will record extra duration according to input start time. it should base on following cases: input video start time from 60s, duration is 300s, 1. stream copy: ffmpeg -ss 40 -t 60 -i in.mp4 -c copy -y out.mp4 open_input_file() will seek to 100 and set ts_offset to -100, process_input() will offset pkt->pts with ts_offset to make it 0, so when do_streamcopy() with -t, exits when ist->pts >= recording_time. 2. stream copy with -copyts: ffmpeg -ss 40 -t 60 -copyts -i in.mp4 -c copy -y out.mp4 open_input_file() will seek to 100 and set ts_offset to 0, process_input() will keep raw pkt->pts as ts_offset is 0, so when do_streamcopy() with -t, exits when ist->pts >= (recording_time+f->start_time+f->ctx->start_time). 3. stream copy with -copyts -start_at_zero: ffmpeg -ss 40 -t 60 -copyts -start_at_zero -i in.mp4 -c copy -y out.mp4 open_input_file() will seek to 120 and set ts_offset to -60 as start_to_zero option, process_input() will offset pkt->pts with input file start time, so when do_streamcopy() with -t, exits when ist->pts >= (recording_time+f->start_time). 0 60 40 60 360 |_______|_____|_______|_______________________| start -ss -t This fixes ticket #9141. Signed-off-by: Shiwang.Xie --- fftools/ffmpeg.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 3ad11452da..fac9f67462 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -2082,9 +2082,11 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p } if (f->recording_time != INT64_MAX) { - start_time = f->ctx->start_time; - if (f->start_time != AV_NOPTS_VALUE && copy_ts) - start_time += f->start_time; + start_time = 0; + if (copy_ts) { + start_time += f->start_time != AV_NOPTS_VALUE ? f->start_time : 0; + start_time += start_at_zero ? 0 : f->ctx->start_time; + } if (ist->pts >= f->recording_time + start_time) { close_output_stream(ost); return;