From patchwork Tue May 18 23:47:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Fabian 'Xaymar' Dirks X-Patchwork-Id: 27836 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:b214:0:0:0:0:0 with SMTP id b20csp872472iof; Tue, 18 May 2021 16:48:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy5+5MkGKRPB4hjTg2f5/rlaC8p6Nnh+7zk3LC7mOyXeTayhyfl3Hp/Gbg8imBMpIp1Z+tS X-Received: by 2002:a17:906:710a:: with SMTP id x10mr8791184ejj.516.1621381714662; Tue, 18 May 2021 16:48:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621381714; cv=none; d=google.com; s=arc-20160816; b=LXs0w0zcF0aJ2wip82AfQADIw4tkUULv9HCeIGyA0GhukiBk91zbJPKGWcdF48oJei 6V9FmwuSE7RhJKv/0I2sDtvx6xTdGE/gbeyyjF5og4sxpM6yHbfv+Q6Q4LTEI+DVJ4f8 gf5VR9EmTthL0p3GDcHwD9yfZlOli0DknnfOLR7tQKZmRmNG5DUyQQKSjQeeFtOXBCPQ 4XMTIJ/ptG4890QIJru+mkLTmq5un31biDGmGP6yMAVZ0exoyPCRDiqwkM8OmoQR9wLn 8N3e5Sr/65bAA4cRnlOMe7hWs215u4D0ZqW164l2MtHPrNOD558GM/spa2JJcI4KPiT/ LI1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=oi3Muozs8oSmQBo0ROBDP/mMQY+f41Gw+URRXPz0tzY=; b=oBsrHxVd7kkSs7CXrQqTlkE2LMQcz68BnVIVNEWCT8yaFRkTXA9f6/L6Bu+9RSG051 miotHHVB94oIPX+gv0AF+ZLmGRb9mHHIykwQkso+zRWoByWlHu/q/MSxIMN0+jus0+wS b3cTuVcHSSr+ZcQBT6qtoe7y2Yadrzl1PIs8CLXC7DperT5VkJ3B0fUMSv83nXsLQi0x WdBPUYmxH5ZCqxaGxNLcWBMDTnkZ5847eY8rEeVJf4x9OaRKME4cOXrZv3A742488dZq W3ly6Yey0djGrGTLHT9isqyb3TA5PXcDKY19O8pawM9B7M8OqDxzZiw29aRbCn5wFfQ4 9K+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@xaymar.com header.s=mail header.b=QG4eytvc; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=xaymar.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id p22si7688813eds.368.2021.05.18.16.48.33; Tue, 18 May 2021 16:48:34 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@xaymar.com header.s=mail header.b=QG4eytvc; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=xaymar.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BE555689D2E; Wed, 19 May 2021 02:48:29 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.xaymar.com (mail.xaymar.com [88.99.2.119]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8CC3D689A91 for ; Wed, 19 May 2021 02:48:22 +0300 (EEST) Received-SPF: Temperror (mailfrom) identity=mailfrom; client-ip=90.187.35.181; helo=localhost.localdomain; envelope-from=michael.dirks@xaymar.com; receiver= DKIM-Signature: v=1; a=rsa-sha256; c=simple/relaxed; d=xaymar.com; s=mail; t=1621381701; bh=gcUVH9rUbDSO0ccOqKIYIMtCus0pvUmT7PkSn0cRsxQ=; h=From:To:Cc:Subject:Date:From; b=QG4eytvcZv/D7wTz3kK00iV65T35DDHjCsmxQt0WlNbSBjKc6m/qBsjhwzgPfjAam SAePFOhRa1+bhXwoaUV7e2mih5mlYoxHoB1nju1Eq3x1JTrWwJy8uDaRlTlM2iKPAs mycHONqzktcLJqkCKm6MlZGnIVNpsdKj9KhHNOvhpf8QUMdnmcL3AkplbvB19jPoXV VisE3JKtZS2fa9ryRPbjIRT6qfkB8hhTsun/I959dy9agN2mkUCw/5qVqmBk3R9Job JSEtfs042yWtJkHgENkGRabeDlqEcKJzZfjHFAjoSfBd71O3bpZ8db4sT1oXGgwLf3 +NoAgBPDVxTdg== Received: from localhost.localdomain (business-90-187-35-181.pool2.vodafone-ip.de [90.187.35.181]) by mail.xaymar.com (Postfix) with ESMTPSA id 62DBFE0748; Wed, 19 May 2021 01:48:21 +0200 (CEST) From: michael.dirks@xaymar.com To: ffmpeg-devel@ffmpeg.org Date: Wed, 19 May 2021 01:47:44 +0200 Message-Id: <20210518234744.1990-1-michael.dirks@xaymar.com> X-Mailer: git-send-email 2.31.1.windows.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat/matroskaenc: Increase time stamp precision to AV_TIME_BASE X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Michael Fabian 'Xaymar' Dirks Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: BxY+USRU9VfV From: Michael Fabian 'Xaymar' Dirks Increases the time stamp precision to 1 microsecond, the same as AV_TIME_BASE. This hopefully prevents demuxers from being confused on the number of frames/samples we actually have per second, and should mark all future Matroska/WebM content as being constant rate. Work-around for: 259, 6406, 7927, 8909, 9124. Signed-off-by: Michael Fabian 'Xaymar' Dirks --- libavformat/matroskaenc.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index ad7b0bf2c6..474e44485a 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -1917,7 +1917,8 @@ static int mkv_write_header(AVFormatContext *s) return ret; pb = mkv->info_bc; - put_ebml_uint(pb, MATROSKA_ID_TIMECODESCALE, 1000000); + // Set time base to 1 microsecond. + put_ebml_uint(pb, MATROSKA_ID_TIMECODESCALE, 1000000000 / AV_TIME_BASE); if ((tag = av_dict_get(s->metadata, "title", NULL, 0))) put_ebml_string(pb, MATROSKA_ID_TITLE, tag->value); if (!(s->flags & AVFMT_FLAG_BITEXACT)) { @@ -1959,11 +1960,11 @@ static int mkv_write_header(AVFormatContext *s) int64_t metadata_duration = get_metadata_duration(s); if (s->duration > 0) { - int64_t scaledDuration = av_rescale(s->duration, 1000, AV_TIME_BASE); + int64_t scaledDuration = s->duration; put_ebml_float(pb, MATROSKA_ID_DURATION, scaledDuration); av_log(s, AV_LOG_DEBUG, "Write early duration from recording time = %" PRIu64 "\n", scaledDuration); } else if (metadata_duration > 0) { - int64_t scaledDuration = av_rescale(metadata_duration, 1000, AV_TIME_BASE); + int64_t scaledDuration = metadata_duration; put_ebml_float(pb, MATROSKA_ID_DURATION, scaledDuration); av_log(s, AV_LOG_DEBUG, "Write early duration from metadata = %" PRIu64 "\n", scaledDuration); } else { @@ -2038,12 +2039,12 @@ static int mkv_write_header(AVFormatContext *s) // after 4k and on a keyframe if (pb->seekable & AVIO_SEEKABLE_NORMAL) { if (mkv->cluster_time_limit < 0) - mkv->cluster_time_limit = 5000; + mkv->cluster_time_limit = 5000000; if (mkv->cluster_size_limit < 0) mkv->cluster_size_limit = 5 * 1024 * 1024; } else { if (mkv->cluster_time_limit < 0) - mkv->cluster_time_limit = 1000; + mkv->cluster_time_limit = 1000000; if (mkv->cluster_size_limit < 0) mkv->cluster_size_limit = 32 * 1024; } @@ -2724,6 +2725,7 @@ static int webm_query_codec(enum AVCodecID codec_id, int std_compliance) static int mkv_init(struct AVFormatContext *s) { int i; + MatroskaMuxContext *mkv = s->priv_data; if (s->nb_streams > MAX_TRACKS) { av_log(s, AV_LOG_ERROR, @@ -2752,10 +2754,13 @@ static int mkv_init(struct AVFormatContext *s) } for (i = 0; i < s->nb_streams; i++) { - // ms precision is the de-facto standard timescale for mkv files - avpriv_set_pts_info(s->streams[i], 64, 1, 1000); + // Use µs precision (same as FFmpeg) + avpriv_set_pts_info(s->streams[i], 64, 1, AV_TIME_BASE); } + // Scale the configured cluster_time_limit to microseconds. + mkv->cluster_time_limit = av_rescale(mkv->cluster_time_limit, 1000, AV_TIME_BASE); + return 0; }