From patchwork Sun May 12 03:20:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andriy Gelman X-Patchwork-Id: 13080 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 A85E5446FC1 for ; Sun, 12 May 2019 06:21:04 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8656F689B51; Sun, 12 May 2019 06:21:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f193.google.com (mail-qt1-f193.google.com [209.85.160.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 36F0A688391 for ; Sun, 12 May 2019 06:20:57 +0300 (EEST) Received: by mail-qt1-f193.google.com with SMTP id d13so3998911qth.5 for ; Sat, 11 May 2019 20:20:57 -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=vKRlFCdHtQVg/CZOq0cvcFzd/DFfLJygxhoO7IC5EZ0=; b=HJaxObIJ1atWLIZpe5EJPQVOLTKgfQrVewToSUQvjByE7O92hlTQT/rGW8kipsbi7+ 8B5rpm/c9GzyTxhF6FsMz4HxK9wrsqNDsEjWIxpa5LMVj1mClgqtZQx1hTpaPaReNeML yRWZXYZKuF/XRMrl8ZHaXiugSnwjAHt/tNQkGpcEYq5RC8IV6ZZYsAt+Zem12dlxE2Ja 1+1NHNMix06oa1vTZMdADUfVlBteMPyH25wPKRHw8HH2tP5Cg4BmrQ/NBipxslvVUmTr 0+SHn8tnnSJb4sali3dKt4k9Vk+6D7pxWv4NOnU9XuuEJcC2SaJmzZMry9Lt8U5nHH4V cgqQ== 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=vKRlFCdHtQVg/CZOq0cvcFzd/DFfLJygxhoO7IC5EZ0=; b=pvlzt4OIrohfJP2btKxSbs3CoECrPk8P+nsm+qGJaqUhXsG6fYO5tZsCV5GzH+C+RO QSXa8MBBf1Adzr89ap3OpFHVRNSemWr/AQFxxumXb7aJCIi2RcG/Fb0GP8UnYsG3D+FL bMSPRwa7nlDQBsw96Z70zz41ptgFvKdkG28h5HiAxlV1sLOYH4riCOQNCQcto1lRgRRr N7rwQ6jJoFYVPs29GBzg2k3YtKNf6Swn3vBvN3prwvZTwwYu3cGPYN/ME0YrrfsOppxH sWRSM37d3ANw6DGW58qnHtJalFx2RCoT3l6f9uznP6eHEPjDSb0wZkqHROhvuc0pSOCz xCBQ== X-Gm-Message-State: APjAAAU5onAYSOauhkuIYzrgX1a9vfCkG/BxCxzHCNmcsn5uo+qI3fc/ Lgalej2hqf27PtCesV9OT0G5Jb/g X-Google-Smtp-Source: APXvYqzysZppO9twMMpHTCDG7D8k2kcUe4zfhWFxLsTUQkofrk7frUifKln6vR6IGZt2Q7MmwyQs1g== X-Received: by 2002:ac8:375d:: with SMTP id p29mr16561680qtb.88.1557631255667; Sat, 11 May 2019 20:20:55 -0700 (PDT) Received: from localhost.localdomain (c-24-60-253-205.hsd1.ma.comcast.net. [24.60.253.205]) by smtp.gmail.com with ESMTPSA id x126sm1149066qkd.34.2019.05.11.20.20.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 11 May 2019 20:20:54 -0700 (PDT) From: Andriy Gelman X-Google-Original-From: Andriy Gelman To: ffmpeg-devel@ffmpeg.org Date: Sat, 11 May 2019 23:20:51 -0400 Message-Id: <20190512032051.29529-1-andriy.gelman@gmail.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] 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..0668ae3ad1 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); 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) {