Exemplo n.º 1
0
        public AssSubtitleRenderer()
        {
            _library  = AssLibrary.Create();
            _renderer = _library.CreateRenderer();

            _renderer.SetFonts("Arial");
        }
Exemplo n.º 2
0
        private static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("Usage: Test.exe <ASS path> <time in seconds> [<output PPM path>]");

                return;
            }

            var inputAssPath = args[0];
            var assTime      = double.Parse(args[1]);

            string outputPpmPath;

            if (args.Length < 3)
            {
                var    fileInfo = new FileInfo(inputAssPath);
                string baseName;

                if (string.IsNullOrEmpty(fileInfo.Extension))
                {
                    baseName = fileInfo.Name;
                }
                else
                {
                    baseName = fileInfo.Name.Substring(0, fileInfo.Name.Length - fileInfo.Extension.Length);
                }

                outputPpmPath = Path.Combine(fileInfo.DirectoryName, baseName + ".ppm");
            }
            else
            {
                outputPpmPath = args[2];
            }

            using (var lib = AssLibrary.Create()) {
                using (var renderer = lib.CreateRenderer()) {
                    renderer.SetFonts("Arial");
                    renderer.SetFrameSize(1280, 720);

                    var text   = File.ReadAllText(inputAssPath);
                    var source = new StringAssSource(text);

                    using (var track = lib.CreateTrack(source)) {
                        var ts    = (long)TimeSpan.FromSeconds(assTime).TotalMilliseconds;
                        var image = renderer.RenderFrame(track, ts);

                        var buf = image.Blend();

                        SaveImageAsPpm(buf, outputPpmPath);
                    }
                }
            }
        }