RealAudio file header

Discussion in 'Computer Information' started by Ed, Jun 30, 2005.

  1. Ed

    Ed Guest

    REAL AUDIO FILE


    An .RA audio file is composed of -

    (a) The File Header (18 bytes)

    (b) The following 5 blocks:
    1. Properties [PROP]
    2. Media Properties [MDPR]
    3. Content Description [CONT]
    4. Data [DATA]
    5. Index [INDX] (optional)

    * * *

    HEADER SECTION:

    File Header -
    Includes RealMedia file format [RMFF] tag = .RMF [Real Media File]

    Header Blocks -
    PROP Properties block
    MDPR Media Properties block (incl. MIME type)
    CONT Content Description block [Title / Author / Copyright fields]
    [NB: The order of the Header blocks is arbitrary]


    DATA SECTION:

    DATA Data block (aka Data chunk) [Audio data]
    - Data header
    - Data Packets (multiple) [Audio packets]

    INDX Index block [located at the END of the file]
    - Index header
    - Index Records (multiple)


    Notes:
    1. The file MUST begin with the File Header.
    2. The Header Blocks (PROP, MDPR & CONT) can be in any order.
    3. The Header Blocks must preceed the DATA block, as otherwise
    the file will be incapable of being streamed over the internet
    (information in the Header Blocks is needed to play the file).
    4. All blocks are required except the INDX block. A live streaming
    file is not capable of seeking, so does not need an Index.
    [NB: It's convenient to have an Index in a non-live streaming file]

    -----------------------------------------------------------------------

    HEADER SECTION


    File Header block (First 18 bytes):

    Bytes Name Description
    ----- ---- -----------
    4 Object ID ID of file [MUST be .RMF]
    4 Size Size of File Header block (hex)
    (NB: Always 18 bytes [12h])
    2 Object version The RealMedia File Format (RMFF) version used
    to encode the file (NB: Always version zero)
    4 File version The PN version of the file
    (NB: This can be either zero or 1)
    [PN version: MIME type is audio/x-pn-realaudio]
    4 Num headers The number of "headers" [blocks] which
    follow, and which make up the file
    (NB: Always 5 [PROP, MDPR, CONT, DATA, INDX])


    Properties block [PROP]:

    Bytes Name Description
    ----- ---- -----------
    4 Object ID ID of block [MUST be PROP]
    4 Size Size of PROP block (in hex)
    (NB: Always 50 bytes [32 hex])
    2 Object version The RealMedia File Format (RMFF) version used
    to encode the file (NB: Always version zero)
    4 Max bit rate The maximum bitrate needed to play the file
    successfully over a dial-up connection (in hex)
    (NB: AC44 = 44,100 [bps] - standard BBC7 rate)
    4 Avg bit rate The average bitrate needed to play the file
    successfully over a dial-up connection (in hex)
    (NB: A BBC7 file is normally AC44 [44,100 bps])
    4 Max packet size Maximum packet size (eg 640 bytes [280 hex])
    (NB: Size of each Data packet - see DATA block)
    [NB: Refers to size alloted for actual data
    (excluding the 12 bytes of the packet header)]
    4 Avg packet size Average packet size (eg 640 bytes [280 hex])
    (NB: MUST be same as Maximum packet size)
    4 Num packets Number of data packets in the DATA block
    (NB: MUST be same as "Num packets" in DATA)
    (NB: File size (in bytes) less size of Header
    Section & Index block, divided by Packet Size)
    (NB: Multiply by 116.09375 to convert to Milli)
    (NB: 1 packet = 116.09375 millisecs;
    30 mins = 15,504 packets [3C90 hex])
    [NB: RealPlayer incorrectly reports a shortened
    audio duration if this setting is corrupted]
    4 Duration Duration of the audio stream, in milliseconds
    (NB: Divide by 60,000 to convert to Minutes)
    (NB: Divide by 116.09375 to convert to Packets)
    (NB: 30 mins = 1,800,000 millisecs [1B7740h])
    [NB: RealPlayer incorrectly reports a shortened
    audio duration if this setting is corrupted]
    4 Preroll Duration of buffering before starting playback,
    in milliseconds [NB: BBC7 is usually 1222 hex]
    4 Index offset Address of start of INDEX block (in hex)
    (NB: Identifies start point of INDX block)
    4 Data offset Address of start of DATA block (in hex)
    (NB: Identifies start point of DATA block)
    2 Num streams Number of streams (1=Audio, 2=Audio+Video)
    2 Flags Sets the characteristics of the file:
    0000 = No flag [Usual state for a BBC file]
    0001 = Save enabled [Can be saved to disk]
    0002 = Perfect-play enabled [Extra buffering]
    0004 = Live broadcast [Seeking disabled]
    0008 = Download enabled [Can be downloaded]
    0009 = Allow Record & Allow Download
    [NB: Flags 0001, 0002 & 0004 are only for
    live broadcasts]
    [50 bytes]


    Media Properties block [MDPR]:

    Bytes Name Description
    ----- ---- -----------
    4 Object ID ID of block [MUST be MDPR]
    4 Size Size of MDPR block (in hex)
    (NB: Usual BBC7 size = 205 bytes [CD hex])
    (NB: Old BBC7 files had a size of 187 [BB hex])
    2 Object version The RealMedia File Format (RMFF) version used
    to encode the file (NB: Always version zero)
    2 Stream Number Stream ID number (NB: Always Stream 0)
    [NB: An audio file has only a single stream]
    [NB: If there are two streams (Audio & Video)
    there will be two MDPR blocks, one for each]
    4 Max bit rate The maximum bitrate needed to play the file
    successfully over a dial-up connection (in hex)
    (NB: AC44 = 44,100 [bps] - standard BBC7 rate)
    4 Avg bit rate The average bitrate needed to play the file
    successfully over a dial-up connection (in hex)
    (NB: A BBC7 file is normally AC44 [44,100 bps])
    [This setting controls the "Clip Bandwidth"
    displayed by View > Statistics > Advanced]
    4 Max pack size Largest packet size (640 [280h]) [DATA packet]
    (NB: Must agree with Max packet size in PROP)
    [NB: This is the space alloted for packet data,
    excluding the space taken by the packet header]
    4 Avg pack size Average packet size (640 [280h])
    (NB: Must agree with Avg packet size in PROP)
    (NB: Must also agree with Max pack size, above)
    4 Start time Starting time of audio stream (NB: Always zero)
    [Audio counter always starts at zero minutes]
    [NB: Not a particularly useful setting]
    4 Preroll Duration of buffering, in milliseconds
    (NB: Need NOT match Preroll duration in PROP)
    [NB: Commonly known as "Buffer Time"]
    [BBC7 usually buffers 4.642 secs (1222 hex)]
    4 Duration Duration of the audio stream, in milliseconds
    (NB: MUST agree with Duration in PROP)
    (NB: 30 mins = 1,800,000 millisec [1B7740 hex])
    1 Stream name size - Length of stream name string, in bytes (hex)
    n Stream name Name of stream (length as above)
    (NB: 12 bytes [0C hex] = "Audio Stream")
    (NB: 45 bytes [2D hex] =
    audio/x-pn-multirate-realaudio logical stream)
    1 MIME type size Length of MIME type string, in bytes (hex)
    n MIME type The file's MIME type (length as above)
    (NB: 35 bytes [23 hex] =
    audio/x-pn-multirate-realaudio-live)
    (NB: 20 bytes [14 hex] = audio/x-pn-realaudio
    [the new BBC7 type: universally compatible])
    4 Type-spe. size Length of type-specific data section, in bytes
    (NB: 5E hex = 94 bytes)
    n Type-spe. data Type-specific data (length as above)
    (NB: Defined by MIME type [incl .ra, genrcook])

    Bytes Description
    ----- -----------
    3 File type [MUST be .ra]
    5 ?
    3 File type [MUST be .ra]
    37 ?
    4 Bitrate (NB: AC44 hex = 44,100) (Max?)
    4 Bitrate (NB: AC44 hex = 44,100) (Avg?)
    6 ?
    8 File format [MUST be "genrcook"]
    24 ?
    --
    94 [= 94 bytes]

    NB: Data used by the data-type renderer to
    initialize itself in order to process
    the media stream or file.


    Content Description block [CONT]:

    Bytes Name Description
    ----- ---- -----------
    4 Object ID ID of block [MUST be CONT]
    4 Size Size of CONT block (in hex)
    (Old BBC7 size = 64 bytes [40 hex])
    (New BBC7 size = 91 bytes [5B hex])
    2 Object version Version number (NB: Always zero)
    2 Title size Length of Title description, in bytes (hex)
    n Title Title description [BBC7: 27 bytes (1B hex)]
    (NB: ASCII text-string; no bytes are alloted
    to this if title size [above] is nil)
    2 Author size Length of Author description, in bytes (hex)
    n Author Author description [BBC7: 5 bytes (="BBC 7")]
    (NB: ASCII text-string; no bytes are alloted
    to this if author size [above] is nil)
    2 Copyright size Length of Copyright description, in bytes (hex)
    n Copyright Copyright description [BBC7: 41 bytes (29 hex)]
    (NB: ASCII text-string; no bytes are alloted
    to this if copyright size [above] is nil)
    2 Comment size Length of Comment, in bytes (hex)
    (NB: For BBC7 files, always zero)
    n Comment Comment (NB: Actually, no bytes are alloted
    to this, because comment size [above] is nil)
    [BBC7 file: 91 bytes]


    * * *

    Notes on the Header Blocks:

    1. The Header Blocks (PROP, MDPR & CONT) can be in any order.

    2. The Header Blocks must preceed the DATA block, as otherwise
    the file will be incapable of being streamed over the Internet
    (as some of the information in the Header Blocks is essential
    for interpreting the DATA block, eg Stream Number & MIME-type).

    -----------------------------------------------------------------------

    DATA SECTION


    Data block [DATA]:

    Data header (First 18 bytes) -

    Bytes Name Description
    ----- ---- -----------
    4 Object ID ID of block [MUST be DATA]
    4 Size Size of DATA block (in hex) [NB: File size
    in bytes, less size of Header & Index blocks]
    (NB: NOT packet size [set in PROP])
    2 Object version Version number (NB: Always zero)
    [Version of RealMedia File Format (RMFF) used]
    4 Num packets Number of data packets in file
    (NB: MUST be the same as "Num packets" in PROP)
    [NB: 1 packet = 116.09375 millisecs of audio
    => 30 mins = 15,504 packets (3C90 hex)]
    4 Next data Location in file of next DATA block
    (NB: Always zero - there is only one DATA
    block in a file, if file smaller than 4.2 GB)


    Data Packets (Multiple packets, 652 bytes each) -

    Bytes Name Description
    ----- ---- -----------
    2 Object ID ID of packet [MUST be 0000] (Marks pckt start)
    2 Length Length of packet, in bytes [652 bytes (028Ch)]
    2 Stream number Stream ID number (NB: Always Stream 0)
    [NB: An audio file has only a single stream]
    4 Timestamp Timestamp of packet, in milliseconds
    (NB: Timestamp of 1st packet MUST be zero;
    increases by 116 millisecs with each packet)
    [Real increase is 116.09375 millisecs, rounded]
    1 Reserved This byte is not used (always zero)
    1 Flag Sets the characteristics of the packet:
    00 = Standard (No flag)
    01 = Reliable flag
    02 = Keyframe flag [NB: Every 16th packet]
    [NB: The packet is a key frame, or
    marks a boundary in the data stream
    (eg the first and last packets)]
    n Data Audio data (640 bytes in a BBC7 file)

    NB: 12 bytes for the packet's "header", plus 640 bytes for data, equals
    652 bytes in total (for new BBC7 files; non-BBC files may be different)

    NB: Old BBC7 files suffered audio problems because the packet size was
    only 640 bytes, thus with 12 bytes taken up by the packet header only
    628 bytes were available for data; new BBC7 files increase the packet
    size by 12 bytes (to 652 bytes) to compensate for this.

    NB: Video files -
    A file can contain more than one media stream (eg an Audio stream and
    a Video stream); Data Packets for each stream are intermixed. Adjacent
    packets will have identical timestamps, but be differentiated by their
    stream numbers (eg Audio packets = stream 0, Video packets = stream 1).
    [The stream number is used to associate the Data Packet with the
    appropriate Media Properties (MDPR) block]


    Index block [INDX]:

    Index header (First 20 bytes) -

    Bytes Name Description
    ----- ---- -----------
    4 Object ID ID of block [MUST be INDX]
    4 Size Size of INDX block, in bytes (hex)
    (NB: Always 20 bytes [14 hex])
    2 Object version Version number (NB: Always zero)
    4 Num indices Number of Index Records ("Indices") in
    the INDX block (hex) [14 bytes each]
    (NB: 1 Index Record for every 1857.5 millisecs
    => 969 Index Records [3C9h] in a 30 min file)
    2 Stream number Stream ID number (NB: Always Stream 0)
    [NB: An audio file has only a single stream]
    [NB: This implies, incorrectly, that in a
    Video file there is more than one INDX block]
    4 Next index Location of next INDX block
    (NB: Always zero - there is only one INDX
    block in a file, if file smaller than 4.2 GB)
    [20 bytes]


    Index Records (Multiple records, 14 bytes each) -

    Bytes Name Description
    ----- ---- -----------
    2 Object version Version number (NB: Always zero [0000h])
    4 Timestamp The start time associated with this Record
    (expressed in thousandths of a second)
    [NB: The first Record MUST be zero [0000 hex];
    each Record then increments by 1.8575 seconds]
    4 Offset The start point in the file of the Data
    associated with this Record
    (NB: Increases by 7,632 bytes [1DD0 hex] each)
    (NB: In new BBC7 files it increases by 10,432
    [28C0 hex] for each Index Record, because each
    Data Packet is 652 bytes & each Index Record
    covers 16 packets [652 x 16 = 10,432 bytes])
    [NB: By associating the offset from the start
    of the file with a timestamp (above), it is
    possible to find locations in the file using
    measurements of time]
    [NB: In a Video file, this offset MUST point
    to a Keyframe; not so in an Audio file]
    4 Packet count The Packet count associated with this Record
    (ie the number of Data Packets that would be
    heard if the file was played from the beginning
    up to this offset)
    (NB: The first Record MUST be zero [0000 hex];
    then each Record increases by 16 [10 hex]
    ie each Index Record covers 16 Data Packets)
    [NB: 16 Data Packets = 1.8575 seconds]
    [NB: The packet count is useful when editing
    or repairing a file]

    NB: The first Index Record starts at byte 21 (decimal) in the INDX
    block (because the Index header is 20 bytes).

    NB: Although the blocks can be placed in the file in any order, in
    practice the INDX block is invariably the final block so as to enable
    re-indexing the file if required (due to a fault, or during editing).

    * * *

    Notes on the Index block:

    1. All blocks are required except the Index block.

    2. The only purpose of the Index is to make the file seekable
    (without an index, the file will still play sequentially).
    [The Index's function is to enable random access to the file]

    3. A live broadcast, not being seekable, will not have an INDX block.
    Ed, Jun 30, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marius
    Replies:
    0
    Views:
    1,012
    Marius
    Aug 27, 2003
  2. Joel Rubin

    Great RealAudio reading for American Independence Day

    Joel Rubin, Jul 2, 2003, in forum: Computer Support
    Replies:
    0
    Views:
    951
    Joel Rubin
    Jul 2, 2003
  3. You Are Right

    DLL and Header file

    You Are Right, Sep 18, 2003, in forum: Computer Support
    Replies:
    3
    Views:
    637
    tRuthvalue
    Nov 19, 2003
  4. Ed

    Analysis of RealAudio file header

    Ed, Oct 8, 2004, in forum: Computer Information
    Replies:
    2
    Views:
    900
    jason
    Oct 9, 2004
  5. Ed

    Analysis of RealAudio file header

    Ed, Jun 30, 2005, in forum: Computer Information
    Replies:
    3
    Views:
    760
Loading...

Share This Page