Re: [Cellar] matroska and side data vs timecode

Steve Lhomme <slhomme@matroska.org> Sun, 03 November 2019 10:29 UTC

Return-Path: <slhomme@matroska.org>
X-Original-To: cellar@ietfa.amsl.com
Delivered-To: cellar@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 85AE8120108 for <cellar@ietfa.amsl.com>; Sun, 3 Nov 2019 02:29:48 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.898
X-Spam-Level:
X-Spam-Status: No, score=-1.898 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (2048-bit key) header.d=matroska-org.20150623.gappssmtp.com
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id BGvX64ikoNTR for <cellar@ietfa.amsl.com>; Sun, 3 Nov 2019 02:29:46 -0800 (PST)
Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id E926A1200FD for <cellar@ietf.org>; Sun, 3 Nov 2019 02:29:45 -0800 (PST)
Received: by mail-pg1-x52f.google.com with SMTP id z24so4813677pgu.4 for <cellar@ietf.org>; Sun, 03 Nov 2019 02:29:45 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=matroska-org.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=iMihK/lXojBGpYuEtbXlNndeU8u/zpS5ae2TZSlTrlc=; b=EhJOScZs0o7kV2LgXK2uBF1zQoBwAfi8jCXApdiQIogmqc1FRaWiTYsh8G9ZXTiBbo htZGDnaEMxrM03b191GzMDfdu2v98+dmfbiqj4Snz01tWaDP4IgQ+DnYd37MHnobrWX6 uouEezwp7sqsZKgop3udsIgCFHMCgKORIwUNTTYlf5mUXTEFF/OAmVr3IExHZF0yyB5s 3ztXsRk9/LDGE+Vg+2dOsgnQ+ZKaB0uxyQpn42CDn9vfW5zuOMtgtakzsKlv4ZDqYvK7 1Iec91i1y+d+PAleD9u3aJZdyynxUldC4tkKZMA4M3thcF1hpD0aASR1KEYrHOgcfDYh +1AA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=iMihK/lXojBGpYuEtbXlNndeU8u/zpS5ae2TZSlTrlc=; b=Th7Zbjv418jBtuBTXXcv9dGI7MM1z9WbScvwJrWgXsfW9fTcHoLNaEVxCdBS2Q15Nu 1D2UuO4ywVGdWG4rxv4zTYRywDDOiEoq3zZK/IQ02QI0GqsELxbk36+TAsgixObzhDSI 5GI6P4hCoTi3BRhDkQEqW9RoRubR4pQviGPnyVEcRKKifm7VYjkXX0xtuD2q/LtmBntZ tccuZ8KdZjQK2r6CCyT8RmyHq9Mo5qfwJuBjSqsEpDhJOF0lRx/PmHYuC8x8wgn2DkD6 DUrL7AEJiTqOLrv43XzAUkQ5K5JyYwGOTjos7r4hy9rKsYNN7cjxlLBwYc5hze2BJLf9 MKCA==
X-Gm-Message-State: APjAAAW4rlPosK+pTHgtsU/i2WHJGitjsR8rO9BK6YUpoSsrxda9HgO7 r0GuNAwG5ylw3R1jDb+QRldIhZ5B1oBwWZzXL93K8ItHB3k=
X-Google-Smtp-Source: APXvYqwTxHdlkCmYlzeAWuhY7Jqk6PGpBpIE34SdqX8As4YViG9jIEevJguSsWD8eDP/HeD8p7G5SM7O1OgPi08retg=
X-Received: by 2002:a17:90a:eac8:: with SMTP id ev8mr27470670pjb.99.1572776985267; Sun, 03 Nov 2019 02:29:45 -0800 (PST)
MIME-Version: 1.0
References: <00F6A0BF-2922-4BAC-AC73-EB888767886F@dericed.com>
In-Reply-To: <00F6A0BF-2922-4BAC-AC73-EB888767886F@dericed.com>
From: Steve Lhomme <slhomme@matroska.org>
Date: Sun, 03 Nov 2019 11:29:34 +0100
Message-ID: <CAOXsMF+_zZjKS9GRjBhpQMQ5dbQK04hph5x5o8UJjj5ngkaaMA@mail.gmail.com>
To: Dave Rice <dave@dericed.com>
Cc: Codec Encoding for LossLess Archiving and Realtime transmission <cellar@ietf.org>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Archived-At: <https://mailarchive.ietf.org/arch/msg/cellar/T3t2VwHQ84CK3rhibgCnyVUYu40>
Subject: Re: [Cellar] matroska and side data vs timecode
X-BeenThere: cellar@ietf.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Codec Encoding for LossLess Archiving and Realtime transmission <cellar.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/cellar>, <mailto:cellar-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/cellar/>
List-Post: <mailto:cellar@ietf.org>
List-Help: <mailto:cellar-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/cellar>, <mailto:cellar-request@ietf.org?subject=subscribe>
X-List-Received-Date: Sun, 03 Nov 2019 10:29:48 -0000

