Beispiel #1
0
        private static void AddPesPacket(List <DvbSubPes> list, List <Packet> packetList)
        {
            int bufferSize = 0;

            foreach (var p in packetList)
            {
                bufferSize += p.Payload.Length;
            }

            var pesData  = new byte[bufferSize];
            int pesIndex = 0;

            foreach (var p in packetList)
            {
                Buffer.BlockCopy(p.Payload, 0, pesData, pesIndex, p.Payload.Length);
                pesIndex += p.Payload.Length;
            }

            DvbSubPes pes;

            if (VobSubParser.IsMpeg2PackHeader(pesData))
            {
                pes = new DvbSubPes(pesData, Mpeg2Header.Length);
            }
            else if (VobSubParser.IsPrivateStream1(pesData, 0))
            {
                pes = new DvbSubPes(pesData, 0);
            }
            else
            {
                pes = new DvbSubPes(pesData, 0);
            }
            list.Add(pes);
        }
Beispiel #2
0
        public static bool IsDvbSup(string fileName)
        {
            try
            {
                byte[] pesData = File.ReadAllBytes(fileName);
                if (pesData[0] != 0x20 || pesData[1] != 0 || pesData[2] != 0x0F)
                {
                    return(false);
                }

                var pes = new DvbSubPes(0, pesData);
                return(pes.SubtitleSegments.Count > 0);
            }
            catch
            {
                return(false);
            }
        }
Beispiel #3
0
        public static List <TransportStreamSubtitle> GetDvbSup(string fileName)
        {
            byte[] pesData = File.ReadAllBytes(fileName);
            var    list    = new List <DvbSubPes>();
            int    index   = 0;

            while (index < pesData.Length - 10)
            {
                var pes = new DvbSubPes(index, pesData);
                index = pes.Length + 1;
                list.Add(pes);
            }

            var subtitles = new List <TransportStreamSubtitle>();
            int seconds   = 0;

            for (int i = 0; i < list.Count; i++)
            {
                var pes = list[i];
                pes.ParseSegments();
                if (pes.ObjectDataList.Count > 0)
                {
                    var sub = new TransportStreamSubtitle();
                    sub.StartMilliseconds = (ulong)seconds * 1000UL;
                    seconds += pes.PageCompositions[0].PageTimeOut;
                    if (pes.PageCompositions.Count > 0)
                    {
                        sub.EndMilliseconds = sub.StartMilliseconds + (ulong)pes.PageCompositions[0].PageTimeOut * 1000UL;
                    }
                    else
                    {
                        sub.EndMilliseconds = sub.StartMilliseconds + 2500;
                    }

                    sub.Pes = pes;
                    subtitles.Add(sub);
                }
                if (pes.PageCompositions.Count > 0)
                {
                    seconds += pes.PageCompositions[0].PageTimeOut;
                }
            }
            return(subtitles);
        }
        /// <summary>
        /// Can be used with e.g. MemoryStream or FileStream
        /// </summary>
        /// <param name="ms">Input stream</param>
        public void Parse(Stream ms)
        {
            var dataIndices = GetDataIndicesAndPesStart(ms, out var dvbPesStartIndex);

            if (dvbPesStartIndex <= 0)
            {
                return;
            }

            ms.Position = 0;
            foreach (var dataIndex in dataIndices)
            {
                ms.Seek(dvbPesStartIndex + dataIndex.Offset, SeekOrigin.Begin);
                var pesData   = new byte[dataIndex.Length];
                var bytesRead = ms.Read(pesData, 0, pesData.Length);
                if (bytesRead < pesData.Length)
                {
                    break; // incomplete packet at end-of-file
                }

                DvbSubPes pes;
                if (VobSubParser.IsMpeg2PackHeader(pesData))
                {
                    pes = new DvbSubPes(pesData, Mpeg2Header.Length);
                }
                else if (VobSubParser.IsPrivateStream1(pesData, 0))
                {
                    pes = new DvbSubPes(pesData, 0);
                }
                else
                {
                    pes = new DvbSubPes(0, pesData);
                }

                pes.PresentationTimestamp = dataIndex.Pts;
                _dvbSubs.Add(pes);
            }
        }