Flash视频的长度

时间:2009-11-26 06:21:09

标签: flash video

我需要找到在任何热门视频分享网站上托管的Flash视频的长度。这可能吗?

Blinkx如何确定已编入索引的视频的长度?

提前感谢你。

此致 曼索尔

3 个答案:

答案 0 :(得分:1)

如果在 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;
            }
        }
    }

答案 1 :(得分:0)

FLV或RTMP流包含onMetaData脚本,该脚本详细说明了创建者已知的持续时间(例如,您没有从“实时”流中获取)。

您可以阅读FLVRTMP规范并进行自己的剖析,也可以在Flash中播放视频并等待onMetaData回调。

答案 2 :(得分:0)

PHP Video Toolkit可以从电影中提取持续时间。