<?xml version="1.0" encoding="utf-8"?>
<!-- name="GENERATOR" content="github.com/mmarkdown/mmark Mmark Markdown Processor - mmark.miek.nl" -->
<rfc version="3" ipr="trust200902" docName="draft-ietf-cellar-chapter-codecs-05" sortRefs="true" tocDepth="4" submissionType="IETF" category="std" xml:lang="en" xmlns:xi="http://www.w3.org/2001/XInclude" indexInclude="true">

<front>
<title abbrev="Matroska Chapter Codecs">Matroska Media Container Chapter Codecs Specifications</title><seriesInfo value="draft-ietf-cellar-chapter-codecs-05" stream="IETF" status="standard" name="Internet-Draft"></seriesInfo>
<author initials="S." surname="Lhomme" fullname="Steve Lhomme"><organization></organization><address><postal><street></street>
</postal><email>slhomme@matroska.org</email>
</address></author><author initials="M." surname="Bunkus" fullname="Moritz Bunkus"><organization></organization><address><postal><street></street>
</postal><email>moritz@bunkus.org</email>
</address></author><author initials="D." surname="Rice" fullname="Dave Rice"><organization></organization><address><postal><street></street>
</postal><email>dave@dericed.com</email>
</address></author><date year="2024" month="August" day="28"></date>
<area>art</area>
<workgroup>cellar</workgroup>
<keyword>binary</keyword>
<keyword>storage</keyword>
<keyword>matroska</keyword>
<keyword>ebml</keyword>
<keyword>tags</keyword>

<abstract>
<t>This document defines common Matroska Chapter Codecs, the basic Matroska Script and the DVD inspired DVD menu <xref target="DVD-Video"></xref>.</t>
</abstract>

</front>

<middle>

<section anchor="introduction"><name>Introduction</name>
<t>The <xref target="Matroska"></xref> container can be expanded with Matroska Chapter Codecs. They define a set of instructions
that the <tt>Matroska Player</tt> should execute when entering, leaving or during playback of a Chapter.
This allows extra features not provided by the classical linear playback of files.</t>
<t>The Matroska Chapter Codecs codec is extensible. So any new codec can be created
and support added in players.</t>
</section>

<section anchor="status-of-this-document"><name>Status of This Document</name>
<t>This document is a work-in-progress specification defining the Matroska file format as part
of the <eref target="https://datatracker.ietf.org/wg/cellar/charter/">IETF Cellar working group</eref>.
It uses basic elements and concept already defined in the Matroska specifications defined by this workgroup <xref target="Matroska"></xref>.</t>
</section>

<section anchor="notation-and-conventions"><name>Notation and Conventions</name>
<t>The key words &quot;<bcp14>MUST</bcp14>&quot;, &quot;<bcp14>MUST NOT</bcp14>&quot;,
&quot;<bcp14>REQUIRED</bcp14>&quot;, &quot;<bcp14>SHALL</bcp14>&quot;, &quot;<bcp14>SHALL NOT</bcp14>&quot;,
&quot;<bcp14>SHOULD</bcp14>&quot;, &quot;<bcp14>SHOULD NOT</bcp14>&quot;,
&quot;<bcp14>RECOMMENDED</bcp14>&quot;, &quot;<bcp14>NOT RECOMMENDED</bcp14>&quot;,
&quot;<bcp14>MAY</bcp14>&quot;, and &quot;<bcp14>OPTIONAL</bcp14>&quot; in this document are to be interpreted as
described in BCP 14 <xref target="RFC2119"></xref> <xref target="RFC8174"></xref>
when, and only when, they appear in all capitals, as shown here.</t>
</section>

<section anchor="matroska-chapter-codecs"><name>Matroska Chapter Codecs</name>
<t>Chapter codecs are a way to add more complex playback features than the usual linear playback.</t>
<t>Some <tt>ChapProcess</tt> elements hold commands to execute when entering/leaving a chapter.</t>
<t>When chapter codecs are used the <tt>EditionFlagOrdered</tt> of the edition they belong to <bcp14>MUST</bcp14> be set.</t>
<t>Each <tt>ChapProcessCodecID</tt> value in an edition <bcp14>SHOULD</bcp14> have a single interpreter for the whole <tt>EditionEntry</tt>,
if that <tt>ChapProcessCodecID</tt> value is supported by the <tt>Matroska Player</tt>.
This is necessary to be able to read/write global variables that can be used between chapters.</t>

