Example #1
0
            public void WriteToStream(Stream stream)
            {
                byte[] regionSubtitle = MakeSubtitleRegions();
                stream.Write(new byte[] { 0, 0, 1, 0xbf }, 0, 4); // MPEG-2 Private stream 2
                int size = regionSubtitle.Length + 15;
                stream.WriteWord(size);
                stream.WriteByte(SegmentTypeDialogPresentation); // 0x82
                stream.WriteWord(size - 3);
                stream.WritePts(StartPts);
                stream.WritePts(EndPts);
                if (PaletteUpdate)
                {
                    stream.WriteWord(PaletteUpdates.Count);
                    foreach (var palette in PaletteUpdates)
                    {
                        stream.WriteByte((byte)palette.PaletteEntryId);
                        stream.WriteByte((byte)palette.Y);
                        stream.WriteByte((byte)palette.Cb);
                        stream.WriteByte((byte)palette.Cr);
                        stream.WriteByte((byte)palette.T);
                    }
                }
                else
                {
                    stream.WriteByte(0); // 1 bit = palette update (0=no update), next 7 bits reserved
                }
                stream.WriteByte((byte)Regions.Count); // number of regions

                stream.Write(regionSubtitle, 0, regionSubtitle.Length);
            }
Example #2
0
            public static void WriteToStream(Stream stream, string text, TimeCode start, TimeCode end, int regionStyleId, bool forced)
            {
                byte[] regionSubtitle = MakeSubtitleRegion(text);
                stream.Write(new byte[] { 0, 0, 1, 0xbf }, 0, 4); // MPEG-2 Private stream 2
                int size = regionSubtitle.Length + 2 + 1 + 5 + 5 + 4;
                stream.WriteWord(size);
                stream.WriteByte(SegmentTypeDialogPresentation); // 0x82
                stream.WriteWord(size-3);
                stream.WritePts(start);
                stream.WritePts(end);
                stream.WriteByte(0); // 1 bit = palette update (0=no update), next 7 bits reserved
                stream.WriteByte(1); // number of regions

                //first byte=continuous_present_flag, second byte=force, next 6 bits reserved
                if (forced)
                    stream.WriteByte(Helper.B01000000);
                else
                    stream.WriteByte(0);

                stream.WriteByte((byte)regionStyleId);
                stream.Write(regionSubtitle, 0, regionSubtitle.Length);
            }