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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

FLV文件中VideoPacket的详解

發布時間:2024/2/28 编程问答 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 FLV文件中VideoPacket的详解 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

FLV文件中VideoPacket的詳解

眾所周知,FLV文件體主要有三種Tag組成:AUDIODATA、VIDEODATA和SCRIPTDATA,其中SCRIPTDATA中包含了MetaData,通過解析這些元數據,可以得到解碼器的初始化信息,如音頻解碼元數據audiocodecid、audiodatarate、audiodelay、audiosamplerate、audiosamplesize、stereo,視頻解碼元數據videocodecid、framerate、height、width、videodatarate等信息。這些信息里面有的對于初始化解碼器非常有用,例如解碼器必須知道codecid,才能進行初始化從操作,視頻解碼器初始化時有的需要知道圖像寬高信息,才能對解碼重建Buffer進行初始化。

某些FLV文件,在SCRIPTDATA的MetaData中并未給出相應信息,這樣就需要對AUDIODATA、VIDEODATA進行解析。Adobe Flash Video File Format Specification中只是簡單交代了AVCVIDEOPACKET的格式。對其他的codecID對應的VideoPacket并未詳細介紹。本文專門針對視頻解碼初始化過程中需要的width和height信息的深入解析為例,詳細介紹一些VideoPacket。因為FLV的VideoPacket的格式和SWF文件離得VideoPacket格式基本一致,也可以參考SWF File Format Specification。詳見http://www.adobe.com/go/swf_file_format。

1、VideoTagBody

IF FrameType == 5

UI8

ELSE (

IF CodecID == 2

H263VIDEOPACKET????????????????????????????//Sorensen H263

IF CodecID == 3

SCREENVIDEOPACKET??????????????//Screen

IF CodecID == 4

VP6FLVVIDEOPACKET???????????????//On2 Vp6

IF CodecID == 5

VP6FLVALPHAVIDEOPACKET??//On2 VP6 alpha

IF CodecID == 6

SCREENV2VIDEOPACKET??????????????????//Screen V2

IF CodecID == 7

AVCVIDEOPACKET?????????????????????//AVC

)

2、H263VIDEOPACKET

這里的H263是Sorenson H263,對ITU-T的H.263進行了訂制,所以在picture層和MB層的header的格式發生了改動,且GOB層被刪除。其具體格式為:

表格 1 H263VIDEOPACKET

Field

Type

Comment

PictureStartCode

UB[17]

Similar to H.263 5.1.1
0000 0000 0000 0000 1

Version

UB[5]

Video format version
Flash Player 6 supports 0 and 1

TemporalReference

UB[8]

See H.263 5.1.2

PictureSize

UB[3]

000: custom, 1 byte
001: custom, 2 bytes
010: CIF (352x288)
011: QCIF (176x144)
100: SQCIF (128x96)
101: 320x240
110: 160x120
111: reserved

CustomWidth

If PictureSize = 000, UB[8]
If PictureSize = 001, UB[16]
Otherwise absent
Note: UB[16] is not the same
as UI16; there is no byte
swapping.

Width in pixels

CustomHeight

If PictureSize = 000, UB[8]
If PictureSize = 001, UB[16]
Otherwise absent
Note: UB[16] is not the same
as UI16; there is no byte
swapping.

Height in pixels

PictureType

UB[2]

00: intra frame
01: inter frame
10: disposable inter frame
11: reserved

DeblockingFlag

UB[1]

Requests use of deblocking
filter (advisory only, Flash
Player may ignore)

Quantizer

UB[5]

See H.263 5.1.4

ExtraInformationFlag

UB[1]

See H.263 5.1.9

ExtraInformation

If ExtraInformationFlag = 1,
UB[8]
Otherwise absent

See H.263 5.1.10

...

The ExtraInformationFlag-
ExtraInformation sequence
repeats until an
ExtraInformationFlag of 0 is
encountered

Macroblock

MACROBLOCK

See following

PictureStuffing

varies

See H.263 5.1.13

從上表可以得出,不用深入到macroblock層,只需解析頭部,就可很簡單的得到width和height信息。

?

2、SCREENVIDEOPACKET和SCREENV2VIDEOPACKET

Screen Video是一個簡單的無損壓縮視頻格式,它利用幀間編碼傳遞位圖,其pixel_froamt是BGR24,專用于電腦截屏視頻傳輸。像素數據使用了Zlib開放標準進行了壓縮。其具體格式為:

表格 2 SCREENVIDEOPACKET

Field

Type

Comment

BlockWidth

UB[4]

Pixel width of each block in the grid. This value is stored as (actualWidth / 16) - 1, so possible block sizes are a multiple of 16 and not more than 256.

ImageWidth

UB[12]

Pixel width of the full image.

BlockHeight

UB[4]

Pixel height of each block in the grid. This value is stored
as (actualHeight / 16) - 1, so possible block sizes are a
multiple of 16 and not more than 256.

ImageHeight

UB[12]

Pixel height of the full image.

ImageBlocks

IMAGEBLOCK[n]

Blocks of image data. See preceding for details of how
to calculate n. Blocks are ordered from bottom left to
top right, in rows.

表格 3 SCREENV2VIDEOPACKET

Field

Type

Comment

BlockWidth

UB[4]

Pixel width of each block in the grid. This value is stored as (actualWidth / 16) - 1, so possible block sizes are a multiple of 16 and not more than 256.

ImageWidth

UB[12]

