Пример #1
0
 internal string GetInput(BatchCommandContext context, string videoInput)
 {
     string input;
     if(String.IsNullOrEmpty(videoInput))
         input = "video = last";
     else
         input = String.Format(@"video = DirectShowSource(""{0}"")",
             Path.Combine(context.path, videoInput));
     return input;
 }
Пример #2
0
 public override void WriteToAvs(BatchCommandContext context)
 {
     var input = GetInput(context, VideoInput);
     var prev = Path.Combine(context.path, VideoPrev);
     var script = String.Format(@"
                     {0}
                     prev = DirectShowSource(""{1}"")
                     CrossFadeTime(video, prev, {2})
                   ", input, prev, EffectDuration);
     WriteAvsScript(context, script);
 }
Пример #3
0
 public override void WriteToBatch(BatchCommandContext context)
 {
     var temp="ConcatFilesList.txt";
     File.WriteAllText(temp, Files.Select(z => "file '" + z + "'").Aggregate((a, b) => a + "\r\n" + b));
     var args = "-f concat -i ConcatFilesList.txt ";
     if (AudioOnly)
         args += " -acodec copy ";
     else
         args += " -c copy ";
     args+=Result;
     WriteFFMPEGCommand(context, args);
     //File.Delete(temp);
 }
Пример #4
0
        // public IList<ProcessingItem> Items { get { return items.AsReadOnly(); } }
        public void WritePartToBatch(BatchCommandContext context)
        {
            FinalizePart();

            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("========  {0}  ========", PartNumber);
            Console.ForegroundColor = ConsoleColor.Gray;

            //// pre-processing
            //context.batFile.WriteLine(@"..\ImageGenerator.exe ""{0}"" ""{1}"" ""{2}"" ""{3}"" ""{4}"" 1280 720 ""{5}""",
            //    "..\\picture.jpg",
            //    "..\\titles.txt",
            //    Title,
            //    "titles.txt",
            //    PartNumber,
            //    String.Format("intro_for_{0}.png", PartNumber)
            //    );

            foreach (var item in items)
            {
                Console.WriteLine(item.Caption);
                item.WriteToBatch(context);  // writes effects to .avs AND encoding command to .bat
            }

            if (!context.lowQuality)
            {
                // processing (concatenation)
                var listFile = new StreamWriter(String.Format("concat_{0}.txt", PartNumber));
                foreach (var item in items)
                    listFile.WriteLine("file '{0}'", item.ResultFilename);
                listFile.Close();

            }
            else
            {
                // recode to "low quality" and concatenate
                var listFile = new StreamWriter(String.Format("concat_{0}.txt", PartNumber));
                Directory.CreateDirectory(RecodeDir);
                foreach (var item in items) {
                    var name = Path.GetFileName(item.ResultFilename);
                    var newName = Path.Combine(RecodeDir, name);
                    context.batFile.WriteLine("ffmpeg -i {0} -vcodec copy -acodec libmp3lame -ar 44100 -ab 32k {1}", item.ResultFilename, newName);
                    listFile.WriteLine("file '{0}'", item.ResultFilename);
                }
                listFile.Close();
            }
            context.batFile.WriteLine("ffmpeg -f concat -i concat_{0}.txt -qscale 0 result-{0}{1}.avi", PartNumber, context.lowQuality ? "_low" : "");

            // post-processing
            // TODO
        }
Пример #5
0
        // ffmpeg execution string for .BAT file
        public override void WriteToBatch(BatchCommandContext context)
        {
            // open script 'AvsFilename' and produce video 'Filename'
            // take care of high and low profiles

            if (String.IsNullOrEmpty(AvsFilename)) return;
            Directory.CreateDirectory(processingDir);
            var avsContext = new BatchCommandContext
                {
                    batFile = new StreamWriter(AvsFilename, false, Encoding.GetEncoding(1251)),
                    path = pathToBase,  // NOTE: not FFMPEG, actually
                    lowQuality = context.lowQuality
                };
            WriteAvsScript(avsContext);
            avsContext.batFile.Close();

            // AviSynth outputs raw (?) video, so we need to recode it to match other clips' properties
            // NOTE: no need to deal with HIGH/LOW profiles for now.
            context.batFile.WriteLine("ffmpeg -i {0} -vf scale=1280:720 -r 30 -q:v 0 -acodec libmp3lame -ar 44100 -ab 32k {1}", AvsFilename, ResultFilename);
        }
Пример #6
0
        public void WriteFFMPEGCommand(BatchCommandContext context, string artuments)
        {
            context.batFile.WriteLine("ffmpeg " + artuments);

            /*Console.WriteLine("FFMPEG " + artuments);
             * Console.WriteLine();
             * var process = new Process();
             * process.StartInfo.FileName = context.FFMPEGPath;
             * process.StartInfo.Arguments = artuments;
             * process.StartInfo.UseShellExecute = false;
             * process.Start();
             * process.WaitForExit();
             * if (process.ExitCode != 0)
             * {
             *  Console.BackgroundColor = ConsoleColor.Red;
             *  Console.ForegroundColor = ConsoleColor.Black;
             *  Console.WriteLine("ERROR");
             *  Console.ReadKey();
             * }
             */
        }
Пример #7
0
 public override void WriteToBatch(BatchCommandContext context)
 {
     if (context.lowQuality)
     {
         WriteFFMPEGCommand(context,
             string.Format("-i {0} -ss {1} -t {2} -acodec copy -vn {3}",
                 VideoInput,
                 MS(StartTime),
                 MS(Duration),
                 AudioOutput));
     }
     else
     {
         WriteFFMPEGCommand(context,
             string.Format("-i {0} -ss {1} -t {2} -vn -qscale 0 {3}",
                 VideoInput,
                 MS(StartTime),
                 MS(Duration),
                 AudioOutput));
     }
 }
Пример #8
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("Assembler <dir>");
                return;
            }

            Directory.SetCurrentDirectory(args[0]);  // to avoid ugly arg[0]+"\\blahblah"
            var titles = File.ReadAllLines(TitlesFileName);
            var subtitles = File.ReadAllLines(SubtitlesFileName).ToList();

            int title = int.Parse(args[0]);  // assume <dir> has arbitrary name, not integer

            XDocument doc = XDocument.Load("list.xspf");

            var tracks = doc
                        .Elements()
                        .Where(z => z.Name.LocalName == "playlist")
                        .Elements()
                        .Where(z => z.Name.LocalName == "trackList")
                        .Elements()
                        .Select(z => z.Elements().Where(x => x.Name.LocalName == "location").FirstOrDefault())
                        .Select(z => z.Value)
                        .Select(z => z.Substring(8, z.Length - 8))
                        .Select(z => z.Replace("/", "\\"))
                        .Select(z=> new FileInfo(z).Name)
                        .ToList();

            var log = MontageCommandIO.ReadCommands("log.txt");

            var parts = CreateParts(tracks, log, title);

            var batFile = new StreamWriter("Assembly.bat", false, Encoding.GetEncoding(866));
            batFile.WriteLine("del processing\\processed*");
            batFile.WriteLine("del result*");

            var context = new BatchCommandContext
            {
                batFile = batFile,
                lowQuality = false
            };

            foreach (var part in parts.Parts)
            {
                part.WritePartToBatch(context);
            }

            batFile.Close();
        }
