我在不使用外部库的情况下制作自己的FLV音频下载器。
我正在关注此文档:
http://osflash.org/flv
在FLV标签类型中,有三个有趣的值:
BodyLength,Timestamp,StreamId是uint24_be
类型。如何阅读它们?
我在这里找到了答案:
Extract Audio from FLV stream in C#
但是我不明白几件事:
如果Timestamp和StreamId都是uint24_be
(又是uint24_be
?),那么为什么
reader.ReadInt32(); //skip timestamps
ReadNext3Bytes(reader); // skip streamID
还有
ReadNext3Bytes
到底做什么?为什么不读取这样的下3个字节:reader.ReadInt32()+reader.ReadInt32()+reader.ReadInt32();
最佳答案
您不能使用reader.ReadInt32()+reader.ReadInt32()+reader.ReadInt32()
,因为起初它是12个字节而不是3个字节,而第二个字节对这些字节进行汇总还不够简单-您应该设置24位值。这是ReadNext3Bytes
函数的可读性更高的版本:
int ReadNext3Bytes(System.IO.BinaryReader reader) {
try {
byte b0 = reader.ReadByte();
byte b1 = reader.ReadByte();
byte b2 = reader.ReadByte();
return MakeInt(b0, b1, b2);
}
catch { return 0; }
}
int MakeInt(byte b0, byte b1, byte b2) {
return ((b0 << 0x10) | (b1 << 0x08)) | b2;
}
关于c# - FLV车身长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10297172/