From patchwork Wed Oct 21 13:40:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 23132 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 49BFB44A460 for ; Wed, 21 Oct 2020 17:03:13 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 27B9468B205; Wed, 21 Oct 2020 17:03:13 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-oi1-f195.google.com (mail-oi1-f195.google.com [209.85.167.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DFD9668AC85 for ; Wed, 21 Oct 2020 17:03:06 +0300 (EEST) Received: by mail-oi1-f195.google.com with SMTP id 16so2159246oix.9 for ; Wed, 21 Oct 2020 07:03:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=4bVa9QOaRyBxLN9h3xbGRCs/hoIvFrHKDCR2gK5OsY4=; b=WQi85Fz+PXRtp4gCbZeM61pw6iIQiLuOiZsNGdRca7jWaMkB5G11Hc2lIYByRe3xNH GlWl5HqQawH1Yrmmht4jK/gJPDneA1+ge9j6VtHasXyCDyjGGE2bksc+HWUdwDnu1jmB E1qTjT1vKGQfOgg+wkzYvpla64U830Zk7M0tkUbjYT/y9E6AlFtm7MkDc8gCK7PesRUC 0i1FdWWFc84/KodjyXmpNhMpu8V6Rx7ExqWNfZbGFmc7SAB9+BoWw09NoVRMBZzd0zD9 HS1SJC+YrnNSl8bs4lr27Ker86M3EA4xiirTg1pTAa1+8n3ZVgMg8lWnoVJY5xppYEjf ZFtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=4bVa9QOaRyBxLN9h3xbGRCs/hoIvFrHKDCR2gK5OsY4=; b=tKVLS/D0LZcYj8hH088srdUf94HFUxhfLJt7hNoXI7lB8ksFPHZfLkZrLPwFGEsG8w +3d44DzikLX/WJVDHbTevuABlfiSwiC1wc3YKynEeE0x8Y+GQ5qnG+YZ+zUDrC9vzGGU IbNyz+xqpfwWDqZ6YSafnny6cOK729SOAMEpSfjfRTY9FhX2+cwvo/Z+nD/+ZTz1QBjH 0hNRB2EaOIcI0Y179F4vJvk58zDyFAiaKK/XTbnykVoT9MYs/aKU7KY3/QZQa/RO9M1J gshmBhPf5HIRKdJFlYsarfZgpMwmr2NWIMI2DINJqQZTIpF3YvN3b9h4Cw3NCke4k4AD OvuA== X-Gm-Message-State: AOAM531upEbmOetW3XWM6G77d+rT6jMud6cnK3ZvdfSUI0P1B9nLLONA aA4AVVtLxXgk+J+06Nc0uihSGAtY99w= X-Google-Smtp-Source: ABdhPJz1JkOPe6TuYf5ZzNkjAzlEOv7SU+R08//2p+11GfEc9GvCLu10HLmJJLtk/RMaCKlgs8JqBA== X-Received: by 2002:a17:90a:e545:: with SMTP id ei5mr3437966pjb.60.1603287621623; Wed, 21 Oct 2020 06:40:21 -0700 (PDT) Received: from vpn2.localdomain ([161.117.202.209]) by smtp.gmail.com with ESMTPSA id o15sm2624718pfd.16.2020.10.21.06.40.19 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Oct 2020 06:40:20 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Wed, 21 Oct 2020 21:40:12 +0800 Message-Id: <1603287614-11545-1-git-send-email-lance.lmwang@gmail.com> X-Mailer: git-send-email 1.8.3.1 Subject: [FFmpeg-devel] [PATCH 1/3] avformat/mpegtsenc: use total_size instead of avio_tell() X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: Limin Wang MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Limin Wang avio_tell() failed to get corrected data size in some condition. Please test with below command: $ ./ffmpeg -f lavfi -i testsrc=duration=100:size=vga -c:v libx264 -x264opts \ nal-hrd=cbr:force-cfr=1 -b:v 500k -minrate 500k -maxrate 500k -bufsize 500k \ -f hls -hls_time 10 -hls_ts_options "muxrate=2000000" test%d.ts $ du -h test*.ts Before: 2.4M test00.ts 4.8M test11.ts 7.2M test22.ts 9.6M test33.ts 12M test44.ts 15M test55.ts 17M test66.ts 20M test77.ts 22M test88.ts 24M test99.ts After apply the patch: 2.4M test00.ts 2.4M test11.ts 2.4M test22.ts 2.4M test33.ts 2.4M test44.ts 2.4M test55.ts 2.4M test66.ts 2.4M test77.ts 2.4M test88.ts 2.4M test99.ts 4.0K test%d.ts Signed-off-by: Limin Wang --- libavformat/mpegtsenc.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c index afdadda..e05d0ce 100644 --- a/libavformat/mpegtsenc.c +++ b/libavformat/mpegtsenc.c @@ -84,6 +84,7 @@ typedef struct MpegTSWrite { int64_t next_pcr; int mux_rate; ///< set to 1 when VBR int pes_payload_size; + int64_t total_size; int transport_stream_id; int original_network_id; @@ -830,9 +831,9 @@ invalid: return 0; } -static int64_t get_pcr(const MpegTSWrite *ts, AVIOContext *pb) +static int64_t get_pcr(const MpegTSWrite *ts) { - return av_rescale(avio_tell(pb) + 11, 8 * PCR_TIME_BASE, ts->mux_rate) + + return av_rescale(ts->total_size + 11, 8 * PCR_TIME_BASE, ts->mux_rate) + ts->first_pcr; } @@ -840,13 +841,15 @@ static void write_packet(AVFormatContext *s, const uint8_t *packet) { MpegTSWrite *ts = s->priv_data; if (ts->m2ts_mode) { - int64_t pcr = get_pcr(s->priv_data, s->pb); + int64_t pcr = get_pcr(s->priv_data); uint32_t tp_extra_header = pcr % 0x3fffffff; tp_extra_header = AV_RB32(&tp_extra_header); avio_write(s->pb, (unsigned char *) &tp_extra_header, sizeof(tp_extra_header)); + ts->total_size += sizeof(tp_extra_header); } avio_write(s->pb, packet, TS_PACKET_SIZE); + ts->total_size += TS_PACKET_SIZE; } static void section_write_packet(MpegTSSection *s, const uint8_t *packet) @@ -987,6 +990,7 @@ static int mpegts_init(AVFormatContext *s) } } + ts->total_size = 0; if (s->max_delay < 0) /* Not set by the caller */ s->max_delay = 0; @@ -1228,7 +1232,7 @@ static void mpegts_insert_pcr_only(AVFormatContext *s, AVStream *st) } /* PCR coded into 6 bytes */ - q += write_pcr_bits(q, get_pcr(ts, s->pb)); + q += write_pcr_bits(q, get_pcr(ts)); /* stuffing bytes */ memset(q, 0xFF, TS_PACKET_SIZE - (q - buf)); @@ -1315,7 +1319,7 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, while (payload_size > 0) { int64_t pcr = AV_NOPTS_VALUE; if (ts->mux_rate > 1) - pcr = get_pcr(ts, s->pb); + pcr = get_pcr(ts); else if (dts != AV_NOPTS_VALUE) pcr = (dts - delay) * 300; @@ -1326,7 +1330,7 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, write_pcr = 0; if (ts->mux_rate > 1) { /* Send PCR packets for all PCR streams if needed */ - pcr = get_pcr(ts, s->pb); + pcr = get_pcr(ts); if (pcr >= ts->next_pcr) { int64_t next_pcr = INT64_MAX; for (int i = 0; i < s->nb_streams; i++) { @@ -1340,7 +1344,7 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, ts_st2->last_pcr = FFMAX(pcr - ts_st2->pcr_period, ts_st2->last_pcr + ts_st2->pcr_period); if (st2 != st) { mpegts_insert_pcr_only(s, st2); - pcr = get_pcr(ts, s->pb); + pcr = get_pcr(ts); } else { write_pcr = 1; } @@ -1983,7 +1987,7 @@ static void mpegts_write_flush(AVFormatContext *s) } if (ts->m2ts_mode) { - int packets = (avio_tell(s->pb) / (TS_PACKET_SIZE + 4)) % 32; + int packets = (ts->total_size / (TS_PACKET_SIZE + 4)) % 32; while (packets++ < 32) mpegts_insert_null_packet(s); } From patchwork Wed Oct 21 13:40:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 23131 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id E47FA44AD36 for ; Wed, 21 Oct 2020 16:48:02 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BB78268B1A8; Wed, 21 Oct 2020 16:48:02 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-oi1-f194.google.com (mail-oi1-f194.google.com [209.85.167.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 13FF1688257 for ; Wed, 21 Oct 2020 16:47:56 +0300 (EEST) Received: by mail-oi1-f194.google.com with SMTP id j7so2086322oie.12 for ; Wed, 21 Oct 2020 06:47:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=yUjIwtxUpBknVYDFN7rTHOMZFmb2NQIH6+T8s09EorE=; b=cyAO5wnZLE0Vpnc87wYBoIhAIERIJOolsPtbmbvMjDTND82bNypyW/RJEQDim5EGPy tngAWXKszUKF/MaQmQ8oIRUWRh+c2h0KbSWm97daOxCHz4gUenVjT4aXW5PPvELfVzLL hEes1awLEjXKy5bDmMQLbDxX2/D6bPeWr51ElE34BH4TqAT1/WqaAmONCCjsS6xJG27y qpfCE0wQKGiOzshLih6hPd2ViObbWic/AMBHlpCPbZJTZbH6WkKEc6gtS7e2N1RaFryW g97NqLMfZR3tJjUXYoJJ1DvL1PsBMrIQ8EeopFm47FVt3Af64DarTg7tznQamN2o0Uv1 LYWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=yUjIwtxUpBknVYDFN7rTHOMZFmb2NQIH6+T8s09EorE=; b=IhGTHk3k8a5QV5YhpjoDa9iKwIvtbPOFmlPmDo1mk/nGcLBHgdPfv/iGGCFFCmTWGB hNNobgwaWv39PsayeXLvAw8niPJV3NsCaIeVZVew89ko+yRjCnRgoNuWa+82nfXWjkC7 UbLkzpsW/vOWKmlHowWZZN/rMAgRfzLDh73l1rDfifgcQPL3TaH8hG7RUsKubka7t0FI dwGNDFnV3cD+Hf66BA2ccyubK59ytAPNzUad/qQnxQthP1NrU12NEHruRsnwCgraXsa0 OIleikIHJFV6xlL8vN68zyZduWsiHquY23RiG4sXl+zspTqRted4kXWCnIPVPR6p995A FzXg== X-Gm-Message-State: AOAM5318++HsoJD78APbj2grlnru4oMgnxczmn2JDB26hiGJbH/9Ziw/ SlgJypjk1r/cLQ8TitNOGDma84Z06oY= X-Google-Smtp-Source: ABdhPJw8Nrlifw6OdfFv4ozHK+Wy9g17j7BxO9L0P8jw5eFlTqGm7QBh35hlOjPu8IZg9GeARNNH1Q== X-Received: by 2002:a17:90a:148:: with SMTP id z8mr3550675pje.173.1603287623238; Wed, 21 Oct 2020 06:40:23 -0700 (PDT) Received: from vpn2.localdomain ([161.117.202.209]) by smtp.gmail.com with ESMTPSA id o15sm2624718pfd.16.2020.10.21.06.40.21 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Oct 2020 06:40:22 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Wed, 21 Oct 2020 21:40:13 +0800 Message-Id: <1603287614-11545-2-git-send-email-lance.lmwang@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1603287614-11545-1-git-send-email-lance.lmwang@gmail.com> References: <1603287614-11545-1-git-send-email-lance.lmwang@gmail.com> Subject: [FFmpeg-devel] [PATCH 2/3] avformat/mpegtsenc: make first_pcr sync with the first valid dts X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: Limin Wang MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Limin Wang now first_pts assume dts will start from zero, if it's not true(copyts is enable), too many null packet will be inserted for cbr output. Please test with below command, you'll get huge test.ts without the patch: ./ffmpeg -y -copyts -i ../fate-suite/mpegts/loewe.ts -c:v libx264 -x264opts \ nal-hrd=cbr:force-cfr=1 -b:v 3500k -minrate 3500k -maxrate 3500k -bufsize \ 1000k -c:a mp2 -muxrate 4500k -vframes 1000 test.ts Signed-off-by: Limin Wang --- libavformat/mpegtsenc.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c index e05d0ce..baea3b4 100644 --- a/libavformat/mpegtsenc.c +++ b/libavformat/mpegtsenc.c @@ -81,6 +81,7 @@ typedef struct MpegTSWrite { int64_t pat_period; /* PAT/PMT period in PCR time base */ int nb_services; int64_t first_pcr; + int first_dts_check; int64_t next_pcr; int mux_rate; ///< set to 1 when VBR int pes_payload_size; @@ -1136,6 +1137,7 @@ static int mpegts_init(AVFormatContext *s) if (ts->copyts < 1) ts->first_pcr = av_rescale(s->max_delay, PCR_TIME_BASE, AV_TIME_BASE); + ts->first_dts_check = 1; select_pcr_streams(s); @@ -1690,6 +1692,11 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt) stream_id = side_data[0]; if (ts->copyts < 1) { + if (ts->first_dts_check && dts != AV_NOPTS_VALUE) { + ts->first_pcr += dts * 300; + } + ts->first_dts_check = 0; + if (pts != AV_NOPTS_VALUE) pts += delay; if (dts != AV_NOPTS_VALUE) From patchwork Wed Oct 21 13:40:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 23133 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 6867D44A1EE for ; Wed, 21 Oct 2020 17:49:22 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5245768AF73; Wed, 21 Oct 2020 17:49:22 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4DD5568A0C3 for ; Wed, 21 Oct 2020 17:49:15 +0300 (EEST) Received: by mail-pf1-f195.google.com with SMTP id e10so1629972pfj.1 for ; Wed, 21 Oct 2020 07:49:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=lcreQwH3tH1TZzM/Wb858Ec12xuS/UrnDT8CW7ZJi8Y=; b=W5bc8B1gamYKa33sbmOsH4n1xw5juq9kyuvvX2bRU9VBXUkaxTG+1wVHYVlGMCsrzd anbt26ACEQjccy6HBTgdKvoyfHvhXkIK/3352/VYxm8drVfigfqXwveys/1hNAPUTBfa 48CaBR75KQl+WbFOIOl05WPkYu2n7JM6zYuXAGT/uQT8clSFsi6tE87L7mYU6qWlvuny kFhmWSIm1rbX6Qh6O/tug0jUyb174wPbp/4eLFKHbn7p15qyMMMo+0OqZw4KeCoEglDF MIcmvYbvzZLa438D3pm24ohgCTBt89ERtpaBeqrjNmPdp/ZKkp5FEGu1KMEXBP+OWePZ B0gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=lcreQwH3tH1TZzM/Wb858Ec12xuS/UrnDT8CW7ZJi8Y=; b=bUwSWwVga7Cx3fcBzsJty5JmQmcoYXtI7DpFdwI3uZBDKWsezJ/Lpp9m5q6A/PGSUN MMJ9rd/sxoZ00Bba8DxrfhYJZeUfSlGleQWgE7FTIitKCLnQIP4Cs8/I74VdedlLSZA/ CzKcDq68LbZ/EreNpCBe/AJp07gyxJQ5CQyhOsCEGXIrPx0vVdBPImO4/kQGMQQVWM79 ZzA8FbYtiu5dcbcicjy5kj8JqOW/b4y9nKMieVioYvQDzqCxXsn3Jr4X2PDer1SXsseG uK3daItKWuGjKRxA5HV/+E4ElV74fnwgtWO2yTA5hKtt8fyzV5wUlsU6qFqsbHF4Rz12 pLQA== X-Gm-Message-State: AOAM530VFCrUEdqBIj/5E/nNNmHMQP24mbdN0/h64tMFlkPoH6fkYR5r wsHqaC6HOIOb+K/46sqoif9U+NBEi0o= X-Google-Smtp-Source: ABdhPJwNRQBo6GxIbC9iLuMG9jZ4TW0Iwcd+QksAazg27ZiGTUtmf1TWXp8SqEH3ePfjeTLkYQO8iQ== X-Received: by 2002:a63:654:: with SMTP id 81mr3342205pgg.27.1603287624919; Wed, 21 Oct 2020 06:40:24 -0700 (PDT) Received: from vpn2.localdomain ([161.117.202.209]) by smtp.gmail.com with ESMTPSA id o15sm2624718pfd.16.2020.10.21.06.40.23 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Oct 2020 06:40:24 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Wed, 21 Oct 2020 21:40:14 +0800 Message-Id: <1603287614-11545-3-git-send-email-lance.lmwang@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1603287614-11545-1-git-send-email-lance.lmwang@gmail.com> References: <1603287614-11545-1-git-send-email-lance.lmwang@gmail.com> Subject: [FFmpeg-devel] [PATCH 3/3] fftools/ffmpeg: fix the wrong bitrate and speed stats X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: Limin Wang MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Limin Wang The bitrate and speed stats are wrong If the copyts is enabled. Please test with below command: wget http://samples.mplayerhq.hu/MPEG2/foxksaz.ts ./ffmpeg -y -copyts -i ./foxksaz.ts -c:v libx264 -x264opts \ nal-hrd=cbr:force-cfr=1 -b:v 3500k -minrate 3500k -maxrate 3500k -bufsize \ 1000k -c:a mp2 -muxrate 4500k -vframes 1000 test.ts before: frame= 1000 fps=112 q=-1.0 Lsize= 9063kB time=09:10:12.41 bitrate= 2.2kbits/s speed=3.7e+03x after: frame= 1000 fps=112 q=-1.0 Lsize= 9062kB time=00:00:15.78 bitrate=4703.4kbits/s speed=1.77x Signed-off-by: Limin Wang --- fftools/ffmpeg.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index cb7644d..6a5bf7d 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -344,6 +344,7 @@ static volatile int received_nb_signals = 0; static atomic_int transcode_init_done = ATOMIC_VAR_INIT(0); static volatile int ffmpeg_exited = 0; static int main_return_code = 0; +static int64_t copy_ts_first_pts = AV_NOPTS_VALUE; static void sigterm_handler(int sig) @@ -1753,9 +1754,17 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti vid = 1; } /* compute min output value */ - if (av_stream_get_end_pts(ost->st) != AV_NOPTS_VALUE) + if (av_stream_get_end_pts(ost->st) != AV_NOPTS_VALUE) { pts = FFMAX(pts, av_rescale_q(av_stream_get_end_pts(ost->st), ost->st->time_base, AV_TIME_BASE_Q)); + if (copy_ts) { + if (copy_ts_first_pts == AV_NOPTS_VALUE && pts > 1) + copy_ts_first_pts = pts; + if (copy_ts_first_pts != AV_NOPTS_VALUE) + pts -= copy_ts_first_pts; + } + } + if (is_last_report) nb_frames_drop += ost->last_dropped; }