Elementary stream

本文介绍了MPEG标准中元素流(ES)的概念及其在音视频编码中的应用。元素流通常为音频或视频编码器的输出,包含单一类型的数据如音频或视频。文章详细解析了MPEG-2视频元素流的头部格式以及MPEG-1音频元素流的一般布局。

Elementary stream


An elementary stream (ES) as defined by MPEG communication protocol is usually the output of an audio or video encoder. ES contains only one kind of data, e.g. audio, video or closed caption. An elementary stream is often referred to as "elementary", "data", "audio", or "video" bitstreams or streams. The format of the elementary stream depends upon the codec or data carried in the stream, but will often carry a common header when packetized into a packetized elementary stream.

Contents

   [hide

Header for MPEG-2 video elementary stream[edit]

Partial Sequence Header Format
Field Name # of bits Description
start code320x000001B3
Horizontal Size12 
Vertical Size12 
Aspect ratio4 
Frame rate code4 
Bit rate18Actual bit rate = bit rate * 400, rounded upwards. Use 0x3FFFF for variable bit rate.
Marker bit1Always 1.
VBV buf size10Size of video buffer verifier = 16*1024*vbv buf size
constrained parameters flag1 
load intra quantizer matrix1If bit set then intra quantizer matrix follows, otherwise use default values.
intra quantizer matrix0 or 64*8 
load non intra quantizer matrix1If bit set then non intra quantizer matrix follows.
non intra quantizer matrix0 or 64*8 

General layout of MPEG-1 audio elementary stream[edit]

The digitized sound signal is divided up into blocks of 384 samples in Layer I and 1152 samples in Layers II and III. The sound sample block is encoded within an audio frame:

  • header
  • error check
  • audio data
  • ancillary data

The header of a frame contains general information such as the MPEG Layer, the sampling frequency, the number of channels, whether the frame is CRC protected, whether the sound is the original:

Field Name # of bits Description
sync word120xFFF
ID1'1'=mpeg1 '0'=mpeg2
layer2'11'=1 '10'=2 '01'=3
no protection1'0'=Protected by CRC (16bit CRC follows header)
'1'=Not Protected
bit rate index4 
sampling frequency2kHz '00'=44.1 '01'=48 '10'=32
padding1 
private1 
mode2'00'=Stereo '01'=joint stereo '10'=dual channel '11'=single channel
mode extension2 
copyright10=none 1=yes
original or copy10=copy 1=original
emphasis2 

Although most of this information may be the same for all frames, MPEG decided to give each audio frame such a header in order to simplify synchronization and bitstream editing.


我给你示例代码了呀为啥你看不到你是有输入限制吗 /*** *@remark: ps头的封装,里面的具体数据的填写已经占位,可以参考标准 *@param : pData [in] 填充ps头数据的地址 * s64Src [in] 时间戳 *@return: 0 success, others failed */ int gb28181_make_ps_header(char *pData, int64_t s64Scr) { int64_t lScrExt = 0; //(s64Scr) % 100; bits_buffer_t bitsBuffer; bitsBuffer.i_size = PS_HDR_LEN; bitsBuffer.i_data = 0; bitsBuffer.i_mask = 0x80; // 二进g制:10000000 这里是为了后面对一个字节的每一位进行操作,避免大小端夸字节字序错乱 bitsBuffer.p_data = (unsigned char *)(pData); memset(bitsBuffer.p_data, 0, PS_HDR_LEN); bits_write(&bitsBuffer, 32, 0x000001BA); /*start codes*/ bits_write(&bitsBuffer, 2, 1); /*marker bits '01b'*/ bits_write(&bitsBuffer, 3, (s64Scr >> 30) & 0x07); /*System clock [32..30] system_clock_reference_base*/ bits_write(&bitsBuffer, 1, 1); /*marker bit*/ bits_write(&bitsBuffer, 15, (s64Scr >> 15) & 0x7FFF); /*System clock [29..15] system_clock_reference_base*/ bits_write(&bitsBuffer, 1, 1); /*marker bit*/ bits_write(&bitsBuffer, 15, s64Scr & 0x7fff); /*System clock [29..15] system_clock_reference_base*/ bits_write(&bitsBuffer, 1, 1); /*marker bit*/ bits_write(&bitsBuffer, 9, lScrExt & 0x01ff); /*System clock [14..0] system_clock_reference_extension*/ bits_write(&bitsBuffer, 1, 1); /*marker bit*/ // bits_write(&bitsBuffer, 22, (3750) & 0x3fffff); /*bit rate(n units of 50 bytes per second.) program_mux_rate*/ bits_write(&bitsBuffer, 22, (5945) & 0x3fffff); bits_write(&bitsBuffer, 2, 3); /*marker bits '11'*/ bits_write(&bitsBuffer, 5, 0x1f); /*reserved(reserved for future use)*/ bits_write(&bitsBuffer, 3, 0); /*stuffing length*/ return 0; } /*** *@remark: sys头的封装,里面的具体数据的填写已经占位,可以参考标准 *@param : pData [in] 填充ps头数据的地址 *@return: 0 success, others failed */ int gb28181_make_sys_header(char *pData, int audioCnt) { bits_buffer_t bitsBuffer; bitsBuffer.i_size = SYS_HDR_LEN; bitsBuffer.i_data = 0; bitsBuffer.i_mask = 0x80; bitsBuffer.p_data = (unsigned char *)(pData); memset(bitsBuffer.p_data, 0, SYS_HDR_LEN); /*system header*/ bits_write(&bitsBuffer, 32, 0x000001BB); /*start code*/ bits_write(&bitsBuffer, 16, SYS_HDR_LEN - 6);/*header_length 表示次字节后面的长度,后面的相关头也是次意思*/ bits_write(&bitsBuffer, 1, 1); /*marker_bit*/ bits_write(&bitsBuffer, 22, 3967); /*rate_bound*/ bits_write(&bitsBuffer, 1, 1); /*marker_bit*/ bits_write(&bitsBuffer, 6, audioCnt); /*audio_bound*/ bits_write(&bitsBuffer, 1, 0); /*fixed_flag */ bits_write(&bitsBuffer, 1, 1); /*CSPS_flag */ bits_write(&bitsBuffer, 1, 1); /*system_audio_lock_flag*/ bits_write(&bitsBuffer, 1, 1); /*system_video_lock_flag*/ bits_write(&bitsBuffer, 1, 1); /*marker_bit*/ bits_write(&bitsBuffer, 5, 1); /*video_bound*/ bits_write(&bitsBuffer, 1, 0); /*dif from mpeg1*/ bits_write(&bitsBuffer, 7, 0x7F); /*reserver*/ /*video stream bound*/ bits_write(&bitsBuffer, 8, 0xE0); /*stream_id*/ bits_write(&bitsBuffer, 2, 3); /*marker_bit */ bits_write(&bitsBuffer, 1, 1); /*PSTD_buffer_bound_scale*/ bits_write(&bitsBuffer, 13, 2048); /*PSTD_buffer_size_bound*/ /*audio stream bound*/ bits_write(&bitsBuffer, 8, 0xC0); /*stream_id*/ bits_write(&bitsBuffer, 2, 3); /*marker_bit */ bits_write(&bitsBuffer, 1, 0); /*PSTD_buffer_bound_scale*/ bits_write(&bitsBuffer, 13, 512); /*PSTD_buffer_size_bound*/ return 0; } /*** *@remark: psm头的封装,里面的具体数据的填写已经占位,可以参考标准 *@param : pData [in] 填充ps头数据的地址 *@return: 0 success, others failed */ int gb28181_make_psm_header(char *pData) { bits_buffer_t bitsBuffer; bitsBuffer.i_size = PSM_HDR_LEN; bitsBuffer.i_data = 0; bitsBuffer.i_mask = 0x80; bitsBuffer.p_data = (unsigned char *)(pData); memset(bitsBuffer.p_data, 0, PSM_HDR_LEN); bits_write(&bitsBuffer, 24, 0x000001); /*start code*/ bits_write(&bitsBuffer, 8, 0xBC); /*map stream id*/ bits_write(&bitsBuffer, 16, 18); /*program stream map length*/ bits_write(&bitsBuffer, 1, 1); /*current next indicator */ bits_write(&bitsBuffer, 2, 3); /*reserved*/ // bits_write(&bitsBuffer, 5, 0); /*program stream map version*/ bits_write(&bitsBuffer, 5, 1); /*program stream map version*/ bits_write(&bitsBuffer, 7, 0x7F); /*reserved */ bits_write(&bitsBuffer, 1, 1); /*marker bit */ bits_write(&bitsBuffer, 16, 0); /*programe stream info length*/ bits_write(&bitsBuffer, 16, 8); /*elementary stream map length is*/ /*video*/ bits_write(&bitsBuffer, 8, 0x1B); /*stream_type*/ bits_write(&bitsBuffer, 8, 0xE0); /*elementary_stream_id*/ bits_write(&bitsBuffer, 16, 0); /*elementary_stream_info_length */ /*audio*/ bits_write(&bitsBuffer, 8, 0x90); /*stream_type*/ bits_write(&bitsBuffer, 8, 0xC0); /*elementary_stream_id*/ bits_write(&bitsBuffer, 16, 0); /*elementary_stream_info_length is*/ /*crc (2e b9 0f 3d)*/ bits_write(&bitsBuffer, 8, 0x45); /*crc (24~31) bits*/ bits_write(&bitsBuffer, 8, 0xBD); /*crc (16~23) bits*/ bits_write(&bitsBuffer, 8, 0xDC); /*crc (8~15) bits*/ bits_write(&bitsBuffer, 8, 0xF4); /*crc (0~7) bits*/ return 0; }
最新发布
11-27
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值