если в C # , я делал что-то похожее некоторое время назад.
class FLVFileLength
{
private static Double ByteArrayToDouble(byte[] bytes, bool readInReverse)
{
if (bytes.Length != 8)
throw new Exception("bytes must be exactly 8 in Length");
if (readInReverse)
Array.Reverse(bytes);
return BitConverter.ToDouble(bytes, 0);
}
private static Double GetNextDouble(Stream fileStream, int offset, int length)
{
byte[] bytes = new byte[length];
// read bytes
int result = fileStream.Read(bytes, 0, length);
if (result != length)
return -1;
// convert to double (all flass values are written in reverse order)
return ByteArrayToDouble(bytes, true);
}
private static string ByteArrayToString(byte[] bytes)
{
string byteString = string.Empty;
foreach (byte b in bytes)
{
byteString += Convert.ToChar(b).ToString();
}
return byteString;
}
public double GetFLVlength(string URL)
{
try
{
HttpWebRequest http = HttpWebRequest.Create(URL) as HttpWebRequest;
http.Proxy = WebProxyManager.GetNextProxy();
http.UserAgent = UserAgentManager.GetNextUserAgent();
HttpWebResponse response = http.GetResponse() as HttpWebResponse;
Stream streamReader = response.GetResponseStream();
double duration = -1;
Stream fileStream = response.GetResponseStream();
byte[] bytes = new byte[1024];
string tag = "duration";
int length = fileStream.Read(bytes, 0, 1024);
string z = ByteArrayToString(bytes);
if (z.Contains(tag))
{
int pos = z.IndexOf(tag) + tag.Length + 1;
MemoryStream ms = new MemoryStream(bytes, pos, 8);
BinaryReader br = new BinaryReader(ms);
duration = ByteArrayToDouble(br.ReadBytes(8), true);
}
fileStream.Close();
return duration;
}
catch (Exception)
{
return -1;
}
}
}