From patchwork Tue May 14 21:54:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andriy Gelman X-Patchwork-Id: 13116 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 2F0254495DD for ; Wed, 15 May 2019 01:00:03 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0D8D8689B96; Wed, 15 May 2019 01:00:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f195.google.com (mail-qt1-f195.google.com [209.85.160.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1A6F5689A5E for ; Wed, 15 May 2019 00:59:56 +0300 (EEST) Received: by mail-qt1-f195.google.com with SMTP id o7so968565qtp.4 for ; Tue, 14 May 2019 14:59:56 -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:mime-version :content-transfer-encoding; bh=qolnAmQC6M9zzoHwxcvaKDqYHH1qgZ+WymWv1UGl5/g=; b=S2D9aXLIsqCgjsNBRqj/+th3/uGWAPyoL0eBqIH09KHeEx8cDZgiGLE6TmD6L8+xsr rv4YxeBneY7dJlKmWxLDmEfIbXCdBDJ0RLNH1YwuWpm0qnwH20xiRODTSJaAmo9hJObu nbDGWvQPCfJmW26Zkifjxhb1/rOfd97tcGFPPNSqm+TSF53JFmVXY5I2aj5aFTZDQJtI itOdqT1MIdDcNnPEeYcVwYD68ha3TayV2ydcrx1yl5Zu21uqxms4URq07gJQL/Kbjak1 CEEBxK/9H9N2TRguogzB5wBv3RVTAyjhZHOWxOCUv3BSJ/o/wjw3O79tH6pl5aRQ8Np2 C6Cg== 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:mime-version :content-transfer-encoding; bh=qolnAmQC6M9zzoHwxcvaKDqYHH1qgZ+WymWv1UGl5/g=; b=LFnlbFos3SEVQGm+A5pRPkSeum4gR1WxKMpmJLaOePk1hfwhQ+7zj1vRt5oMET9KE4 F5oUiTB6PZbTAI+MTErmMamwsV3R0gkI8ZGm2D6T5ByeFFiMAjqtTZB45oz9Lw8pT3EO rqzxyiehEntISnuO2EkBYKRpG/Jv6GZUHoBAsFrUAuGF5KPvyzqv6+FgIVJ1Eg1ro8iS +qpYOUaJNyIoi/5xPqeqMQCDa8l7/La4efJ5hQcdMlQK3SS4YA52yVNGM/VM+OUtF96D VtAJe+MGnKSofWYfoMBT7R8EUQKyKN7bvEYWVmoSwWWh/jq+d4B7l7yJ1Qni2smvkkrz +HEQ== X-Gm-Message-State: APjAAAWve0s/5cw8ZmGjIEI0wRbien1qmFCjab+BQ4nuOy1pVTwbr6KK Uqz0jwSD8fHRyX6k6lvYb8MMdcBH X-Google-Smtp-Source: APXvYqye/Cgwr5O5YYUpNLWlA7I8DPLUohS8SG5g0NGLkJc5HHbmPwbvu1a7IqeCuuIKeAV6pg0hWg== X-Received: by 2002:ac8:4746:: with SMTP id k6mr8860729qtp.249.1557870857784; Tue, 14 May 2019 14:54:17 -0700 (PDT) Received: from localhost.localdomain (ip-108-114-227-166.spfdma.spcsdns.net. [108.114.227.166]) by smtp.gmail.com with ESMTPSA id d5sm81761qtj.92.2019.05.14.14.54.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 14:54:17 -0700 (PDT) From: Andriy Gelman X-Google-Original-From: Andriy Gelman To: ffmpeg-devel@ffmpeg.org Date: Tue, 14 May 2019 17:54:21 -0400 Message-Id: <20190514215422.11996-1-andriy.gelman@gmail.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 1/2] libavformat/utils: Interpolate missing timestamps in H264 and HEVC when no b-frames observed 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: Andriy Gelman Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Andriy Gelman Fixes Ticket #7895. Currently, timestamp interpolation is disabled by default in H264 and HEVC. This creates playback issues when the demuxer does not output a valid timestamp. This patch allows interpolation when no b-frames have been observed during decoding, which fixes playback issues for some missing timestamp cases. --- libavformat/utils.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libavformat/utils.c b/libavformat/utils.c index a63d71b0f4..3dd0bf0d66 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -1233,7 +1233,9 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, int64_t offset; AVRational duration; int onein_oneout = st->codecpar->codec_id != AV_CODEC_ID_H264 && - st->codecpar->codec_id != AV_CODEC_ID_HEVC; + st->codecpar->codec_id != AV_CODEC_ID_HEVC || + (!st->internal->avctx->max_b_frames && + st->cur_dts != RELATIVE_TS_BASE); /*skip when no timing info from demuxer */ if (s->flags & AVFMT_FLAG_NOFILLIN) return; @@ -1272,6 +1274,10 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, delay = st->internal->avctx->has_b_frames; presentation_delayed = 0; + /*update max_b_frames if delay is larger */ + if (delay > st->internal->avctx->max_b_frames) + st->internal->avctx->max_b_frames = delay; + /* XXX: need has_b_frame, but cannot get it if the codec is * not initialized */ if (delay && @@ -1337,7 +1343,8 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, presentation_delayed, av_ts2str(pkt->pts), av_ts2str(pkt->dts), av_ts2str(st->cur_dts), pkt->stream_index, pc, pkt->duration, delay, onein_oneout); - /* Interpolate PTS and DTS if they are not present. We skip H264 + /* Interpolate PTS and DTS if they are not present. H264/HEVC timestamps are + * interpolated only if no b-frames have been observed. Otherwise, we skip H264/HEVC * currently because delay and has_b_frames are not reliably set. */ if ((delay == 0 || (delay == 1 && pc)) && onein_oneout) {