<section anchor="segment-linking"><name>Segment Linking</name>
<t>Chapter Codecs can reference another <tt>Segment</tt> and jump to that <tt>Segment</tt>.</t>
<t>The Chapter Codecs <bcp14>MAY</bcp14> store the Segment information in their own format, possibly not using the <tt>SegmentUUID</tt> format.
The <tt>ChapterTranslate</tt> element and its child elements <bcp14>SHOULD</bcp14> be used
to link the internal chapter codec representation, the chapter codec number and the actual Segment it represents.</t>
<t>For example, if a chapter codec of type &quot;1&quot; in SegmentA needs to link to SegmentB,
it can store that information as &quot;SegB&quot; in its internal data.</t>
<t>The translation <tt>ChapterTranslate</tt> in SegmentB would use the following elements:</t>

<ul>
<li><t><tt>ChapterTranslate\ChapterTranslateCodec</tt> = 1</t>
</li>
<li><t><tt>ChapterTranslate\ChapterTranslateID</tt> = &quot;SegB&quot;</t>
</li>
</ul>
<t>The <tt>Matroska Player</tt> <bcp14>MUST</bcp14> use the <tt>SegmentFamily</tt> to find all Segments that need translation
between the chapter codec values and the actual segment it targets.</t>
</section>
</section>

<section anchor="matroska-chapter-codecs-and-nested-chapters"><name>Matroska Chapter Codecs and Nested Chapters</name>
<t>When <tt>Nested Chapters</tt> contain chapters codecs -- via the <tt>ChapProcess</tt> element --
the enter/leave commands -- <tt>ChapProcessTime</tt> element -- <bcp14>MUST</bcp14> be executed in a specific order,
if the Matroska Player supports the chapter codecs included in the chapters.</t>
<t>When starting playback, the <tt>Matroska Player</tt> <bcp14>MUST</bcp14> start at the <tt>ChapterTimeStart</tt> of the first chapter of the ordered chapter.
The enter commands of that chapter <bcp14>MUST</bcp14> be executed.
If that chapter contains <tt>Nested Chapters</tt>, the enter commands of the <tt>Nested Chapter</tt> with the same <tt>ChapterTimeStart</tt> <bcp14>MUST</bcp14> be executed.
If that chapter contains <tt>Nested Chapters</tt>, the enter commands of the <tt>Nested Chapter</tt> with the same <tt>ChapterTimeStart</tt> <bcp14>MUST</bcp14> be executed,
and so on until there is no <tt>Nested Chapter</tt> with the same <tt>ChapterTimeStart</tt>.</t>
<t>When switching from a chapter to another:</t>

<ul>
<li><t>the leave commands (<tt>ChapProcessTime</tt>=2) of the
chapter <bcp14>MUST</bcp14> be executed, then the leave commands of its parent chapter, etc., until the
common <tt>Parent Chapter</tt> or <tt>Edition</tt> element. The leave command of that <tt>Parent Chapter</tt> or <tt>Edition</tt> element
<bcp14>MUST NOT</bcp14> be executed.</t>
</li>
<li><t>the enter commands (<tt>ChapProcessTime</tt>=1) of the <tt>Nested Chapter</tt> of the common <tt>Parent Chapter</tt> or <tt>Edition</tt> element,
to reach the chapter we switch to, <bcp14>MUST</bcp14> be executed, then the enter commands of its <tt>Nested Chapter</tt>
to reach the chapter we switch to <bcp14>MUST</bcp14> be executed, until that chapter is the chapter we switch to.
The enter commands of that chapter <bcp14>MUST</bcp14> be executed as well.</t>
</li>
</ul>
<t>When the last Chapter finished playing, i.e., its <tt>ChapterTimeEnd</tt> has been reached,
the <tt>Matroska Player</tt> <bcp14>MUST</bcp14> execute its leaved commands, then the leave commands of it's <tt>Parent Chapter</tt>,
until the parent of the chapter is the Edition.</t>

