Пример #1
0
        public void VancTest()
        {
            var s         = VancDataWriter.GenerateLinesFromText("Hi!", 0)[0];
            var smpte291M = new Smpte291M(HexStringToByteArray(s));
            var result    = smpte291M.GetText(0, true, new CommandState());

            Assert.AreEqual("Hi!", result);
        }
Пример #2
0
        public override string ToText(Subtitle subtitle, string title)
        {
            var sb = new StringBuilder();

            sb.AppendLine(@"File Format=MacCaption_MCC V1.0
///////////////////////////////////////////////////////////////////////////////////
// Computer Prompting and Captioning Company
// Ancillary Data Packet Transfer File
//
// Permission to generate this format is granted provided that
// 1. This ANC Transfer file format is used on an as-is basis and no warranty is given, and
// 2. This entire descriptive information text is included in a generated .mcc file.
//
// General file format:
// HH:MM:SS:FF(tab)[Hexadecimal ANC data in groups of 2 characters]
// Hexadecimal data starts with the Ancillary Data Packet DID (Data ID defined in S291M)
// and concludes with the Check Sum following the User Data Words.
// Each time code line must contain at most one complete ancillary data packet.
// To transfer additional ANC Data successive lines may contain identical time code.
// Time Code Rate=[24, 25, 30, 30DF, 50, 60]
//
// ANC data bytes may be represented by one ASCII character according to the following schema:
// G FAh 00h 00h
// H 2 x (FAh 00h 00h)
// I 3 x (FAh 00h 00h)
// J 4 x (FAh 00h 00h)
// K 5 x (FAh 00h 00h)
// L 6 x (FAh 00h 00h)
// M 7 x (FAh 00h 00h)
// N 8 x (FAh 00h 00h)
// O 9 x (FAh 00h 00h)
// P FBh 80h 80h
// Q FCh 80h 80h
// R FDh 80h 80h
// S 96h 69h
// T 61h 01h
// U E1h 00h 00h
// Z 00h
//
///////////////////////////////////////////////////////////////////////////////////");
            sb.AppendLine();
            sb.AppendLine("UUID=" + Guid.NewGuid().ToString().ToUpperInvariant());// UUID=9F6112F4-D9D0-4AAF-AA95-854710D3B57A
            sb.AppendLine("Creation Program=Subtitle Edit");
            sb.AppendLine($"Creation Date={DateTime.Now.ToLongDateString()}");
            sb.AppendLine($"Creation Time={DateTime.Now:HH:mm:ss}");
            sb.AppendLine("Time Code Rate=30DF"); // 30DF = 30 drop frame = 29.97
            sb.AppendLine();

            Configuration.Settings.General.CurrentFrameRate = GetFrameForCalculation(29.97);

            var timeCode = new TimeCode();

            if (subtitle.Paragraphs.Count > 0 && subtitle.Paragraphs[0].StartTime.Hours > 0)
            {
                timeCode = new TimeCode(subtitle.Paragraphs[0].StartTime.Hours, 0, 0, 0);
            }

            var i       = 0;
            var counter = 0;
            int frameNo = 0;

            while (i < subtitle.Paragraphs.Count)
            {
                var p = subtitle.Paragraphs[i];
                if (timeCode.TotalMilliseconds < p.StartTime.TotalMilliseconds)
                {
                    // write empty lines (filler)
                    var empty = VancDataWriter.GenerateEmpty(counter++);
                    var s     = $"{ToTimeCode(timeCode.TotalMilliseconds)}\t{CompressHex(empty)}";
                    sb.AppendLine(s);
                    frameNo = StepToNextFrame(frameNo, timeCode);
                    continue;
                }

                // write text lines
                var lines = VancDataWriter.GenerateLinesFromText(p.Text, counter);
                counter += lines.Length;
                foreach (var line in lines)
                {
                    sb.AppendLine($"{ToTimeCode(p.StartTime.TotalMilliseconds)}\t{CompressHex(line)}");
                }
                frameNo = StepToNextFrame(frameNo, timeCode);

                // filler between start/end text
                while (timeCode.TotalMilliseconds < p.EndTime.TotalMilliseconds)
                {
                    // write empty lines (filler)
                    var empty = VancDataWriter.GenerateEmpty(counter++);
                    sb.AppendLine($"{ToTimeCode(timeCode.TotalMilliseconds)}\t{CompressHex(empty)}");
                    frameNo = StepToNextFrame(frameNo, timeCode);
                }

                // write end text
                var endTimeText = VancDataWriter.GenerateTextInit(counter++);
                sb.AppendLine($"{ToTimeCode(p.EndTime.TotalMilliseconds)}\t{CompressHex(endTimeText)}");
                frameNo = StepToNextFrame(frameNo, timeCode);
                i++;
            }

            //int counter = 0;
            //for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            //{
            //    var p = subtitle.Paragraphs[i];
            //    if (i == 0)
            //    {
            //        var firstText = VancDataWriter.GenerateTextInit(counter++);
            //        sb.AppendLine($"{ToTimeCode(p.StartTime.TotalMilliseconds)}\t{CompressHex(firstText)}");
            //    }
            //    var lines = VancDataWriter.GenerateLinesFromText(p.Text, counter);
            //    counter += lines.Length;
            //    foreach (var line in lines)
            //    {
            //        sb.AppendLine($"{ToTimeCode(p.StartTime.TotalMilliseconds)}\t{CompressHex(line)}");
            //    }
            //    var endTimeText = VancDataWriter.GenerateTextInit(counter++);
            //    sb.AppendLine($"{ToTimeCode(p.EndTime.TotalMilliseconds)}\t{CompressHex(endTimeText)}");
            //}

            var lastLine = VancDataWriter.GenerateEmpty(counter);

            sb.AppendLine($"{ToTimeCode(timeCode.TotalMilliseconds)}\t{CompressHex(lastLine)}");

            return(sb.ToString());
        }