From patchwork Wed Jan 13 17:46:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Foucu X-Patchwork-Id: 24939 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 B023444BAD3 for ; Wed, 13 Jan 2021 19:46:38 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 896DE68AD91; Wed, 13 Jan 2021 19:46:38 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9AC15680C0D for ; Wed, 13 Jan 2021 19:46:31 +0200 (EET) Received: by mail-pl1-f178.google.com with SMTP id b8so1467536plh.12 for ; Wed, 13 Jan 2021 09:46:31 -0800 (PST) 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=f+WMHYDFWaV2A21ygy8/5ltGExRIf2f1/47OE6xE6fc=; b=uGzx/pKPRz++8ZXo++uvUQKgV+6y1rLuyzcAvewkHcLZ5ehCQrebdD5Skahec+Yq0f KnRy3MXH2dg7IifGqNLtFt3wFn9Ilgc8KArSGMY5go3lOfjlOA7NfRvMLCMZkYEPGHzf Edb4COqoWQBHLnQJbxkh3Ul61a+LJ74Ku6lCBfhI5K09CE/4WWU7hLL+7u2Mveg8+RiR 9v0HHtwyy1M8PU+OEByPGM+Hn8vmQNxuWLxYcupMWCWuRMQn+dBR+UJxKKlm5e60VvDa f4iugiuY6zjB1ESkzpnt4rq0kvt0akJWkQG/bsFxW6A51s5DShtW4h2Bk3BZkcLvKEMh r5Hg== 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=f+WMHYDFWaV2A21ygy8/5ltGExRIf2f1/47OE6xE6fc=; b=BlB1KXShy1QJD7b0KGYCp9LbcpcGRJk4+VB+43ctMcZldwEZJwH1pn5ifFsRGvuBCk p79nIrymifH/TjRuTyNSmz0+0KewZiZPvu0SC3lleQP2/wVof4hgODS8iRnWJVJC5IK7 og4swr2Yj6kYeqxSuYreo44VfmdM5V3AW8OZYJh10y2K2+Bv1tOdcA413Gfo3X9Z+xzm 1QthOaJhyUDX3FqtJ9iH2BT53wIusTljmAgseIxKndHsgEoZmV9+AJklTCU72MQrPjJx D24ZK50XKUP5newaKwyY9ZOZL31p9cDqy6sm2VT3xdiqVJCO2qjXGNd47JQiECgM6yp8 oi6Q== X-Gm-Message-State: AOAM532dUCIAV6UZBi5loKKVjgtkOAn+E9FPCl1xKb7dxu0FgDmzYVs8 yspGxhoWu8J3RxMcc86s6laegJFstUc= X-Google-Smtp-Source: ABdhPJxkCcVKYUygXHKT/UGMCU5mJ7eyw81yCRyz37ZVWNRtP2Dc2pNGgALcV14w2+NvgErdvLmAnQ== X-Received: by 2002:a17:90a:a88e:: with SMTP id h14mr381326pjq.59.1610559989040; Wed, 13 Jan 2021 09:46:29 -0800 (PST) Received: from tfoucu.mtv.corp.google.com ([2620:0:1000:4001:a28c:fdff:feed:4b81]) by smtp.gmail.com with ESMTPSA id 123sm3224280pgf.38.2021.01.13.09.46.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jan 2021 09:46:27 -0800 (PST) From: Thierry Foucu To: ffmpeg-devel@ffmpeg.org Date: Wed, 13 Jan 2021 09:46:23 -0800 Message-Id: <20210113174623.1397914-1-tfoucu@gmail.com> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] libavformat/matroskaenc.c: Add option to set timecodescale 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: Thierry Foucu Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" By default the time code scale in a MKV file in millisecond. With this option we can set the time code scale to microsecond or nanoseconds for very high frame rate. --- libavformat/matroskaenc.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 233c472b8f..cfad6a4693 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -158,6 +158,8 @@ typedef struct MatroskaMuxContext { int default_mode; uint32_t segment_uid[4]; + + int64_t timecodescale; } MatroskaMuxContext; /** 2 bytes * 7 for EBML IDs, 7 1-byte EBML lengths, 6 1-byte uint, @@ -1827,7 +1829,7 @@ static int mkv_write_header(AVFormatContext *s) return ret; pb = mkv->info.bc; - put_ebml_uint(pb, MATROSKA_ID_TIMECODESCALE, 1000000); + put_ebml_uint(pb, MATROSKA_ID_TIMECODESCALE, mkv->timecodescale); 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)) { @@ -1927,12 +1929,12 @@ static int mkv_write_header(AVFormatContext *s) // after 4k and on a keyframe if (IS_SEEKABLE(pb, mkv)) { if (mkv->cluster_time_limit < 0) - mkv->cluster_time_limit = 5000; + mkv->cluster_time_limit = 5*(1000000000/mkv->timecodescale); 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 = 1*(1000000000/mkv->timecodescale); if (mkv->cluster_size_limit < 0) mkv->cluster_size_limit = 32 * 1024; } @@ -2708,7 +2710,7 @@ static int mkv_init(struct AVFormatContext *s) } // ms precision is the de-facto standard timescale for mkv files - avpriv_set_pts_info(st, 64, 1, 1000); + avpriv_set_pts_info(st, 64, 1, 1000000000/mkv->timecodescale); if (st->codecpar->codec_type == AVMEDIA_TYPE_ATTACHMENT) { if (mkv->mode == MODE_WEBM) { @@ -2795,6 +2797,7 @@ static const AVOption options[] = { { "infer", "For each track type, mark the first track of disposition default as default; if none exists, mark the first track as default.", 0, AV_OPT_TYPE_CONST, { .i64 = DEFAULT_MODE_INFER }, 0, 0, FLAGS, "default_mode" }, { "infer_no_subs", "For each track type, mark the first track of disposition default as default; for audio and video: if none exists, mark the first track as default.", 0, AV_OPT_TYPE_CONST, { .i64 = DEFAULT_MODE_INFER_NO_SUBS }, 0, 0, FLAGS, "default_mode" }, { "passthrough", "Use the disposition flag as-is", 0, AV_OPT_TYPE_CONST, { .i64 = DEFAULT_MODE_PASSTHROUGH }, 0, 0, FLAGS, "default_mode" }, + { "timecodescale", "Time code scale for all tracks in nanoseconds", OFFSET(timecodescale), AV_OPT_TYPE_INT64, { .i64 = 1000000 }, 1, 1000000000, FLAGS }, { NULL }, };