public static Video LoadVideo(string nameFile)
        {
            byte[]   data = System.IO.File.ReadAllBytes(nameFile);
            DateTime dateBeg = DateTime.Now, dateEnd = dateBeg;
            string   ip = string.Empty;
            int      i  = 0;

            if (data[i] == 'T' && data[i + 1] == 'A' && data[i + 2] == 'G')
            {
                i      += 3;
                dateBeg = VideoHead.GetDateTime(data, i); i += 7;
                dateEnd = VideoHead.GetDateTime(data, i); i += 7;
                ip      = new System.Net.IPAddress(BitConverter.ToUInt32(data, i)).ToString(); i += 4;
            }
            if (data[i] == 'F' && data[i + 1] == 'R' && data[i + 2] == 'M')
            {
                i += 3;
                int   sz            = VideoHead.GetShort(data, i); i += 2;
                int   freq          = data[i]; i++; //частота кадров
                int   szNameVideo   = VideoHead.GetShort(data, i); i += 2;
                int   szNameProcess = VideoHead.GetShort(data, i); i += 2;
                Video video         = new Video(freq, 2, dateBeg, dateEnd, ip);
                video.NameVideo = Encoding.ASCII.GetString(data, i, szNameVideo);
                sz = i + szNameVideo + szNameProcess;
                int    numFrame = 0; //номер кадра
                byte[] data2    = null;
                byte[] dataTmp  = null;
                while (sz + 4 < data.Length && sz > 0)
                {
                    int sz2 = BitConverter.ToInt32(data, sz); sz += 4;
                    if (sz + sz2 > data.Length)
                    {
                        break;
                    }
                    Server.LZW lzw = new Server.LZW();
                    if (dataTmp == null || dataTmp.Length < sz2)
                    {
                        dataTmp = new byte[sz2];
                    }
                    if (data2 == null || data2.Length < 20 * sz2)
                    {
                        data2 = new byte[20 * sz2];
                    }
                    Array.Copy(data, sz, dataTmp, 0, sz2);
                    int sz3 = lzw.from_lzw(dataTmp, data2);
                    i = 0;
                    while (i < sz3)
                    {
                        numFrame++;
                        int szStruct = VideoHead.GetShort(data2, i);
                        if (i + szStruct >= sz3 || szStruct < 0)
                        {
                            break;
                        }
                        int      width     = VideoHead.GetShort(data2, i + 2);
                        int      height    = VideoHead.GetShort(data2, i + 4);
                        int      szData    = VideoHead.GetInt(data2, i + 6);
                        int      type      = VideoHead.GetShort(data2, i + 10);
                        int      szCaption = VideoHead.GetShort(data2, i + 12);
                        DateTime timeFrame = dateBeg.AddSeconds(numFrame / freq); //предположительное время кадра
                        if (szStruct > 14)                                        //было добавлено время на стороне бота
                        {
                            timeFrame = VideoHead.GetDateTime(data2, i + 14);
                        }
                        if (sz3 >= i + szStruct + szData && width < 6000 && height < 3000)
                        {
                            video.AddFrame(width, height, type, data2, i + szStruct, szData, szCaption, timeFrame);
                        }
                        i += szStruct + szData + szCaption;
//						if (video.frames.Count == 168)
//							video.frames.Count.ToString();
                    }
                    sz += sz2;
                }
                video.ArrangeCaptions();
                video.CorrectTime();
                return(video);
            }
            return(null);
        }
        public VideoHead(string nameFile)
        {
            byte[] data             = new byte[512];
            System.IO.FileStream fs = new System.IO.FileStream(nameFile, System.IO.FileMode.Open, System.IO.FileAccess.Read);
            int rd = fs.Read(data, 0, 3);

            if (data[0] == 'T' && data[1] == 'A' && data[2] == 'G')
            {
                rd = fs.Read(data, 0, 18);
                if (rd == 18)
                {
                    timeBeg = GetDateTime(data, 0);
                    timeEnd = GetDateTime(data, 7);
                    ip      = new System.Net.IPAddress(BitConverter.ToUInt32(data, 14)).ToString();
                }
            }
            else
            {
                fs.Seek(0, System.IO.SeekOrigin.Begin);
                timeBeg = DateTime.Now;
                timeEnd = DateTime.Now;
                ip      = "nothing";
            }
            rd = fs.Read(data, 0, 10);
            if (data[0] == 'F' && data[1] == 'R' && data[2] == 'M' && rd == 10)
            {
                int sz = GetShort(data, 3);
                freq = data[5];
                int szNameVideo   = GetShort(data, 6);
                int szNameProcess = GetShort(data, 8);
                sz         += szNameVideo + szNameProcess;
                rd         += fs.Read(data, rd, sz - rd);
                name        = Encoding.ASCII.GetString(data, 10, szNameVideo);
                nameProcess = Encoding.ASCII.GetString(data, 10 + szNameVideo, szNameProcess);
                try
                {
                    captions = new List <string>();
                    bool   stop  = false;
                    byte[] data2 = null;
                    while (fs.Read(data, 0, 4) == 4 && !stop)
                    {
                        sz = BitConverter.ToInt32(data, 0);
                        if (data.Length < sz)
                        {
                            data = new byte[sz];
                        }
                        if (fs.Read(data, 0, sz) != sz)
                        {
                            break;
                        }
                        Server.LZW lzw = new Server.LZW();
                        if (data2 == null || data2.Length < 20 * sz)
                        {
                            data2 = new byte[20 * sz];
                        }
                        int sz2 = lzw.from_lzw(data, data2);
                        int i   = 0;
                        while (i < sz2)
                        {
                            int szStruct = VideoHead.GetShort(data2, i);
                            if (szStruct < 0)
                            {
                                stop = true;
                                break;
                            }
                            int szData = VideoHead.GetInt(data2, i + 6);
                            if (szData < 0)
                            {
                                stop = true;
                                break;
                            }
                            int szCaption = VideoHead.GetShort(data2, i + 12);
                            if (szCaption < 0)
                            {
                                stop = true;
                                break;
                            }
                            i += szStruct + szData;
                            if (szCaption > 0 && i <= sz2)
                            {
                                string s = GetCaption(data2, i, szCaption);
                                if (!captions.Contains(s))
                                {
                                    captions.Add(s);
                                }
                                i += szCaption;
                            }
                        }
                    }

/*
 *                                      while (fs.Read(data, 0, 2) > 0)
 *                                      {
 *                                              int szStruct = VideoHead.GetShort(data, 0);
 *                                              if (szStruct < 0) break;
 *                                              fs.Read(data, 2, szStruct - 2);
 *                                              int szData = VideoHead.GetInt(data, 6);
 *                                              if (szData < 0) break;
 *                                              int szCaption = VideoHead.GetShort(data, 12);
 *                                              if (szCaption < 0) break;
 *                                              fs.Seek(szData, System.IO.SeekOrigin.Current);
 *                                              if (szCaption > 0 && fs.Length > fs.Position)
 *                                              {
 *                                                      int c = fs.Read(data, 0, szCaption);
 *                                                      if (c == szCaption)
 *                                                      {
 *                                                              string s = GetCaption(data, 0, szCaption);
 *                                                              if (!captions.Contains(s))
 *                                                                      captions.Add(s);
 *                                                      }
 *                                              }
 *                                      }
 */
                }
                catch
                {
                    if (captions.Count == 0)
                    {
                        bad = true;
                    }
                }
            }
            else
            {
                bad = true;
            }
            fs.Close();
        }