Ogg Format Parsing

Source: Internet
Author: User

The most recent task is to Demux Ogg. I have been studying the Ogg format and accumulated some materials and knowledge. I will record it here.

Ogg is a multimedia container, can contain a lot of audio and video formats, he is xiph provided by the Free Open Source Audio and video format, the official website can look at the http://www.xiph.org /!

Most of the files that can be seen by everyone are in the Ogg Vorbis audio format. It is an audio that is comparable to MP3. When I first came into contact with Ogg, I thought it was pure audio, I have read the introduction on the official website and found that it is a very powerful container structure. The Free videos provided by xiph, theora and audio Vorbis, are both open-source and free, and are included in the Ogg container, in addition, Ogg can contain many other audio and video files, such as FLAC and MP3. You can see the link on my official website and then you will be enlightened.

<1> Ogg standard container format

Ogg organizes logical streams by page. Each page contains pageheader and pagedata. The page header has the following definitions:

1> page ID: ASCII character, 0x4f 'o '0X67 'G' 0x67 'G' 0x53 s', 4 bytes, it identifies the beginning of a page.

2> Version ID: Generally, the current version defaults to 0 to 1 bytes.

3> type identification: identifies the type of the current page, 1 byte,

0x01: The Media Encoding data on this page belongs to the same packet of the same logical stream as the previous page. If this bit is not set, this page starts with a new packet;

0x02: indicates that this page is the first page of the logical flow, Bos ID. If this bit is not set, it indicates that it is not the first page;

0x04: the last page of the logic flow of the page. It is the EOS identifier. If this bit is not set, this page is not the last page.

4> granule_position: The parameter information related to media encoding. It consists of 8 bytes. For audio streams, it stores the number of sample codes of logical streams in PCM output up to this page, it can calculate the timestamp. For a video stream, it stores the number of video frames encoded until the current page. If this value is-1, it indicates that the logical flow packet has not ended as of this page. (Small End)

5> serial_number: the ID of the stream on the current page, which consists of four bytes. It is the sequence number that distinguishes the logical stream to which the current page belongs from other logical streams. We can use this value to divide the stream. (Small End)

6> page_seguence_number: the number of the logical stream in the current page, 4 bytes.

7> crc_cbecksum: the Cyclic Redundancy verification code, which consists of four bytes to verify the validity of each page.

8> number_page_segments: specify the number of segments in the segment_table domain of the current page, in 1 byte.

9> segment_table: it is a table literally, indicating the length of each segment. The value range is 0 ~ 255.

The segment can get the packet value. The size of each packet ends with the last segment not equal to 255. The length of each packet can be obtained from the segment_table in the header of the page. For example: if the sequence of a group of segments is FF 45 ff FFFF 40 FF 5 FF 66, the length of the first packet is 255 + 69 = 324, and the size of the second packet is 829.

The page header is basically composed of the above parameters, so we can get the length of the page header and the length of the entire page:

Header_size = 27 + number_page_segments; (byet)

Page_size = header_size + size of each segment in segment_table;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.