Le mar. 29 oct. 2019 à 17:04, Dave Rice <dave@dericed.com> a écrit :
> I drafted a pull request at https://github.com/cellar-wg/matroska-specification/pull/348 that builds upon the new side data structure defined above. This pull request registers a BlockAddIDType for a 64 bit binary expression of timecode as defined by SMPTE ST12-1:2014 (which is mostly hours, minutes, seconds, frames, a drop frame flag, and other a few other flags and binary groups). This would allow timecode to be associated with Matroska frames such as:
>
> <Segment>
>  <!-- skipped elements here -->
>  <Tracks>
>   <!-- lots of other track data here -->
>   <TrackEntry>
>    <BlockAdditionMapping>
>     <BlockAddIDValue>2</BlockAddIDValue>
>     <BlockAddIDName>SMPTE ST 12-1 timecode</BlockAddIDName>
>     <BlockAddIDType>121</BlockAddIDType>
>    </BlockAdditionMapping>
>  </Tracks>
>  <!-- then within the Cluster which stores audiovisual data within frames in Blocks, there is -->
>  <Cluster>
>   <BlockGroup>
>    <Block> { a video frame } </Block>
>    <BlockAdditions>
>     <BlockMore>
>      <BlockAddID>2</BlockAddID>
>      <BlockAdditional> { SMPTE ST12-1:2014 64-bit binary representation of a 07:32:54;18 } </BlockAdditional>
>     </BlockMore>
>    </BlockAdditions>
>   </BlockGroup>
>   <BlockGroup>
>    <Block> { the next video frame } </Block>
>    <BlockAdditions>
>     <BlockMore>
>      <BlockAddID>2</BlockAddID>
>      <BlockAdditional> { SMPTE ST12-1:2014 64-bit binary representation of a 07:32:54;19 } </BlockAdditional>
>     </BlockMore>
>    </BlockAdditions>
>   </BlockGroup>
>  </Cluster>
> </Segment>
>
> With the BlockAdditions, BlockMore, BlockAddID, and BlockAdditional Elements, I think this would add 18 bytes per timecode expression. Adding timecode to one hour of PAL video (25 frames * 3600 seconds/hour) would add about 1.5 MB to the file.

That seems like a big overhead. Is the 64 bits value necessary ? It
seems 32 bits might be sufficient (saving 4 bytes). Maybe 40 if you
need extra flags.

> Implementation Considerations:
>
> Thinking ahead of this work, I think it would be worthwhile to add a dedicated section to the Matroska specification on timecode and describe two methods for adding a reference timecode to a Matroska Segment.
>
> 1. Using tags. Make an official tag “TIMECODE” to store a string of the timecode expression that correlates to the Matroska timestamp of 0. This approach is limited to storing timecode that is incremental and continuous. Defaults for the incrementation and the behavior of the timecode could be described as part of the tag definitions and feasibly another tag or tags could be reserved for timecode flags when the timecode behavior is not a default. Defining a use of a “TIMECODE” tag would provide the benefit of standardizing an existing practice in FFmpeg’s Matroska muxer, where rewrapping from a timecode-supportive format to Matroska carries the timecode value over as a tag.

In general I'm not in favor of using tags for data that may be needed
when remuxing, especially tied to a timestamp (yes, I mean timestamp).
If the first frame is damaged, does the timecode apply to the second
frame ? If the first frame timestamp wasn't 0, how do you know the
difference you have to apply ?

If you want something that will survive this scenario you have to tie
this value to the first timestamp. When remuxing, if timestamps are
altered of portions at the beginning of the file are removed, you need
to edit the first timecode. It may be better to store in the TrackInfo
with both the first timestamp and timecode values. It may not work
when stripping the audio (as Tobias pointed out). So it may even be
put in the SegmentInfo instead of the TrackInfo.

You may also set the value in Chapters (which are not tied to a
track). There's already a start timestamp. You could add the timecode
for this timestamp. That works for NLE sources as well, each
non-linear part would be a chapter with its timestamp translation. A
good NLE system would also tag this chapter with all kinds of data
about the source. (Matroska was also designed for this case in mind).

> 2. Using BlockAdditions as described above. This adds more overhead as each timecode value would be written, but would support non-continuous timecode. In FFmpeg, timecode is sometimes carried as side-data such as from the decklink device via https://git.ffmpeg.org/gitweb/ffmpeg.git/commit/0946c0ec177dc48ef0677f890aa42d95e667c417. I’d be interested if the Block Addition Mapping described above could be used to carry the timecode side data from the decklink device (or other incoming stream with timecode side data) and store the result within the written Matroska BlockGroups.

That's the no-brainer option. It just works. It's just less optimal
that one value (or a few for NLE sources).

> Comments welcome.
>
> Thanks much,
> Dave Rice
> _______________________________________________
> Cellar mailing list
> Cellar@ietf.org
> https://www.ietf.org/mailman/listinfo/cellar



-- 
Steve Lhomme
Matroska association Chairman