Пример #9
0
 internal void WriteAvsScript(BatchCommandContext avsContext, string avsScript)
 {
     avsContext.batFile.WriteLine(avsScript);
 }
Пример #10
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("Montager.exe <folder>");
                Console.ReadKey();
                return;
            }

            Environment.CurrentDirectory = args[0];
            var log = VideoLib.MontageCommandIO.ReadCommands("log.txt");
            var chunks = Montager.CreateChunks(log, "..\\face-converted.avi", "..\\desktop-converted.avi");

            var lines = chunks.Select(z => z.OutputVideoFile).ToList();
            var folder = new DirectoryInfo(".");

            File.WriteAllLines("ConcatFilesList.txt", lines.Select(z => "file 'chunks\\" + z + "'").ToList());

            using (var xspf = new StreamWriter("list.xspf"))
            {
                xspf.WriteLine(@"<?xml version=""1.0"" encoding=""UTF-8""?>
                <playlist xmlns=""http://xspf.org/ns/0/"" xmlns:vlc=""http://www.videolan.org/vlc/playlist/ns/0/"" version=""1"">
                <title>Плейлист</title>
                <trackList>
                ");

                int id = 0;
                foreach (var e in chunks)
                {
                        xspf.WriteLine(@"
                        <track>
                            <location>file:///{0}/chunks/{1}</location>
                            <duration>{2}</duration>
                            <extension application=""http://www.videolan.org/vlc/playlist/0"">
                            <vlc:id>{3}</vlc:id>
                            </extension>
                        </track>"
                            , folder.FullName.Replace("\\", "/"), e.OutputVideoFile, 0, id++);
                }

                xspf.WriteLine(@"
                    </trackList>

                    </playlist>");

            }

            File.WriteAllLines("Recode.bat",
                new string[]
                {
                "ffmpeg -i face.mp4    -vf scale=1280:720 -r 30 -q:v 0 -acodec libmp3lame -ar 44100 -ab 32k face-converted.avi",
                "ffmpeg -i desktop.avi -vf scale=1280:720 -r 30 -qscale 0 -an desktop-converted.avi"
                });

            var batFile = OpenMontageBat("MakeChunksLow.bat");

            var context = new BatchCommandContext
            {
                batFile = batFile,
                lowQuality = true
            };
            foreach (var e in Montager.Processing1(chunks, "result.avi"))
            {
                Console.ForegroundColor = ConsoleColor.DarkCyan;
                Console.WriteLine(e.Caption);
                Console.ForegroundColor = ConsoleColor.Gray;
                e.WriteToBatch(context);
            }

            CloseMontageBat(batFile);

            batFile = OpenMontageBat("MakeChunksHigh.bat");

            context = new BatchCommandContext
            {
                batFile = batFile,
                lowQuality = false
            };
            foreach (var e in Montager.Processing1(chunks, "result.avi"))
            {
                Console.ForegroundColor = ConsoleColor.DarkCyan;
                Console.WriteLine(e.Caption);
                Console.ForegroundColor = ConsoleColor.Gray;
                e.WriteToBatch(context);
            }

            CloseMontageBat(batFile);
        }
Пример #11
0
 public abstract void WriteToAvs(BatchCommandContext avsContext);
Пример #12
0
 public override void WriteToAvs(BatchCommandContext context)
 {
     var input = GetInput(context, VideoInput);
     Settings["image"] = Path.Combine(context.path, Settings["image"]);
     var paramString = String.Join(
         ", ",
         Settings.Select(pair => String.Format(@"{0}=""{1}""", pair.Key, pair.Value))
         );
     var script = String.Format(@"
                     {0}
                     AddWatermarkPNG(video, {1})
                   ", input, paramString);
     WriteAvsScript(context, script);
 }
Пример #13
0
 public override void WriteToAvs(BatchCommandContext context)
 {
     var pathToReference = Path.Combine(context.path, VideoReference);
     var pathToImage = Path.Combine(context.path, ImageFile);
     var script = String.Format(@"
                     video = DirectShowSource(""{0}"")
                     Intro(video, ""{1}"", {2})
                   ", pathToReference, pathToImage, EffectDuration);
     WriteAvsScript(context, script);
 }
Пример #14
0
 public override void WriteToAvs(BatchCommandContext context)
 {
     var input = GetInput(context, VideoInput);
     var script = String.Format(@"
                     {0}
                     FadeOutTime(video, {1})
                   ", input, EffectDuration);
     WriteAvsScript(context, script);
 }
Пример #15
0
 public override void WriteToBatch(BatchCommandContext context)
 {
     File.Delete(FileName);
 }
Пример #16
0
 public abstract void WriteToBatch(BatchCommandContext context);
Пример #17
0
        // transformations to write to .AVS file
        private void WriteAvsScript(BatchCommandContext context)
        {
            // chain transformations inside .avs script
            // return video
            // NOTE: do not rely on SourceFilename, use data supplied in AviSynthCommands!

            context.batFile.WriteLine("import(\"{0}\")", AviSynthCommand.LibraryPath);
            foreach (var t in Transformations)
                t.WriteToAvs(context);
        }
Пример #18
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("Montager.exe <folder>");
                Console.ReadKey();
                return;
            }

            Environment.CurrentDirectory = args[0];
            var log    = VideoLib.MontageCommandIO.ReadCommands("log.txt");
            var chunks = Montager.CreateChunks(log, "..\\face-converted.avi", "..\\desktop-converted.avi");


            var lines  = chunks.Select(z => z.OutputVideoFile).ToList();
            var folder = new DirectoryInfo(".");

            File.WriteAllLines("ConcatFilesList.txt", lines.Select(z => "file 'chunks\\" + z + "'").ToList());

            using (var xspf = new StreamWriter("list.xspf"))
            {
                xspf.WriteLine(@"<?xml version=""1.0"" encoding=""UTF-8""?>
                <playlist xmlns=""http://xspf.org/ns/0/"" xmlns:vlc=""http://www.videolan.org/vlc/playlist/ns/0/"" version=""1"">
	            <title>Плейлист</title>
	            <trackList>
                ");

                int id = 0;
                foreach (var e in chunks)
                {
                    xspf.WriteLine(@"
		                <track>
			                <location>file:///{0}/chunks/{1}</location>
			                <duration>{2}</duration>
			                <extension application=""http://www.videolan.org/vlc/playlist/0"">
			                <vlc:id>{3}</vlc:id>
			                </extension>
		                </track>"
                                   , folder.FullName.Replace("\\", "/"), e.OutputVideoFile, 0, id++);
                }

                xspf.WriteLine(@"
	                </trackList>
                   
                    </playlist>");
            }

            File.WriteAllLines("Recode.bat",
                               new string[]
            {
                "ffmpeg -i face.mp4    -vf scale=1280:720 -r 30 -q:v 0 -acodec libmp3lame -ar 44100 -ab 32k face-converted.avi",
                "ffmpeg -i desktop.avi -vf scale=1280:720 -r 30 -qscale 0 -an desktop-converted.avi"
            });



            var batFile = OpenMontageBat("MakeChunksLow.bat");

            var context = new BatchCommandContext
            {
                batFile    = batFile,
                lowQuality = true
            };

            foreach (var e in Montager.Processing1(chunks, "result.avi"))
            {
                Console.ForegroundColor = ConsoleColor.DarkCyan;
                Console.WriteLine(e.Caption);
                Console.ForegroundColor = ConsoleColor.Gray;
                e.WriteToBatch(context);
            }

            CloseMontageBat(batFile);


            batFile = OpenMontageBat("MakeChunksHigh.bat");

            context = new BatchCommandContext
            {
                batFile    = batFile,
                lowQuality = false
            };
            foreach (var e in Montager.Processing1(chunks, "result.avi"))
            {
                Console.ForegroundColor = ConsoleColor.DarkCyan;
                Console.WriteLine(e.Caption);
                Console.ForegroundColor = ConsoleColor.Gray;
                e.WriteToBatch(context);
            }

            CloseMontageBat(batFile);
        }
Пример #19
0
 public override void WriteToBatch(BatchCommandContext context)
 {
     WriteFFMPEGCommand(context,
         string.Format("-i {1} -i {0} -acodec copy -vcodec copy {2}",
             VideoInput,
             AudioInput,
             VideoOutput));
 }
Пример #20
0
        public void WriteFFMPEGCommand(BatchCommandContext context, string artuments)
        {
            context.batFile.WriteLine("ffmpeg " + artuments);

            /*Console.WriteLine("FFMPEG " + artuments);
            Console.WriteLine();
            var process = new Process();
            process.StartInfo.FileName = context.FFMPEGPath;
            process.StartInfo.Arguments = artuments;
            process.StartInfo.UseShellExecute = false;
            process.Start();
            process.WaitForExit();
            if (process.ExitCode != 0)
            {
                Console.BackgroundColor = ConsoleColor.Red;
                Console.ForegroundColor = ConsoleColor.Black;
                Console.WriteLine("ERROR");
                Console.ReadKey();
            }
            */
        }