private void runAutocombineAV(string vid, string aud)
        {
            var vidOnly = Path.GetDirectoryName(vid) + "/" + Path.GetFileNameWithoutExtension(vid) +
                          "_{vidonly}" + Path.GetExtension(vid);
            var outFile = Path.GetDirectoryName(vid) + "/" + Path.GetFileNameWithoutExtension(vid) +
                          "_{out}" + Path.GetExtension(vid);

            if (File.Exists(outFile))
            {
                Utils.SoftDelete(outFile);
            }

            var args = Utils.SplitByString("-i|" + vid + "|-an|-c:v|copy|" + vidOnly, "|");
            var info = new ProcessStartInfo();

            info.FileName               = CsDownloadVidFilepaths.GetFfmpeg();
            info.Arguments              = Utils.CombineProcessArguments(args.ToArray());
            info.CreateNoWindow         = true;
            info.RedirectStandardError  = true;
            info.RedirectStandardOutput = true;
            info.UseShellExecute        = false;
            _runner.RunProcessSync(info, "AutocombineAV: 1) Ensuring video-only version " + vid);
            Utils.AssertTrue(File.Exists(vidOnly) && new FileInfo(vidOnly).Length > 0, "Did not write to " + vidOnly);

            args                        = Utils.SplitByString("-i|" + vidOnly + "|-i|" + aud + "|-c:a|copy|-c:v|copy|" + outFile, "|");
            info                        = new ProcessStartInfo();
            info.FileName               = CsDownloadVidFilepaths.GetFfmpeg();
            info.Arguments              = Utils.CombineProcessArguments(args.ToArray());
            info.CreateNoWindow         = true;
            info.RedirectStandardError  = true;
            info.RedirectStandardOutput = true;
            info.UseShellExecute        = false;
            _runner.RunProcessSync(info, "AutocombineAV: 2) Putting A+V together " + vid);
            Utils.AssertTrue(File.Exists(outFile) && new FileInfo(outFile).Length > 0, "Did not write to " + outFile);

            _runner.Trace("AutocombineAV: 3) Deleting temporaries");
            Utils.SoftDelete(vidOnly);
            Utils.SoftDelete(vid);
            Utils.SoftDelete(aud);
        }
Example #2
0
        void MediaJoin(string[] lines, string outFormat)
        {
            var parentDirs = (from part in lines
                              select Path.GetDirectoryName(part)).Distinct();

            if (parentDirs.Count() != 1)
            {
                throw new CsDownloadVidException("Input files must be in same directory.");
            }

            var fileExts = (from part in lines select Path.GetExtension(part)).Distinct();

            if (fileExts.Count() != 1)
            {
                throw new CsDownloadVidException("Files have different extensions.");
            }

            var tmpList = parentDirs.First() + Utils.Sep + "temp_csdownloadvid_list.txt";

            if (File.Exists(tmpList))
            {
                File.Delete(tmpList);
                Utils.AssertTrue(!File.Exists(tmpList));
            }

            foreach (var part in lines)
            {
                var file = "file " + EscapeStringForFfmpeg(part) + "\n";
                File.AppendAllText(tmpList, file);
            }

            outFormat = outFormat == "auto" ? fileExts.ToArray()[0] : outFormat;
            var output = lines[0] + "_out" + outFormat;

            if (File.Exists(output))
            {
                throw new CsDownloadVidException("File already exists " + output);
            }

            var args = new List <string>();

            args.Add("-nostdin");
            args.Add("-f");
            args.Add("concat");
            args.Add("-safe"); // many versions of ffmpeg think windows full paths are unsafe
            args.Add("0");     // perhaps better to set current directory + use relative paths
            args.Add("-i");
            args.Add(tmpList);
            args.Add("-acodec");
            args.Add("copy");
            args.Add("-vcodec");
            args.Add("copy");
            args.Add(output);
            _runner.Trace("Saving to " + output);

            var info = new ProcessStartInfo();

            info.FileName               = CsDownloadVidFilepaths.GetFfmpeg();
            info.Arguments              = Utils.CombineProcessArguments(args.ToArray());
            info.CreateNoWindow         = true;
            info.RedirectStandardError  = true;
            info.RedirectStandardOutput = true;
            info.UseShellExecute        = false;
            _runner.RunProcessSync(info, "Join Media");

            if (File.Exists(tmpList))
            {
                File.Delete(tmpList);
            }
        }