Pixel width of the full image.

BlockHeight

UB[4]

Pixel height of each block in the grid. This value is stored as (actualHeight / 16) - 1, so possible block sizes are a multiple of 16 and not more than 256.

ImageHeight

UB[12]

Pixel height of the full image.

Reserved

UB[6]

Must be 0

HasIFrameImage

UB[1]

If 1, has IFrameImage

HasPaletteInfo

UB[1]

If 1, has PaletteInfo

PaletteInfo

If HasPaletteInfo,
IMAGEBLOCK

One block of data to describe the palette.

ImageBlocks

IMAGEBLOCKV2[n]

Blocks of image data. See Block format for details of how to calculate n. Blocks are ordered from bottom left to top right in rows and can be a combination of keyblocks and interblocks.

IFrameImage

If HasIFrameImage,
IMAGEBLOCKV2[n]

Blocks of image data representing interblocks that must be combined with the previous keyblocks to produce the image. See Block format for details of how to calculate n. Blocks are ordered from bottom left to top right in rows.

從上表可以得出,不用深入到macroblock層,只需解析頭部,就可很簡單的得到width和height信息。

3、VP6FLVVIDEOPACKET和VP6FLVALPHAVIDEOPACKET

?????????VP6FLVVIDEOPACKET和VP6FLVALPHAVIDEOPACKET比較簡單,只是簡單的將VP6或VP6A的一個視頻幀封裝到VideoPacket即可。

表格 4 VP6FLVVIDEOPACKET

Field

Type

Comment

HorizontalAdjustment

UB[4]

Number of pixels to subtract from the total width. The resulting width is used on the stage, and the rightmost pixels of the video is cropped.

VerticalAdjustment

UB[4]

Number of pixels to subtract from the total height. The resulting height is used on the stage, and the rightmost pixels of the video is cropped.

Data

UI8[n]

Raw VP6 video stream data

表格 5 VP6FLVALPHAVIDEOPACKET

Field

Type

Comment

HorizontalAdjustment

UB[4]

Number of pixels to subtract from the total width. The resulting width is used on the stage, and the rightmost pixels of the video is cropped.

VerticalAdjustment

UB[4]

Number of pixels to subtract from the total height. The resulting height is used on the stage, and the rightmost pixels of the video is cropped.

OffsetToAlpha

UI[24]

Offset in bytes to the alpha channel video data.

Data

UI8[n]

Raw VP6 video stream data.

AlphaData

UI8[n]

Raw VP6 video stream data representing the alpha channel

這樣如果MetaData中沒有寬高信息的話,就需要深入到Data層進行header parse,解析得到寬高信息,過程比較麻煩,不過可以參考FFmpeg的avcodec中的vp6_parse_header()函數,亦或是參考VP6或VP6Alpha的codec文檔吧,本文暫不做詳解。

4、AVCVIDEOPACKET

???????FLV將AVC的SPS(序列參數集)和PPS(圖像參數集)和其他的配置信息封裝到AVCDecoderConfigurationRecord,其具體格式為:

AVCDecoderConfigurationRecord {
?????????unsigned int(8) ConfigurationVersion = 1;
?????????unsigned int(8) AVCProfileIndication;
?????????unsigned int(8) ProfileCompatibility;
?????????unsigned int(8) AVCLevelIndication;?
?????????bit(6) reserved = ‘111111’b;
?????????unsigned int(2) LengthSizeMinusOne;?
?????????bit(3) reserved = ‘111’b;
?????????unsigned int(5) numOfSequenceParameterSets;
?????????for (i=0; i< numOfSequenceParameterSets;??i++) {
???????????????????unsigned int(16) sequenceParameterSetLength ;
???????????????????bit(8*sequenceParameterSetLength) sequenceParameterSetNALUnit;???//SPS
?????????}
?????????unsigned int(8) numOfPictureParameterSets;
?????????for (i=0; i< numOfPictureParameterSets;??i++) {
???????????????????unsigned int(16) pictureParameterSetLength;
???????????????????bit(8*pictureParameterSetLength) pictureParameterSetNALUnit;??????????????//PPS
?????????}
}

?????????圖像的寬高信息在SPS中,所以需要得到寬高信息,需要解析H.264的SPS,詳見H.264的文檔,當然也可以參考FFmpeg的avcodec中的ff_h264_decode_seq_parameter_set()函數。

5、一點點個人想法

流媒體播放中,多媒體音視頻包經過網絡到達終端,脫去一層層網絡打包外衣,而后容器的外衣、再次是codec的header,經過艱辛的歷程到達解碼器。最終的目的就是節省網絡帶寬。隨著互聯網免費服務潮的到來,那些效果不錯,但是收費高昂的標準或技術,遇到了很大的挑戰。Google主推的VP8,較之ITU-T的H264,雖在編碼效果上稍微遜色,但是其最大的殺手锏——免費,抓住了H264專利費高昂的七寸。Google強大的號召力或許真的會使VPx系列的codec最后勝出。一般公司玩技術、牛公司玩標準、超牛公司玩潮流,不得不佩服美帝的技術帝國。何種這些風潮才能Made in China?
---------------------?
作者:xietao_live_cn?
來源:CSDN?
原文:https://blog.csdn.net/xietao_live_cn/article/details/6539625?
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!

超強干貨來襲 云風專訪:近40年碼齡,通宵達旦的技術人生

總結

以上是生活随笔為你收集整理的FLV文件中VideoPacket的详解的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。