From patchwork Thu May 2 18:45:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Panagiotis Malakoudis X-Patchwork-Id: 12971 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 7B4FC44903E for ; Thu, 2 May 2019 21:52:37 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 58BDE68ABC7; Thu, 2 May 2019 21:52:37 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-it1-f194.google.com (mail-it1-f194.google.com [209.85.166.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9548068A405 for ; Thu, 2 May 2019 21:52:30 +0300 (EEST) Received: by mail-it1-f194.google.com with SMTP id s3so5235812itk.1 for ; Thu, 02 May 2019 11:52:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=YVvSM9w4ikzNgfF+ziHFC19Upkn0KGjVc6r8yadirB0=; b=JdhQqfMSfDgRZNG5HOjCPtcKieRaZOEWyiVZu7PiDKBusVNYunl9ADcLshPt4NFXvO YFbgKDz77UMrv0y9M31WMjrLezzdWiOscHUKx8IGn9r5TQuisVPXBl0LQrUvKomx4h16 YtBITvmFVMlKGmpvDtJajQBsAX28EheeutsFVL/tsJ6Xdsn8fDrj4NupBJYe8iND+9BO Y4Og+54dWhOrDRPaOdio+cYkX09zXMGQNbNPwCCd/0kZHEwruFNDGWAg7TrCwOTwANkl 3WsKcxQqJvQcqV64KfMxKync/C3veQBvzScaze0k8vX24BaMLuDuxxX2xU935cq8z7VX 7HGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=YVvSM9w4ikzNgfF+ziHFC19Upkn0KGjVc6r8yadirB0=; b=D1+qLVxvupSQgSQDEAvY1n/6i4K0h6dCbIoslcLnJEPaR9vHprAaqW6KxGzC4R5x5P POGGJDrjkCT5uN/8xb7OpB1ROikXLDXMOoLNC4VsPMiGH5tYU1W+xB5kwYToqwtlB9Ij qbONQfehd25YMtXvac5vxrcZiWsAD691ELB3JqrUITu+M24Ax6G0PvxnU7zC/HZzB6WM aD9gVfrCpyMLr5YYqyGiqDpygjYaM1z9cLpALgeWZCqhJvSKx3yUX7yKIAtqL0CFzeBl 8zZ9e7H9ItGDX3lgrekf18l8g1DJ2R9EKgzxOJfGEZ6pBIKmbnIw3K27D38vTzYWJT/B jjlQ== X-Gm-Message-State: APjAAAXD9TyPn5HdVyFIPGsxEdpcq9aP2IBmxnqxesQGcO5inHP5TqBa VQ5qLIcRag5kGROZzLfz7TzKgF8c9KrQst2X9rFrDSr8 X-Google-Smtp-Source: APXvYqzxNv8RkcX7+wWbRfjciHxFhmEYXuS/XKk+2rYtajrrPWhZgC8FRZjFagzvaaZtJo6B7ujqrnTutSBeGn8JYhk= X-Received: by 2002:a02:c504:: with SMTP id s4mr3812383jam.75.1556822744680; Thu, 02 May 2019 11:45:44 -0700 (PDT) MIME-Version: 1.0 References: <20190502173330.GC3501@michaelspb> In-Reply-To: <20190502173330.GC3501@michaelspb> From: Panagiotis Malakoudis Date: Thu, 2 May 2019 21:45:33 +0300 Message-ID: To: FFmpeg development discussions and patches Subject: Re: [FFmpeg-devel] Using copyts with mpegts output fails after 26, 5 hours 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" > On Thu, May 02, 2019 at 08:13:10PM +0300, Panagiotis Malakoudis wrote: > > When outputing to mpegts format, using -copyts option makes program > > fail after the oveflow of mpegts PCR happens at around 26 hours and 30 > > minutes. When not using -copyts, only a warning is reported. > > In order to reproduce the issue, you first have to create a 27 hour > > mpegts video. > > I have described the problem in thorough at ticket > > https://trac.ffmpeg.org/ticket/7876 > > > > The issue is resolved if you use a patch created originally by Arut > > (Roman Arutyunyan) at > > https://github.com/arut/ffmpeg-patches/blob/master/mpegts-33bit > > > > I have converted the patch in order to apply with current git and > > confirmed working fine, fixing the above mentioned issue. Original > > author describes the patch as: "Implements smooth 33-bit mpeg-ts > > timestamp overflow in mpegts muxer." > > > > Here it is: > > --- libavformat/mpegts.c 2019-04-30 16:11:49.000000000 +0300 > > +++ libavformat/mpegts.c 2019-04-30 18:55:12.736428766 +0300 > > doesnt apply with git am > Applying: Using copyts with mpegts output fails after 26, 5 hours > error: mpegts.c: does not exist in index > Patch failed at 0001 Using copyts with mpegts output fails after 26, 5 hours > Sorry, it was a simple diff, not a git am compatible diff. Hope I made it correctly this time: From 5273daaf8e568fc2a2b9a77d91cb8a834b9e14e7 Mon Sep 17 00:00:00 2001 From: Panagiotis Malakoudis Date: Thu, 2 May 2019 21:34:44 +0300 Subject: [PATCH] Implement smooth 33bit mpegts timestamp overflow in mpegts muxer --- libavformat/mpegts.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) uint8_t *sd; @@ -1005,8 +1028,8 @@ static int new_pes_packet(PESContext *pes, AVPacket *pkt) pkt->stream_index = pes->sub_st->index; else pkt->stream_index = pes->st->index; - pkt->pts = pes->pts; - pkt->dts = pes->dts; + pkt->pts = unroll_timestamp(pes->ts, pes->pts); + pkt->dts = unroll_timestamp(pes->ts, pes->dts); /* store position of first TS packet of this PES packet */ pkt->pos = pes->ts_packet_pos; pkt->flags = pes->flags; diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index 8a84e5cc19..b7f5d8ea4e 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -163,6 +163,9 @@ struct MpegTSContext { /** structure to keep track of Program->pids mapping */ unsigned int nb_prg; struct Program *prg; + + /** base timestamp for smooth rolling over 33bits */ + int64_t base_ts; int8_t crc_validity[NB_PID_MAX]; /** filters for various streams specified by PMT + for the PAT and PMT */ @@ -982,6 +985,26 @@ static void new_data_packet(const uint8_t *buffer, int len, AVPacket *pkt) pkt->size = len; } +static int64_t unroll_timestamp(MpegTSContext *ts, int64_t t) +{ + int64_t dt; + + if (t == AV_NOPTS_VALUE) + return t; + + if (!ts->base_ts) + ts->base_ts = t; + + dt = (t - ts->base_ts) & 0x01ffffffffll; + if (dt & 0x0100000000ll) { + dt |= 0xffffffff00000000ll; + } + + ts->base_ts += dt; + + return ts->base_ts; +} + static int new_pes_packet(PESContext *pes, AVPacket *pkt) {