<section anchor="matroska-script"><name>Matroska Script</name>
<t>This is the case when <tt>ChapProcessCodecID</tt> = 0. This is a script language build for
Matroska purposes. The inspiration comes from <xref target="ActionScript"></xref>, <xref target="ECMAScript"></xref> and other similar
scripting languages. The commands are stored as text commands, in UTF-8. The syntax is C like,
with commands spanned on many lines, each terminating with a semicolon &quot;;&quot;. You can also include comments
at the end of lines with &quot;//&quot; or comment many lines using &quot;/* */&quot;. The scripts are stored
in <tt>ChapProcessData</tt>. For the moment <tt>ChapProcessPrivate</tt> is not used.</t>
<t>The one and only command existing for the moment is <tt>GotoAndPlay( ChapterUID );</tt>. As the
same suggests, it means that, when this command is encountered, the <tt>Matroska Player</tt>
<bcp14>SHOULD</bcp14> jump to the <tt>Chapter</tt> specified by the UID and play it, as long as this <tt>Chapter</tt> exists.</t>
</section>

<section anchor="dvd-menu"><name>DVD Menu</name>
<t>This is the case when <tt>ChapProcessCodecID</tt> = 1. Each level of a chapter corresponds
to a logical level in the DVD system <xref target="DVD-Video"></xref> that is stored in the first octet of the <tt>ChapProcessPrivate</tt>.
This DVD hierarchy is as follows:</t>
<table>
<thead>
<tr>
<th>ChapProcessPrivate</th>
<th>DVD Name</th>
<th>Hierarchy</th>
<th>Commands Possible</th>
<th>Comment</th>
</tr>
</thead>

<tbody>
<tr>
<td>0x30</td>
<td>SS</td>
<td>DVD domain</td>
<td>-</td>
<td>First Play, Video Manager, Video Title</td>
</tr>

<tr>
<td>0x2A</td>
<td>LU</td>
<td>Language Unit</td>
<td>-</td>
<td>Contains only PGCs</td>
</tr>

<tr>
<td>0x28</td>
<td>TT</td>
<td>Title</td>
<td>-</td>
<td>Contains only PGCs</td>
</tr>

<tr>
<td>0x20</td>
<td>PGC</td>
<td>Program Group Chain (PGC)</td>
<td>*</td>
<td></td>
</tr>

<tr>
<td>0x18</td>
<td>PG</td>
<td>Program 1 / Program 2 / Program 3</td>
<td>-</td>
<td></td>
</tr>

<tr>
<td>0x10</td>
<td>PTT</td>
<td>Part Of Title 1 / Part Of Title 2</td>
<td>-</td>
<td>Equivalent to the chapters on the sleeve.</td>
</tr>

<tr>
<td>0x08</td>
<td>CN</td>
<td>Cell 1 / Cell 2 / Cell 3 / Cell 4 / Cell 5 / Cell 6</td>
<td>-</td>
<td></td>
</tr>
</tbody>
</table><t>You can also recover wether a Segment is a Video Manager (VMG), Video Title Set (VTS)
or Video Title Set Menu (VTSM) from the ChapterTranslateID element found in the Segment Info.
This field uses 2 octets as follows:</t>

<ol spacing="compact">
<li>Domain Type: 0 for VMG, the domain number for VTS and VTSM</li>
<li>Domain Value: 0 for VMG and VTSM, 1 for the VTS source.</li>
</ol>
<t>For instance, the menu part from VTS_01_0.VOB would be coded [1,0] and the content
part from VTS_02_3.VOB would be [2,1]. The VMG is always [0,0]</t>
<t>The following octets of <tt>ChapProcessPrivate</tt> are as follows:</t>
<table>
<thead>
<tr>
<th>Octet 1</th>
<th>DVD Name</th>
<th>Following Octets</th>
</tr>
</thead>

<tbody>
<tr>
<td>0x30</td>
<td>SS</td>
<td>Domain name code (1: 0x00= First play, 0xC0= VMG, 0x40= VTSM, 0x80= VTS) + VTS(M) number (2)</td>
</tr>

<tr>
<td>0x2A</td>
<td>LU</td>
<td>Language code (2) + Language extension (1)</td>
</tr>

<tr>
<td>0x28</td>
<td>TT</td>
<td>global Title number (2) + corresponding TTN of the VTS (1)</td>
</tr>

<tr>
<td>0x20</td>
<td>PGC</td>
<td>PGC number (2) + Playback Type (1) + Disabled User Operations (4)</td>
</tr>

<tr>
<td>0x18</td>
<td>PG</td>
<td>Program number (2)</td>
</tr>

<tr>
<td>0x10</td>
<td>PTT</td>
<td>PTT-chapter number (1)</td>
</tr>

<tr>
<td>0x08</td>
<td>CN</td>
<td>Cell number [VOB ID(2)][Cell ID(1)][Angle Num(1)]</td>
</tr>
</tbody>
</table><t>If the level specified in <tt>ChapProcessPrivate</tt> is a PGC (0x20), there is an octet
called the Playback Type, specifying the kind of PGC defined:</t>

