[FFmpeg-devel] [PATCH] FFV1 specification: Add more details about the configuration record

Jerome Martinez jerome at mediaarea.net
Thu May 14 12:36:53 CEST 2015


Le 14/05/2015 00:48, Michael Niedermayer a écrit :
>
> nut and ffm surely work too

I have doubts there are lot of FFV1 content in such container format ;-)

Anyway:
- Patch updated with NUT file format information
- I tested FFmpeg for the support of FFV1 in FFM (source MOV files are 
there 
https://github.com/MediaArea/MediaConch/tree/master/SampleTestFiles/FFV1 )

ffmpeg -i ffv1_0.mov -vcodec copy ffv1_0.ffm
ffmpeg -i ffv1_0.ffm -f null /dev/null
is OK.

ffmpeg -i ffv1_3.mov -vcodec copy ffv1_3.ffm
ffmpeg -i ffv1_3.ffm -f null /dev/null
is NOK

[ffv1 @ 004F2600] read_quant_table error
[ffv1 @ 00515AC0] Cannot decode non-keyframe without valid keyframe
[ffv1 @ 005296A0] Cannot decode non-keyframe without valid keyframe
[ffv1 @ 00537BC0] Cannot decode non-keyframe without valid keyframe
[ffv1 @ 004D22A0] Cannot decode non-keyframe without valid keyframe
[ffv1 @ 004D2700] Cannot decode non-keyframe without valid keyframe
[ffv1 @ 004D3300] Cannot decode non-keyframe without valid keyframe
Error while decoding stream #0:0: Invalid data found when processing input

I looked for the GlobalHeader presence in ffv1_3.ffm (FFM2 format) but 
it is not present (I don't find the 4 bytes of CRC in the file)
Looks like FFmpeg creates invalid FFV1 version 3 in NUT files (frames 
are OK but the GlobalHeader part is missing) and is not able to read 
such file.

I don't find any documentation about FFM format specification (I just 
find some reference in 
https://www.ffmpeg.org/ffserver.html#FFM_002c-FFM2-formats ) but it 
looks like FFM supports extra_data (AVFMT_GLOBALHEADER, 
CODEC_FLAG_GLOBAL_HEADER, in avformat/ffm_*.c) and the issue is maybe in 
ffv1enc/ffv1dec:
I see in ffmenc.c:
         if (codec->flags & CODEC_FLAG_GLOBAL_HEADER) {
             avio_wb32(pb, codec->extradata_size);
             avio_write(pb, codec->extradata, codec->extradata_size);
         }
but ffv1enc.c does not contain any reference to CODEC_FLAG_GLOBAL_HEADER 
as libx264.c / libx265.c / libfaac.c / ... do.
If don't now enough FFmpeg source code for going further in my 
inspection: it is a headache because FFM2 format looks like to rely on 
CODEC_FLAG_GLOBAL_HEADER (which is not part of FFM2, it is in FFMpeg 
source code) for writing extradata_size in the container, but extradata 
may be present or not present depending of the FFV1 version, and I don't 
see  how to write that in the code: if I force ffv1 for writing 
extradata_size in FFM file in all cases, I break previous FFV1 version 
0-1 files, and if I let as is I can not write extradata_size in FFM file.
Someone for helping?

>
>
>>>   It should make it clear that these are not the only containers
>>> supported but that nearly any container can be used
>> Agreed.
>>
>> Is it OK with:
>>
>> "This configuration record can be placed in any file format
>> supporting configuration records, fitting as much as possible with
>> how the file format uses to store configuration records. The
>> configuration record storage place and NumBytes are currently
>> defined and supported by this specification for the following
>> container formats:"
> ok

Patch updated.
-------------- next part --------------
>From 4c71831de018cfa5279610cace0183e8db80dcee Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Martinez?= <jerome at mediaarea.net>
Date: Thu, 14 May 2015 10:59:48 +0200
Subject: [PATCH] Add more details about the configuration record

Version 2+ of the format has a configuration record which is in
the underlying container track definition.
GlobalHeader definition is split in 2 parts:
- a configuration record part, including more details about how to find
it in AVI and MP4, including the algorithm for how to skip remaining
bits directly in the bitstream definition, including the crc_parity,
- the header part itself, which is the prveious GlobalHeader definition
minus crc_parity.
crc_parity definition is also split and moved in the right subsections:
- configuration_record_crc_parity for the configuration record part
subsection,
- slice_crc_parity for the slice subsection.
---
 ffv1.lyx | 565 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 503 insertions(+), 62 deletions(-)

diff --git a/ffv1.lyx b/ffv1.lyx
index c8bb2b7..41f2015 100644
--- a/ffv1.lyx
+++ b/ffv1.lyx
@@ -893,6 +893,20 @@ Range
 a...b means any value starting from a to b, inclusive.
 \end_layout
 
+\begin_layout Subsection
+Bitstream functions
+\end_layout
+
+\begin_layout Description
+remaing_bits_in_bitstream(
+\begin_inset space ~
+\end_inset
+
+) means the count of remaining bits after the current position in the bitstream.
+ It is computed from the NumBytes value multiplied by 8 minus the count
+ of bits already read by the bitstream parser.
+\end_layout
+
 \begin_layout Section
 General Description
 \end_layout
@@ -2525,31 +2539,49 @@ The same context which is initialized to 128 is used for all fields in the
  header.
 \end_layout
 
+\begin_layout Standard
+Default values at the decoder initialization phase:
+\end_layout
+
+\begin_layout Description
+ConfigurationRecordIsPresent is set to 0.
+\end_layout
+
 \begin_layout Subsection
-Frame
+Configuration Record
+\end_layout
+
+\begin_layout Standard
+In the case of a bitstream with version >= 2, a configuration record is
+ stored in the the underlying container, at the track header level.
+\begin_inset Newline newline
+\end_inset
+
+The size of the configuration record, NumBytes, is supplied by the underlying
+ container.
 \end_layout
 
 \begin_layout Standard
 \begin_inset Tabular
-<lyxtabular version="3" rows="9" columns="2">
+<lyxtabular version="3" rows="7" columns="2">
 <features rotate="0" tabularvalignment="middle">
 <column alignment="left" valignment="top">
 <column alignment="center" valignment="top">
 <row>
-<cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
+<cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
 \begin_inset Text
 
 \begin_layout Plain Layout
-Frame( ) {
+ConfigurationRecord( NumBytes ) {
 \end_layout
 
 \end_inset
 </cell>
-<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
 \begin_inset Text
 
 \begin_layout Plain Layout
-type
+
 \end_layout
 
 \end_inset
@@ -2575,7 +2607,7 @@ type
 \begin_inset space ~
 \end_inset
 
-keyframe
+ConfigurationRecordIsPresent = 1
 \end_layout
 
 \end_inset
@@ -2584,7 +2616,42 @@ keyframe
 \begin_inset Text
 
 \begin_layout Plain Layout
-br
+
+\end_layout
+
+\end_inset
+</cell>
+</row>
+<row>
+<cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+\begin_inset space ~
+\end_inset
+
+
+\begin_inset space ~
+\end_inset
+
+
+\begin_inset space ~
+\end_inset
+
+
+\begin_inset space ~
+\end_inset
+
+GlobalHeader( )
+\end_layout
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+
 \end_layout
 
 \end_inset
@@ -2610,7 +2677,7 @@ br
 \begin_inset space ~
 \end_inset
 
-if( keyframe ) {
+while( remaing_bits_in_bitstream( ) > 32)
 \end_layout
 
 \end_inset
@@ -2661,7 +2728,7 @@ if( keyframe ) {
 \begin_inset space ~
 \end_inset
 
-if( version < 2 )
+reserved
 \end_layout
 
 \end_inset
@@ -2670,14 +2737,14 @@ if( version < 2 )
 \begin_inset Text
 
 \begin_layout Plain Layout
-
+u(1)
 \end_layout
 
 \end_inset
 </cell>
 </row>
 <row>
-<cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
 \begin_inset Text
 
 \begin_layout Plain Layout
@@ -2696,7 +2763,292 @@ if( version < 2 )
 \begin_inset space ~
 \end_inset
 
+configuration_record_crc_parity
+\end_layout
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+u(32)
+\end_layout
+
+\end_inset
+</cell>
+</row>
+<row>
+<cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
+\begin_inset Text
 
+\begin_layout Plain Layout
+}
+\end_layout
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+
+\end_layout
+
+\end_inset
+</cell>
+</row>
+</lyxtabular>
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Description
+configuration_record_crc_parity 32 bits that are choosen so that the configurati
+on record as a whole has a crc remainder of 0.
+\begin_inset Newline newline
+\end_inset
+
+This is equivalent to storing the crc remainder in the 32-bit parity.
+\begin_inset Newline newline
+\end_inset
+
+The CRC generator polynom used is the standard IEEE CRC polynom (0x104C11DB7)
+ with initial value 0.
+\end_layout
+
+\begin_layout Standard
+This configuration record can be placed in any file format supporting configurat
+ion records, fitting as much as possible with how the file format uses to
+ store configuration records.
+ The configuration record storage place and NumBytes are currently defined
+ and supported by this specification for the following container formats:
+\end_layout
+
+\begin_layout Subsubsection
+In AVI File Format
+\end_layout
+
+\begin_layout Standard
+The Configuration Record extends the stream format chunk (
+\begin_inset Quotes eld
+\end_inset
+
+AVI
+\begin_inset space ~
+\end_inset
+
+
+\begin_inset Quotes eld
+\end_inset
+
+, 
+\begin_inset Quotes eld
+\end_inset
+
+hdlr
+\begin_inset Quotes erd
+\end_inset
+
+, 
+\begin_inset Quotes eld
+\end_inset
+
+strl
+\begin_inset Quotes erd
+\end_inset
+
+, 
+\begin_inset Quotes eld
+\end_inset
+
+strf
+\begin_inset Quotes erd
+\end_inset
+
+) with the ConfigurationRecord bistream.
+\begin_inset Newline newline
+\end_inset
+
+See 
+\begin_inset CommandInset citation
+LatexCommand cite
+key "AVI"
+
+\end_inset
+
+ for more information about chunks.
+\end_layout
+
+\begin_layout Description
+NumBytes is defined as the size, in bytes, of the strf chunk indicated in
+ the chunk header minus the size of the stream format structure.
+\end_layout
+
+\begin_layout Subsubsection
+In ISO/IEC 14496-12 (MP4 File Format)
+\end_layout
+
+\begin_layout Standard
+The Configuration Record extends the sample description box (
+\begin_inset Quotes eld
+\end_inset
+
+moov
+\begin_inset Quotes erd
+\end_inset
+
+, 
+\begin_inset Quotes eld
+\end_inset
+
+trak
+\begin_inset Quotes erd
+\end_inset
+
+, 
+\begin_inset Quotes eld
+\end_inset
+
+mdia
+\begin_inset Quotes erd
+\end_inset
+
+, 
+\begin_inset Quotes eld
+\end_inset
+
+minf
+\begin_inset Quotes erd
+\end_inset
+
+, 
+\begin_inset Quotes eld
+\end_inset
+
+stbl
+\begin_inset Quotes erd
+\end_inset
+
+, 
+\begin_inset Quotes eld
+\end_inset
+
+stsd
+\begin_inset Quotes erd
+\end_inset
+
+) with a 
+\begin_inset Quotes eld
+\end_inset
+
+glbl
+\begin_inset Quotes erd
+\end_inset
+
+ box which contains the ConfigurationRecord bitstream.
+\begin_inset Newline newline
+\end_inset
+
+See 
+\begin_inset CommandInset citation
+LatexCommand cite
+key "ISO14496_12"
+
+\end_inset
+
+ for more information about boxes.
+\end_layout
+
+\begin_layout Description
+NumBytes is defined as the size, in bytes, of the 
+\begin_inset Quotes eld
+\end_inset
+
+glbl
+\begin_inset Quotes erd
+\end_inset
+
+ box indicated in the box header minus the size of the box header.
+\end_layout
+
+\begin_layout Subsubsection
+In NUT File Format
+\end_layout
+
+\begin_layout Standard
+The codec_specific_data element (in 
+\begin_inset Quotes eld
+\end_inset
+
+stream_header
+\begin_inset Quotes erd
+\end_inset
+
+ packet) contains the ConfigurationRecord bitstream.
+\begin_inset Newline newline
+\end_inset
+
+See 
+\begin_inset CommandInset citation
+LatexCommand cite
+key "NUT"
+
+\end_inset
+
+ for more information about elements.
+\end_layout
+
+\begin_layout Description
+NumBytes is defined as the size, in bytes, of the codec_specific_data element
+ as indicated in the 
+\begin_inset Quotes eld
+\end_inset
+
+length
+\begin_inset Quotes erd
+\end_inset
+
+ field of codec_specific_data
+\end_layout
+
+\begin_layout Subsection
+Frame
+\end_layout
+
+\begin_layout Standard
+\begin_inset Tabular
+<lyxtabular version="3" rows="7" columns="2">
+<features rotate="0" tabularvalignment="middle">
+<column alignment="left" valignment="top">
+<column alignment="center" valignment="top">
+<row>
+<cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+Frame( ) {
+\end_layout
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+type
+\end_layout
+
+\end_inset
+</cell>
+</row>
+<row>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
 \begin_inset space ~
 \end_inset
 
@@ -2712,7 +3064,26 @@ if( version < 2 )
 \begin_inset space ~
 \end_inset
 
+keyframe
+\end_layout
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\begin_layout Plain Layout
+br
+\end_layout
+
+\end_inset
+</cell>
+</row>
+<row>
+<cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
 
+\begin_layout Plain Layout
 \begin_inset space ~
 \end_inset
 
@@ -2728,7 +3099,7 @@ if( version < 2 )
 \begin_inset space ~
 \end_inset
 
-FrameHeader01( )
+if( keyframe && !ConfigurationRecordIsPresent)
 \end_layout
 
 \end_inset
@@ -2744,7 +3115,7 @@ FrameHeader01( )
 </cell>
 </row>
 <row>
-<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+<cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
 \begin_inset Text
 
 \begin_layout Plain Layout
@@ -2763,7 +3134,27 @@ FrameHeader01( )
 \begin_inset space ~
 \end_inset
 
-}
+
+\begin_inset space ~
+\end_inset
+
+
+\begin_inset space ~
+\end_inset
+
+
+\begin_inset space ~
+\end_inset
+
+
+\begin_inset space ~
+\end_inset
+
+
+\begin_inset space ~
+\end_inset
+
+FrameHeader01( )
 \end_layout
 
 \end_inset
@@ -3639,7 +4030,7 @@ u(8)
 \begin_inset space ~
 \end_inset
 
-crc_parity
+slice_crc_parity
 \end_layout
 
 \end_inset
@@ -3849,6 +4240,20 @@ reserved for future use
 
 \end_layout
 
+\begin_layout Description
+slice_crc_parity 32 bits that are choosen so that the slice as a whole has
+ a crc remainder of 0.
+\begin_inset Newline newline
+\end_inset
+
+This is equivalent to storing the crc remainder in the 32-bit parity.
+\begin_inset Newline newline
+\end_inset
+
+The CRC generator polynom used is the standard IEEE CRC polynom (0x104C11DB7)
+ with initial value 0.
+\end_layout
+
 \begin_layout Subsection
 Slice Header
 \end_layout
@@ -5321,7 +5726,7 @@ Version 2 and later files use a global header and a per frame header.
 
 \begin_layout Standard
 \begin_inset Tabular
-<lyxtabular version="3" rows="29" columns="2">
+<lyxtabular version="3" rows="28" columns="2">
 <features rotate="0" tabularvalignment="middle">
 <column alignment="left" valignment="top">
 <column alignment="center" valignment="top">
@@ -6496,41 +6901,6 @@ ur
 </cell>
 </row>
 <row>
-<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
-\begin_inset Text
-
-\begin_layout Plain Layout
-\begin_inset space ~
-\end_inset
-
-
-\begin_inset space ~
-\end_inset
-
-
-\begin_inset space ~
-\end_inset
-
-
-\begin_inset space ~
-\end_inset
-
-crc_parity
-\end_layout
-
-\end_inset
-</cell>
-<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
-\begin_inset Text
-
-\begin_layout Plain Layout
-u(32)
-\end_layout
-
-\end_inset
-</cell>
-</row>
-<row>
 <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
 \begin_inset Text
 
@@ -6568,6 +6938,16 @@ Each version is incompatible with others versions: decoders SHOULD reject
 \begin_inset Newline newline
 \end_inset
 
+Decoders SHOULD reject a file with version < 2 && ConfigurationRecordIsPresent
+ == 1.
+\begin_inset Newline newline
+\end_inset
+
+Decoders SHOULD reject a file with version >= 2 && ConfigurationRecordIsPresent
+ == 0.
+\begin_inset Newline newline
+\end_inset
+
 
 \begin_inset Tabular
 <lyxtabular version="3" rows="6" columns="2">
@@ -7744,16 +8124,6 @@ reserved for future use
 
 \end_layout
 
-\begin_layout Description
-crc_parity 32bit that are choosen so that the global header as a whole or
- slice as a whole has a crc remainder of 0.
- This is equivalent to storing the crc remainder in the 32bit parity.
- The CRC generator polynom used is the standard IEEE CRC polynom (0x104C11DB7)
- with initial value 0.
- The compressed bitstream is padded so that the 32bit crc end in the last
- 4 bytes.
-\end_layout
-
 \begin_layout Subsection
 Quantization Tables
 \end_layout
@@ -9002,6 +9372,77 @@ key "RangeCoder"
  held in Southampton July 24-27 1979."
 \end_layout
 
+\begin_layout Bibliography
+\labelwidthstring References
+\begin_inset CommandInset bibitem
+LatexCommand bibitem
+label "AVI"
+key "AVI"
+
+\end_inset
+
+AVI RIFF File Format 
+\begin_inset Flex URL
+status collapsed
+
+\begin_layout Plain Layout
+
+https://msdn.microsoft.com/en-us/library/windows/desktop/dd318189%28v=vs.85%29.aspx
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Bibliography
+\labelwidthstring References
+\begin_inset CommandInset bibitem
+LatexCommand bibitem
+label "ISO/IEC 14496-12"
+key "ISO14496_12"
+
+\end_inset
+
+Information technology — Coding of audio-visual objects — Part 12: ISO base
+ media file format 
+\begin_inset Flex URL
+status collapsed
+
+\begin_layout Plain Layout
+
+http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=619
+88
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Bibliography
+\labelwidthstring References
+\begin_inset CommandInset bibitem
+LatexCommand bibitem
+label "NUT"
+key "NUT"
+
+\end_inset
+
+NUT Open Container Format 
+\begin_inset Flex URL
+status collapsed
+
+\begin_layout Plain Layout
+
+http://www.ffmpeg.org/~michael/nut.txt
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
 \begin_layout Section
 Copyright
 \end_layout
-- 
1.9.5.msysgit.1



More information about the ffmpeg-devel mailing list