FLV文件格式分析
来源:互联网 发布:探测鬼魂的软件 编辑:程序博客网 时间:2024/04/30 11:11
FLV是一个二进制文件,由文件头(FLV header)和很多tag组成。tag又可以分成三类:audio,video,script,分别代表音频流,视频流,脚本流(关键字或者文件信息之类)。
FLV Header
一般比较简单,包括文件类型之类的全局信息,如图:
文件类型3bytes总是FLV(0x46 0x4C 0x56),否则...版本1byte一般是0x01,表示FLV version 1流信息1byte倒数第一bit是1表示有视频,倒数第三bit是1表示有音频,其他都应该是0(有些软件如flvtool2可能造成倒数第四bit是1,不过也没发现有什么不对)header长度4bytes整个文件头的长度,一般是9(3+1+1+4),有时候后面还有些别的信息,就不是9了FLV Body
FLV body就是由很多tag组成的。
FLV文件里面帧的实体就是tag了。每个tag都可以分为两部分,第一部分包含是tag 类型信息,长度固定为15字节,如图:
三类:
- 8 -- 音频tag
- 9 -- 视频tag
- 18 -- 脚本tag
接下来就是下一个tag的内容,其开始的四个字节定义了上个tag的总长度,注意上个tag的总长度中不包括上个tag之前的4个描述再上一个tag的长度的4个字节,如图:
接下来说一下文件尾,在文件尾的最后有四个字节是定义最后一个tag的长度的,如图:
这里我门可以算一下,是00 00 00 DD是221,最后一个tag的长度是221,如图:
下面是不同类型的tag数据区的内容体
Audio tag 数据区
audio信息1byte前四位bits表示音频格式:
- 0 -- 未压缩
- 1 -- ADPCM
- 2 -- MP3
- 5 -- Nellymoser 8kHz momo
- 6 -- Nellymoser
下面两位bits表示samplerate:
- 0 -- 5.5kHz
- 1 -- 11kHz
- 2 -- 22kHz
- 3 -- 44kHz
下面一位bit表示每个采样的长度:
- 0 -- snd8Bit
- 1 -- snd16Bit
下面一位bit表示类型:
- 0 -- sndMomo
- 1 -- sndStereo
video tag 数据区
video信息1byte前四位bits表示类型:
- 1 -- keyframe
- 2 -- inner frame
- 3 -- disposable inner frame (H.263 only)
后四位bits表示编码器id:
- 2 -- Seronson H.263
- 3 -- Screen video
- 4 -- On2 VP6
- 5 -- On2 VP6 without channel
- 6 -- Screen video version 2
script tag 数据区
略n字...
下面是自己写的一段根据上面对FLV文件结构的分析读取FLV播放时间的Delphi代码:
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
OpenDialog1.Execute;
Edit1.Text:=OpenDialog1.FileName;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
iFileHandle: Integer;
iFileLength: Integer;
iBytesRead: Integer;
Buffer: array of Byte;
i: Integer;
str1,str2:String;
tminute,tSecond,tMillisecond,tmptime:Integer;
begin
if Edit1.Text = '' then
begin
ShowMessage('请选择文件!');
exit;
end;
iFileHandle := FileOpen( Edit1.Text , fmOpenRead);
iFileLength := FileSeek(iFileHandle, 0, 2);
FileSeek(iFileHandle, 0, 0);
SetLength(Buffer, iFileLength);
iBytesRead := FileRead(iFileHandle, Buffer[0], iFileLength);
FileClose(iFileHandle);
str1 := '';
for i := iBytesRead - 4 to iBytesRead - 1 do
begin
str1 := str1 + IntToHex(Buffer[i],2);
end;
str2 := '';
for i := iBytesRead - StrToInt('$'+str1) to iBytesRead - (StrToInt('$'+str1)-2) do
begin
str2 := str2 + IntToHex(Buffer[i],2);
end;
tMillisecond:=strtoint('$'+str2);
tminute:=(tMillisecond div 1000) div 60;
tSecond:=(tMillisecond div 1000) mod 60;
tmptime:=tMillisecond mod 1000;
Label2.Caption:=IntToStr(tminute)+'分'+IntToStr(tSecond)+'秒';
Buffer := nil;
end;
- FLV文件格式分析
- FLV文件格式分析
- FLV文件格式分析
- FLV文件格式分析
- FLV 文件格式分析
- FLV文件格式分析
- FLV文件格式分析实例
- FLV文件格式分析
- flv文件格式分析FlvParse.exe
- FLV文件格式——实例分析
- FLV文件格式分析(附源码)
- FLV文件格式
- flv文件格式
- FLV文件格式
- FLV文件格式
- FLV 文件格式
- FLV文件格式
- flv文件格式
- Sicily 4835. Numbersrebmun
- 21岁的人生
- 利用ntsd手动转储程序内存
- Quartz时间计划
- 如何查看Eclipse安装了那些插件
- FLV文件格式分析
- POJ 1811 Prime Test 素数测试
- 看图说话:如何高效地工作、学习及阅读?
- Windows Phone执行模型
- 为什么架构设计需要方法论?
- STM32固件库详解
- iPhone 在XML或JSON交互过程中出现的编码问题解决办法
- Office 15体验
- 仅有USB线拷贝无SD卡小米照相文件方法