<ul>
<li><t><tt>0x00</tt>: entry only/basic PGC</t>
</li>
<li><t><tt>0x82</tt>: Title+Entry Menu (only found in the Video Manager domain)</t>
</li>
<li><t><tt>0x83</tt>: Root Menu (only found in the VTSM domain)</t>
</li>
<li><t><tt>0x84</tt>: Subpicture Menu (only found in the VTSM domain)</t>
</li>
<li><t><tt>0x85</tt>: Audio Menu (only found in the VTSM domain)</t>
</li>
<li><t><tt>0x86</tt>: Angle Menu (only found in the VTSM domain)</t>
</li>
<li><t><tt>0x87</tt>: Chapter Menu (only found in the VTSM domain)</t>
</li>
</ul>
<t>The next 4 following octets correspond to the <tt>User Operation flags</tt>
in the standard PGC. When a bit is set, the command <bcp14>SHOULD</bcp14> be disabled.</t>
<t><tt>ChapProcessData</tt> contains the pre/post/cell commands in binary format as there are stored on a DVD.
There is just an octet preceding these data to specify the number of commands in the element.
As follows: [# of commands(1)][command 1 (8)][command 2 (8)][command 3 (8)].</t>
<t>More information on the DVD commands and format on DVD
from the <xref target="DVD-Info"></xref> project and <xref target="Inside-DVD-Video"></xref>.</t>
</section>
</section>

<section anchor="security-considerations"><name>Security Considerations</name>
<t><tt>Tag</tt> values can be either strings or binary blobs. This document inherits security
considerations from the EBML <xref target="RFC8794"></xref> and Matroska <xref target="Matroska"></xref> documents.</t>
</section>

<section anchor="iana-considerations"><name>IANA Considerations</name>
<t>The Chapter Codec ID values set in <tt>ChapProcessCodecID</tt> use the Matroska Chapter Codec IDs Registry
defined in <xref target="Matroska"></xref>.</t>
<t>The initial values 0 and 1 are defined in <xref target="matroska-script"></xref> and <xref target="dvd-menu"></xref> respectively.</t>
</section>

</middle>

<back>
<references><name>References</name>
<references><name>Normative References</name>
<reference anchor="Matroska" target="">
  <front>
    <title>Media Container Specifications</title>
    <author fullname="Steve Lhomme" initials="S." surname="Lhomme"></author>
    <author fullname="Moritz Bunkus" initials="M." surname="Bunkus"></author>
    <author fullname="Dave Rice" initials="D." surname="Rice"></author>
    <date year="2024" month="April" day="24"></date>
  </front>
  <seriesInfo name="Internet-Draft" value="draft-ietf-cellar-matroska-21"></seriesInfo>
</reference>
<xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.2119.xml"/>
<xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.8174.xml"/>
<xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.8794.xml"/>
</references>
<references><name>Informative References</name>
<reference anchor="ActionScript" target="https://en.wikipedia.org/wiki/ActionScript">
  <front>
    <title>ActionScript</title>
    <author>
      <organization>Wikipedia</organization>
    </author>
  </front>
</reference>
<reference anchor="DVD-Info" target="http://dvd.sourceforge.net/dvdinfo/">
  <front>
    <title>DVD-Video Information</title>
    <author></author>
  </front>
</reference>
<reference anchor="DVD-Video" target="http://www.dvdforum.org/">
  <front>
    <title>DVD-Books: Part 3 DVD-Video Book</title>
    <author>
      <organization>DVD Forum</organization>
    </author>
    <date year="1995" month="November"></date>
  </front>
</reference>
<reference anchor="ECMAScript" target="https://262.ecma-international.org/14.0/">
  <front>
    <title>ECMA-262 14th Edition, June 2022. ECMAScript 2023 language specification</title>
    <author>
      <organization>Ecma International</organization>
    </author>
    <date year="2023" month="June"></date>
  </front>
</reference>
<reference anchor="Inside-DVD-Video" target="https://en.wikibooks.org/wiki/Inside_DVD-Video/Instruction_Set_Details">
  <front>
    <title>Inside DVD-Video/Instruction Set Details</title>
    <author>
      <organization>Wikibooks</organization>
    </author>
  </front>
</reference>
</references>
</references>

</back>

</rfc>
