From patchwork Thu May 2 17:13:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Panagiotis Malakoudis X-Patchwork-Id: 12967 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 BD6AF4462BF for ; Thu, 2 May 2019 20:13:29 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 981D668AB8A; Thu, 2 May 2019 20:13:29 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-io1-f44.google.com (mail-io1-f44.google.com [209.85.166.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E274768A302 for ; Thu, 2 May 2019 20:13:22 +0300 (EEST) Received: by mail-io1-f44.google.com with SMTP id m9so2847217iok.7 for ; Thu, 02 May 2019 10:13:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=gC9RYcHhWOrx6qWfwiWMj/4pekm9WOK7CoWvoSLvWr4=; b=n8wXkznuW1fdOh2K8kIO8aTpMZ85051dxY+fb8sv0EW+rSZAgfDCClYn45tgTNPXL7 zNYXgIi+acZC2TYUVbP2L9v68cVF3aYL6CHzb2WnOO0AE+jqd12kU05jNg10SDm3uA6d mWsgjvS/+/1yWFCuEy0voYxPsIpaMomarXuwIKYQeO0qk5yJl5vBi8kOhyiTyuK1Fgic 68xZYbeDqv0+CywNLg0Sos+HvMVMSKCKfuIPjMiUV2vsPJ2sisq3Ea/boF1NeWVRPuRc i45Wzz/tfM0i+IiuqJjVmKTC5pzLmdremjEX2DvfOzpCSJAVUwkgf8Kk1id8JMxqvDSM qzZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=gC9RYcHhWOrx6qWfwiWMj/4pekm9WOK7CoWvoSLvWr4=; b=miz4vFFNUSdQzKkuZrnq9StrMm6fvm4wh8Z4LjBID/3LiBXFQISC59YGkYHYpoYbRY 75uJzzRF+JV3lq88gvrqtdOSjABMzG5FLQwoNUgf1V9m8RmtoUjsTMG02e+Xo7q6V2Jy bN9ttixDiMHsD4wh2TiTqzX1SnKisjtkIQroo0/N2Yc+FnHsmO/CY1udog9/EdtQe90M R/whHFwL8C+JlNRFHajUzEuMCSEFmxgr7C+EURM9YhtBUI4npO81S3/kMFiFyw1Qzzmz Xbcsg/A2ssXdLNDLgHCmeKOEfZQPTqoX5E3tHMFvl09LFcnnd4FFuBydLVj54u69A60V DD0A== X-Gm-Message-State: APjAAAUB8Qh4pXDVd0HKU9mH0WbbsSR20GByhyJtWLkd7rDF8nYs+/uG diQK3z6SJTBexLk/DIl6Bk1mmdjLRZt/AZjjHNhQ2ofC X-Google-Smtp-Source: APXvYqxnjNs601ll9itEP/9PH0pfeUmOpaTcYzfJ266KABpNdxTvdwKwRDNNTaHyeR9ksEBFrC/zA6rxoMuiw9EVjQ8= X-Received: by 2002:a6b:7d46:: with SMTP id d6mr3269054ioq.222.1556817201003; Thu, 02 May 2019 10:13:21 -0700 (PDT) MIME-Version: 1.0 From: Panagiotis Malakoudis Date: Thu, 2 May 2019 20:13:10 +0300 Message-ID: To: ffmpeg-devel@ffmpeg.org Subject: [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" 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 @@ -163,6 +163,9 @@ /** 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 @@ 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) { uint8_t *sd; @@ -1005,8 +1028,8 @@ 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;