日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

多媒体文件格式之RMVB

發(fā)布時間:2025/3/21 编程问答 66 豆豆
生活随笔 收集整理的這篇文章主要介紹了 多媒体文件格式之RMVB 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

[時間:2016-07] [狀態(tài):Open]

RM/RMVB是Real公司私有的封裝格式,常見的后綴形式是rm、ra、rmvb。
通常封裝的都是real轉(zhuǎn)悠的編碼格式,比如音頻中的sipro、cook、atrc、ralf、raac,視頻的RV10、RV20、RV30、RV40。

0. 學習多媒體容器格式的目的

主要是為了回答以下問題:

  • 該容器中數(shù)據(jù)是如何組織的?
  • 該容器包含哪些編碼格式的數(shù)據(jù)?這些數(shù)據(jù)是如何存儲的?
  • 該容器包含哪些元數(shù)據(jù)信息?包含哪些節(jié)目信息?
  • 對于支持多節(jié)目的容器格式,如何找到對應(yīng)的音頻流、視頻流、字幕流?
  • 如何確定該容器的節(jié)目播放時長?
  • 如何從該容器中提取音頻、視頻、字幕數(shù)據(jù),并交給解碼器解碼,有時間戳否?
  • 該容器是否支持seek?有哪些輔助信息?
  • 是否支持直接流化?
  • 哪里可以找到該容器格式最標準的文檔資料?
  • 有哪些可用的工具,方便分析容器格式異常或者錯誤?
  • 1. RM文件格式概述

    RealMedia File Format(RMFF)是一種基于TAG的文件格式,每個TAG有四個字節(jié)(FOURCC)用于標識元素類型。
    RM文件的基本構(gòu)成塊是chunk。每個chunk構(gòu)成如下:

    ==============ID(FOURCC) --------------size(4 byte) --------------data([size]) ==============

    每個chunk的ID決定了data域如何解析。頂層的chunk可以包含sub-chunk。
    一個常見的chunk構(gòu)成如下圖:

    通常RM文件有三部分構(gòu)成:header section、data section、index section。每個section都是多個chunk構(gòu)成,具體可以參考下圖:

    后續(xù)部分詳細介紹各個section。

    2. RM文件頭(header section)

    RMFF是基于TAG的格式,在header section中各個chunk出現(xiàn)的順序并不是固定的,但RealMedia File Header(文件頭)必須是第一個chunk。其他后續(xù)chunk包括:Properties Header(屬性頭)、Media Properties Header(媒體屬性頭)、Content Description Header(內(nèi)容描述頭)。

    RealMedia文件頭

    RealMedia文件頭通常用于識別文件格式,并且每個RM文件只有一個文件頭。其中包含的字段如下:

    RealMedia_File_Header {UINT32 object_id;UINT32 size;UINT16 object_version;if ((object_version == 0) || (object_version == 1)){UINT32 file_version;UINT32 num_headers;} }

    各字段具體含義見下表:

    fieldtypedescription
    object_idUINT32The unique object ID for a RealMedia File (.RMF). All RealMedia files begin with this identifier.
    sizeUINT32The size of the RealMedia header section in bytes.
    object_versionUINT16The version of the RealMedia File Header object. All files created according to this specification have an object_version number of 0 (zero) or 1.
    file_versionUINT32The version of the RealMedia file. This member is present on all RealMedia_File_Header objects with an object_version of 0 (zero) or 1.
    num_headersUINT32The number of headers in the header section that follow the RealMedia File Header. This member is present on all RealMedia_File_Header objects with an object_version of 0 (zero) or 1.

    注:后續(xù)表格中將不會出現(xiàn)關(guān)于object_version的限制,具體建議參考標準文檔。

    RM屬性頭

    Properties Header描述RMF的一般媒體屬性。
    RM系統(tǒng)會參考這個對象中的數(shù)據(jù)處理RM文件或流中的數(shù)據(jù)。在RMF中只有一個屬性頭。其中包含的字段如下:

    Properties_Header {UINT32 object_id;UINT32 size;UINT16 object_version;if (object_version == 0){UINT32 max_bit_rate;UINT32 avg_bit_rate;UINT32 max_packet_size;UINT32 avg_packet_size;UINT32 num_packets;UINT32 duration;UINT32 preroll;UINT32 index_offset;UINT32 data_offset;UINT16 num_streams;UINT16 flags;} }

    各字段具體含義見下表:

    fieldtypedescription
    object_idUINT32The unique object ID for a Properties Header ('PROP').
    sizeUINT32The 32-bit size of the Properties Header in bytes.
    object_versionUINT16The version of the RealMedia File Header object. All files created according to this specification have an object_version number of 0 (zero).
    max_bit_rateUINT32The maximum bit rate required to deliver this file over a network.
    avg_bit_rateUINT32The average bit rate required to deliver this file over a network.
    max_packet_sizeUINT32The largest packet size (in bytes) in the media data.
    avg_packet_sizeUINT32The average packet size (in bytes) in the media data.
    num_packetsUINT32The number of packets in the media data.
    durationUINT32The duration of the file in milliseconds.
    prerollUINT32The number of milliseconds to prebuffer before starting playback.
    index_offsetUINT32The offset in bytes from the start of the file to the start of the index header object. This value can be 0 (zero), which indicates that no index chunks are present in this file.
    data_offsetUINT32The offset in bytes from the start of the file to the start of the Data Section.
    Note: There can be a number of Data_Chunk_Headers in a RealMedia file. The data_offset value specifies the offset in bytes to the first Data_Chunk_Header. The offsets to the other Data_Chunk_Headers can be derived from the next_data_header field in a Data_Chunk_Header.
    num_streamsUINT16The total number of media properties headers in the main headers section.
    flagsUINT16

    RM媒體屬性頭(Media Properties Header)

    Media Properties Header描述了RM文件中每個流的特定媒體屬性。每一個流都有一個媒體屬性頭。其中包含的字段如下:

    Media_Properties_Header {UINT32 object_id;UINT32 size;UINT16 object_version;if (object_version == 0){UINT16 stream_number;UINT32 max_bit_rate;UINT32 avg_bit_rate;UINT32 max_packet_size;UINT32 avg_packet_size;UINT32 start_time;UINT32 preroll;UINT32 duration;UINT8 stream_name_size;UINT8[stream_name_size] stream_name;UINT8 mime_type_size;UINT8[mime_type_size] mime_type;UINT32 type_specific_len;UINT8[type_specific_len] type_specific_data;} }

    各字段含義如下表:

    fieldtypedescription
    object_idUINT32The unique object ID for a Media Properties Header ("MDPR").
    sizeUINT32The size of the Media Properties Header in bytes.
    object_versionUINT16The version of the Media Properties Header object.
    stream_numberUINT16The stream_number (synchronization source identifier) is a unique value that identifies a physical stream. Every data packet that belongs to a physical stream contains the same STREAM_NUMBER. The STREAM_NUMBER enables a receiver of multiple physical streams to distinguish which packets belong to each physical stream.
    max_bit_rateUINT32The maximum bit rate required to deliver this stream over a network.
    avg_bit_rateUINT32The average bit rate required to deliver this stream over a network.
    max_packet_sizeUINT32The largest packet size (in bytes) in the stream of media data.
    avg_packet_sizeUINT32The average packet size (in bytes) in the stream of media data.
    start_timeUINT32The time offset in milliseconds to add to the time stamp of each packet in a physical stream.
    prerollUINT32The time offset in milliseconds to subtract from the time stamp of each packet in a physical stream.
    durationUINT32The duration of the stream in milliseconds.
    stream_name_sizeUINT8The length of the following stream_name member in bytes.
    stream_nameUINT8[]A nonunique alias or name for the stream. This size of this member is variable.
    mime_type_sizeUINT8The length of the following mime_type field in bytes.
    mime_typeUINT8[]A nonunique MIME style type/subtype string for data associated with the stream.This size of this member is variable.
    type_specific_lenUINT32The length of the following type_specific_data in bytes. The type_specific_data is typically used by the data type renderer to initialize itself in order to process the physical stream.
    type_specific_dataUINT8[]The type_specific_data is typically used by the data type renderer to initialize itself in order to process the physical stream.The size of this member is variable.

    RM邏輯流屬性頭

    RM中可以包含多節(jié)目流,一般RM文件中通過RM邏輯流(logical stream)將多個物理流構(gòu)成。邏輯流包含以下信息:有哪些物理流構(gòu)成的,以及一些用于識別邏輯流的屬性(比如語言、包組等)。
    邏輯流也是保存在Media Properties Header中,其mime type的前綴是"logical-"。舉個例子,一個RealAudio流(physical stream)的mime type是audio/x-pn-multirate-realaudio,那么對應(yīng)的邏輯流(logical stream)的mime type是logical-audio/x-pn-multirate-realaudio。下圖是一個邏輯流的構(gòu)成示例:

    對于邏輯流對應(yīng)的屬性頭,其type_specific_data字段包含LogicalStream結(jié)構(gòu)。
    文件中也有一個特殊的邏輯流,其MIME type是logical-fileinfo,包含整個文件的信息,而且只能有一個類似的文件。

    LogicalStream Structure

    其中包含的字段如下:

    LogicalStream {ULONG32 size;UINT16 object_version;if (object_version == 0){UINT16 num_physical_streams;UINT16 physical_stream_numbers[num_physical_streams];ULONG32 data_offsets[num_physical_streams];UINT16 num_rules;UINT16 rule_to_physical_stream_number_map[num_rules];UINT16 num_properties;NameValueProperty properties[num_properties];} };

    各字段含義如下表:

    fieldtypedescription
    sizeUINT32The size of the LogicalStream structure in bytes.
    object_versionUINT16The version of the LogicalStream structure.
    num_physical_streamsUINT16The number of physical streams that make up this logical stream. The physical stream numbers are stored in a list immediately following this field. These physical stream numbers refer to the stream_number field found in the Media Properties Object for each physical stream belonging to this logical stream.
    physical_stream_numbersUINT16[]The list of physical stream numbers that comprise this logical stream. The size of this structure member is variable.
    data_offsetsUINT32[]The list of data offsets indicating the start of the data section for each physical stream. The size of this structure member is variable.
    num_rulesUINT16The number of ASM rules for the logical stream. Each physical stream in the logical stream has at least one ASM rule associated with it or it will never get played. The mapping of ASM rule numbers to physical stream numbers is stored in a list immediately following this member. These physical stream numbers refer to the stream_number field found in the Media Properties Object for each physical stream belonging to this logical stream.
    rule_to_physical_stream_mapUINT16[]The list of physical stream numbers that map to each rule. Each entry in the map corresponds to a 0-based rule number. The value in each entry is set to the physical stream number for the rule. For example:
    rule_to_physical_stream_map[0] = 5
    This example means physical stream 5 corresponds to rule 0. All of the ASM rules referenced by this array are stored in the first name-value pair of this logical stream which must be called "ASMRuleBook" and be of type "string". Each rule is separated by a semicolon.
    The size of this structure member is variable.
    num_propertiesUINT16The number of NameValueProperty structures contained in this structure. These name/value structures can be used to identify properties of this logical stream (for example, language).
    propertiesNameValueProperty[]The list of NameValueProperty structures (see NameValueProperty Structure below for more details). As mentionied above, it is required that the first name-value pair be a string named "ASMRuleBook" and contain the ASM rules for this logical stream. The size of this structure member is variable.

    NameValueProperty Structure

    其中包含的字段如下:

    NameValueProperty {ULONG32 size;UINT16 object_version;if (object_version == 0){UINT8 name_length;UINT8 name[namd_length];INT32 type;UINT16 value_length;UINT8 value_data[value_length];} }

    各字段含義如下表:

    fieldtypedescription
    sizeUINT32The size of the NameValueProperty structure in bytes.
    object_versionUINT16The version of the NameValueProperty structure.
    name_lengthUINT8The length of the name data.
    nameUINT8[]The name string data.
    typeUINT32The type of the value data. This member can take on one of three values (any other value is undefined), as shown in the following table:
    =0 32-bit unsigned integer property
    =1 buffer
    =2 string
    value_lengthUINT16The length of the value data.
    value_dataUINT8[]The value data.

    RM內(nèi)容描述頭(Content Description Header)

    Content Description Header包含了RM文件的title、author、copyright、comments information等信息。其中包含的字段如下:

    Content_Description {UINT32 object_id;UINT32 size;UINT16 object_version;if (object_version == 0){UINT16 title_len;UINT8[title_len] title;UINT16 author_len;UINT8[author_len] author;UINT16 copyright_len;UINT8[copyright_len] copyright;UINT16 comment_len;UINT8[comment_len] comment;} }

    各字段含義如下表:

    fieldtypedescription
    object_idUINT32The unique object ID for the Content Description Header ("CONT").
    sizeUINT32The size of the Content Description Header in bytes.
    object_versionUINT16the version of the Content Description Header object.
    title_lenUINT16The length of the title data in bytes. Note that the title data is not null-terminated.
    titleUINT8[title_len]An array of ASCII characters that represents the title information for the RealMedia file. The size of this member is variable.
    author_lenUINT16The length of the author data in bytes. Note that the author data is not null-terminated.
    authorUINT8[author_len]An array of ASCII characters that represents the author information for the RealMedia file. The size of this member is variable.
    copyright_lenUINT16The length of the copyright data in bytes. Note that the copyright data is not null-terminated.
    copyrightUINT8[]An array of ASCII characters that represents the copyright information for the RealMedia file. The size of this member is variable.
    comment_lenUINT16The length of the comment data in bytes. Note that the comment data is not null-terminated.
    commentUINT8[]An array of ASCII characters that represents the comment information for the RealMedia file.The size of this member is variable.

    3. RM數(shù)據(jù)段(Data Section)

    Data Section的起始位置可以通過Properties Header的data_offset字段獲取。通常RM數(shù)據(jù)段包括一個Data Chunk Header和多個交織的媒體數(shù)據(jù)包(data packet)構(gòu)成。

    Data Chunk Header

    標記數(shù)據(jù)塊的開始位置。一般RM文件只有一個數(shù)據(jù)塊。特別大的文件,可能有多個數(shù)據(jù)塊。其中包含的字段如下:

    Data_Chunk_Header {UINT32 object_id;UINT32 size;UINT16 object_version;if (object_version == 0){UINT32 num_packets; UINT32 next_data_header;} }

    各字段含義如下表:

    fieldtypedescription
    object_idUINT32The unique object ID for the Data Chunk Header ('DATA').
    sizeUINT32The size of the Data Chunk in bytes. The size includes the size of the header plus the size of all the packets in the data chunk.
    object_versionUINT16The version of the Data Chunk Header object.
    num_packetsUINT32Number of packets in the data chunk.
    next_data_headerUINT32Offset from start of file to the next data chunk. A non-zero value refers to the file offset of the next data chunk. A value of zero means there are no more data chunks in this file. This field is not typically used.

    Data Packet

    data chunk header之后緊跟著是num_packets個數(shù)據(jù)包。這些packet可能來自多個流,但是其時間戳是按照升序順序存儲的。每一個數(shù)據(jù)包的構(gòu)成如下:

    Media_Packet_Header {UINT16 object_version;if ((object_version == 0) || (object_version == 1)){UINT16 length;UINT16 stream_number;UINT32 timestamp;if (object_version == 0){UINT8 packet_group;UINT8 flags;}else if (object_version == 1){UINT16 asm_rule;UINT8 asm_flags;}UINT8[length] data;}else{StreamDone();} }

    各字段含義如下表:

    fieldtypedescription
    object_versionUINT16The version of the Media Packet Header object.
    lengthUINT16The length of the packet in bytes.
    stream_numberUINT16The 16-bit alias used to associate data packets with their associated Media Properties Header.
    timeStampUINT32The time stamp of the packet in milliseconds.
    packet_groupUINT8The packet group to which the packet belongs. If packet grouping is not used, set this field to 0 (zero).
    flagsUINT8Flags describing the properties of the packet. The following flags are defined:
    HX_RELIABLE_FLAG=1
    If this flag is set, the packet is delivered reliably.
    HX_KEYFRAME_FLAG=2
    If this flag is set, the packet is part of a key frame or in some way marks a boundary in your data stream.
    asm_ruleUINT16The ASM rule assigned to this packet.
    asm_flagsUINT8Contains HX_ flags that dictate stream switching points.
    dataUINT8[length]The application-specific media data. The size of this member is variable.

    4. RM索引段(Index Section)

    Index Section存儲了音視頻關(guān)鍵幀相關(guān)的時間到偏移量的映射。
    通常索引塊包含一個Index Chunk Header和一系列的index records。

    Index Chunk Header

    Index Chunk Header標識索引塊的開始位置,其偏移量可以通過Properties Header的index_offset字段獲取。其中保存了索引段的屬性信息。其中包含的字段如下:

    Index_Chunk_Header {u_int32 object_id;u_int32 size;u_int16 object_version;if (object_version == 0){u_int32 num_indices;u_int16 stream_number;u_int32 next_index_header;} }

    各字段含義如下表:

    fieldtypedescription
    object_idUINT32The unique object ID for the Index Chunk Header ("INDX").
    sizeUINT32The size of the Index Chunk in bytes.
    object_versionUINT16The version of the Index Chunk Header object.
    num_indicesUINT32Number of index records in the index chunk.
    stream_numberUINT16The stream number for which the index records in this index chunk are associated.
    next_index_headerUINT32Offset from start of file to the next index chunk. This member enables RealMedia file format readers to find all the index chunks quickly. A value of zero for this member indicates there are no more index headers in this file.

    index records

    index record中記錄時間戳到數(shù)據(jù)包偏移量的映射。其中包含的字段如下:

    IndexRecord {UINT16 object_version;if (object_version == 0){u_int32 timestamp;u_int32 offset;u_int32 packet_count_for_this_packet;} }

    各字段含義如下表:

    fieldtypedescription
    object_versionUINT16The version of the Index Record object.
    timestampUINT32The time stamp (in milliseconds) associated with this record.
    offsetUINT32The offset from the start of the file at which this packet can be found.
    packet_count_for_this_packetUINT32The packet number of the packet for this record. This is the same number of packets that would have been seen had the file been played from the beginning to this point.

    注意,通常情況下每個stream對應(yīng)一個索引段,也就是說index section可能會出現(xiàn)多次。

    6. RM元數(shù)據(jù)段(Metadata Section)

    RealMedia元數(shù)據(jù)中只有一個tag,這個tag里面包含一系列的命名metadata,這些metadata描述了媒體文件的屬性。這些metadata可以是文本、整型或二進制數(shù)據(jù)。Metadata Section包含一個Header和Tag Body。

    Metadata Section Header

    定義如下:

    MetadataSectionHeader {u_int32 object_id; // The unique object ID for the Metadata Section Header ("RMMD")u_int32 size; }

    Metadata Tag

    metadata tag有多個properties構(gòu)成。這些properties通過樹形結(jié)構(gòu)組織,每一個property包含一個類型和值,也可能包括多個sub-properties。其中包含如下字段:

    MetadataTag {u_int32 object_id;u_int32 object_version;u_int8[] properties; }

    各字段含義如下表:

    fieldtypedescription
    object_idUINT32The unique object ID for the Metadata Tag ("RJMD").
    object_versionUINT32The version of the Metadata Tag.
    propertiesUINT8[]The MetadataProperty structure that makes up the metadata tag (see "Metadata Property Structure" for more details). As mentioned above, the properties will be represented as one unnamed root metadata property with multiple sub-properties, each with their own optional sub-properties. These will be nested, as in a tree.

    Metadata Property Structure

    該部分包含如下字段:

    MetadataProperty {u_int32 size;u_int32 type;u_int32 flags;u_int32 value_offset;u_int32 subproperties_offset;u_int32 num_subproperties;u_int32 name_length;u_int8[name_length] name;u_int32 value_length;u_int8[value_length] value;PropListEntry[num_subproperties] subproperties_list;MetadataProperty[num_subproperties] subproperties; }

    各字段含義如下表:

    fieldtypedescription
    sizeUINT32The size of the MetadataProperty structure in bytes.
    typeUINT32The type of the value data. The data in the value array can be one of the following types:
    MPT_TEXT
    The value is string data.
    MPT_TEXTLIST
    The value is a separated list of strings, separator specified as sub-property/type descriptor.
    MPT_FLAG
    The value is a boolean flag either 1 byte or 4 bytes, check size value.
    MPT_ULONG
    The value is a four-byte integer.
    MPT_BINARY
    The value is a byte stream.
    MPT_URL
    The value is string data.
    MPT_DATE
    The value is a string representation of the date in the form: YYYYmmDDHHMMSS (m = month, M = minutes).
    MPT_FILENAME
    The value is string data.
    MPT_GROUPING
    This property has subproperties, but its own value is empty.
    MPT_REFERENCE
    The value is a large buffer of data, use sub-properties/type descriptors to identify mime-type.
    flagsUINT32Flags describing the property. The following flags are defined these can be used in combination:
    MPT_READONLY
    Read only, cannot be modified.
    MPT_PRIVATE
    Private, do not expose to users.
    MPT_TYPE_DESCRIPTOR
    Type descriptor used to further define type of value.
    value_offsetUINT32The offset to the value_length , relative to the beginning of the MetadataProperty structure.
    subproperties_offsetUINT32The offset to the subproperties_list , relative to the beginning of the MetadataProperty structure.
    num_subpropertiesUINT32The number of subproperties for this MetadataProperty structure.
    name_lengthUINT32The length of the name data, including the null-terminator.
    nameUINT8[]The name of the property (string data). The size of this member is designated by name_length.
    value_lengthUINT32The length of the value data.
    valueUINT8[]The value of the property (data depends on the type specified for the property). The size of this member is designated by value_length.
    subproperties_listPropListEntry[]The list of PropListEntry structures. The PropListEntry structure identifies the offset for each property (see "PropListEntry Structure" for more details. The size of this member is num_subproperties * sizeof(PropListEntry).
    subpropertiesMetadataProperty[]The sub-properties. Each sub-property is a MetadataProperty structure with its own size, name, value, sub-properties, and so on. The size of this member is variable.

    PropListEntry Structure

    該部分包含如下字段:

    PropListEntry {u_int32 offset;u_int32 num_props_for_name; }

    各字段含義如下表:

    fieldtypedescription
    offsetUINT32The offset for this indexed sub-property, relative to the beginning of the containing MetadataProperty.
    num_props_for_nameUINT32The number of sub-properties that share the same name. For example, a lyrics property could have multiple versions as differentiated by the language sub-property type descriptor.

    metadata section footer標志著RealMedia文件的metasection的結(jié)束。由于位于RM文件末尾,section footer的位置是固定的,即相對文件結(jié)尾偏移量-140字節(jié)。section footer中的size字段表示metadata tag的長度,這個字段可以用于快速定位metadata數(shù)據(jù)。其中包含的字段如下:

    MetadataSectionFooter {u_int32 object_id; // The unique object ID for the Metadata Section Footer ("RMJE").u_int32 object_version; // The version of the metadata tag.u_int32 size; // The size of the preceding metadata tag }

    ID3v1 Tag

    ID3v1 Tag位于metadata section最后一部分,其長度固定為128字節(jié)。格式可參考ID3v1 standard。

    7. 其他問題

    整個rm/rmvb文件結(jié)構(gòu)相對比較簡單。
    比較官方的文檔可以從Helix DNA Common Components找到。
    目前來說只有一個工具可以分析RM/RMVB文件,名字是RM文件分析器。

    參考文獻

  • multimedia-wiki-RealMedia
  • RealMedia File Format-helix
  • RM文件解析
  • 轉(zhuǎn)載于:https://www.cnblogs.com/tocy/p/media_container_7-rmvb.html

    總結(jié)

    以上是生活随笔為你收集整理的多媒体文件格式之RMVB的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。