public string SplitOneFileSynchronous(string input, double start, double length, int i, ref string log) { var outFilename = input + "." + string.Format( "{0}", i.ToString("D3")) + Path.GetExtension(input); var args = new List <string>(); args.Add("-nostdin"); args.Add("-i"); args.Add(input); // important: put the options -ss and -t between -i and output args.Add("-ss"); args.Add(start.ToString()); args.Add("-t"); args.Add(length.ToString()); args.Add("-acodec"); args.Add("copy"); args.Add("-vcodec"); args.Add("copy"); args.Add(outFilename); RunGetStdout(CsDownloadVidFilepaths.GetFfmpeg(), Utils.CombineProcessArguments(args.ToArray()), "split", outFilename, ref log); Utils.AssertTrue(File.Exists(outFilename)); return(outFilename); }
string GetFileWithFadeoutSynchronous(string input, double start, double fadeLength, int i, ref string log) { var outFilename = input + string.Format("_outfade{0}.wav", i.ToString("D2")); var args = new List <string>(); args.Add("-nostdin"); args.Add("-i"); args.Add(input); args.Add("-ss"); args.Add(start.ToString()); args.Add("-t"); args.Add(fadeLength.ToString()); args.Add("-vn"); // note: hours:min:seconds format does not seem to work in the fade spec. args.Add("-af"); args.Add(string.Format("afade=t=out:st={0}:d={1}", start.ToString(), fadeLength.ToString())); args.Add(outFilename); RunGetStdout(CsDownloadVidFilepaths.GetFfmpeg(), Utils.CombineProcessArguments(args.ToArray()), "get fadeout", outFilename, ref log); Utils.AssertTrue(File.Exists(outFilename)); return(outFilename); }
private ProcessStartInfo MakeTaskCombineAudioVideo(string audioFile, string videoFile, string output) { var args = new List <string>(); args.Add("-nostdin"); args.Add("-i"); args.Add(videoFile); args.Add("-i"); args.Add(audioFile); args.Add("-c:v"); args.Add("copy"); args.Add("-c:a"); 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; return(info); }
private void downloadFromWeb(string url) { lblShortStatus.Visible = true; txtStatus.Visible = true; var urlBeforeParam = Utils.SplitByString(url, "?")[0]; if (urlBeforeParam.EndsWith(".m3u") || urlBeforeParam.EndsWith(".m3u8")) { var ext = Utils.AskToConfirm( "Use mp4 (default) or .mkv (more resilient)?") ? ".mp4" : ".mkv"; var nameShort = Path.GetFileName(urlBeforeParam); var destName = Path.Combine(txtOutputDir.Text, Path.GetFileNameWithoutExtension(nameShort) + ext); MessageBox.Show("Downloading video (via m3u) to " + destName + "..."); Utils.AssertTrue(!File.Exists(destName), "File already exists here."); var args = new List <string>() { "-i", url, "-c", "copy" }; if (ext == ".mp4") { args.Add("-bsf:a"); args.Add("aac_adtstoasc"); } args.Add(destName); 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.RunInThread(() => { _runner.Trace("Downloading..."); _runner.RunProcessSync(info, "Download from web"); _runner.Trace("Download complete, to " + destName); }); } else { var destName = Path.Combine(txtOutputDir.Text, Path.GetFileName(urlBeforeParam)); MessageBox.Show("Downloading video to " + destName + "..."); Utils.AssertTrue(!File.Exists(destName), "File already exists here."); _runner.RunInThread(() => { _runner.Trace("Downloading..."); DownloadLatestPyScriptBase.DownloadFile(url, destName); _runner.Trace("Download complete, to " + destName); }); } }
private void doCustomEncode(string example, InputBoxHistory key) { var files = this.GetInputFiles(1); var cmd = InputBoxForm.GetStrInput("Command for the ffmpeg encoder:", example, key); if (String.IsNullOrEmpty(cmd)) { return; } else if (!cmd.Contains("%in%") && !Utils.AskToConfirm("Did not see '%in%', " + "won't process input files. Continue?")) { return; } if (!Utils.AskToConfirm("Run the command right now? (or copy the command line to the clipboard)")) { var s = ""; foreach (var file in files) { s += "\r\n\"" + CsDownloadVidFilepaths.GetFfmpeg() + "\" "; s += cmd.Replace("%in%", files[0]); } Clipboard.SetText(s); MessageBox.Show("Command was copied to the clipboard."); return; } RunToolHelper.RunAndCatch(() => { var infos = new List <ProcessStartInfo>(); foreach (var file in files) { var info = new ProcessStartInfo(); info.FileName = CsDownloadVidFilepaths.GetFfmpeg(); info.Arguments = cmd.Replace("%in%", file); info.CreateNoWindow = true; info.RedirectStandardError = true; info.RedirectStandardOutput = true; info.UseShellExecute = false; infos.Add(info); } _runner.RunProcesses(infos.ToArray(), "Custom encode"); }); }
private void btnDownload_Click(object sender, EventArgs e) { RunToolHelper.RunAndCatch(() => { if (chkDashToM4a.Checked || chkAutoCombineAV.Checked) { CsDownloadVidFilepaths.GetFfmpeg(); } GetOptionsFromUI(out List <string> urlsRet, out int waitBetween, out string filenamePattern, out string outDir); var formats = GetFormatsFromUI(); if (formats == null || formats.Length == 0) { throw new CsDownloadVidException("No format chosen."); } else if (formats.Any((fmt) => cbUsePytube.Checked != fmt.StartsWith("<Stream:"))) { throw new CsDownloadVidException("It looks like you've clicked " + "'use pytube instead of ytdl' half-way through-- when you change " + "this you have to start over at step 1."); } Configs.Current.Set(ConfigKey.SaveVideosTo, txtOutputDir.Text); _runner.SetWaitBetween(waitBetween); List <ProcessStartInfo> listInfos = new List <ProcessStartInfo>(); foreach (var url in urlsRet) { foreach (var fmt in formats) { listInfos.Add(GetStartInfo(url, fmt, false)); } } _runner.RunProcesses(listInfos.ToArray(), "downloading", () => { if (chkAutoCombineAV.Checked && Directory.Exists(txtOutputDir.Text)) { runAutocombineAVAll(txtOutputDir.Text); } }); }); }
private ProcessStartInfo MakeTask(bool audioOrVideo, string suggestedFormat, string file) { if (suggestedFormat.StartsWith(".")) { // let the user type ".m4a" as well as "m4a" suggestedFormat = suggestedFormat.Substring(1); } Utils.AssertTrue(suggestedFormat.Length > 0, "You did not provide a suggested format."); var args = new List <string>(); args.Add("-nostdin"); args.Add("-i"); args.Add(file); if (audioOrVideo) { var format = suggestedFormat == "auto" ? "m4a" : suggestedFormat; args.Add("-vn"); args.Add("-acodec"); args.Add("copy"); args.Add(file + "_audio." + format); } else { var format = suggestedFormat == "auto" ? "m4v" : suggestedFormat; args.Add("-an"); args.Add("-vcodec"); args.Add("copy"); args.Add(file + "_video." + format); } 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; return(info); }
string ConvertM4aToAacSynchronous(string input, ref string log) { Utils.AssertTrue(input.EndsWith(".m4a")); var outFilename = Path.GetDirectoryName(input) + Utils.Sep + Path.GetFileNameWithoutExtension(input) + ".aac"; var args = new List <string>(); args.Add("-nostdin"); args.Add("-i"); args.Add(input); args.Add("-acodec"); args.Add("copy"); args.Add(outFilename); RunGetStdout(CsDownloadVidFilepaths.GetFfmpeg(), Utils.CombineProcessArguments(args.ToArray()), "m4a to aac", outFilename, ref log); Utils.AssertTrue(File.Exists(outFilename)); return(outFilename); }
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); }
private void makeLouderOnes(string input) { foreach (var scale in new List <string>() { "2.0", "4.0", "8.0", "16.0", "32.0" }) { var outfile = input + ".makelouder" + scale + ".wav"; var args = new List <string>(); args.Add("-nostdin"); args.Add("-i"); args.Add(input); args.Add("-filter:a"); args.Add("volume=" + scale); args.Add(outfile); 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, "Make Louder"); if (!File.Exists(outfile)) { _runner.Trace("expected to see output at " + outfile); throw new Exception("expected to see output at " + outfile); } var pathOut = Utils.RunM4aConversion(outfile, "flac"); if (new FileInfo(pathOut).Length > 1) { File.Delete(outfile); } } }
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); } }
ProcessStartInfo GetStartInfo(string url, string format, bool listSupportedFormatsOnly) { var args = new List <string>(); args.Add("--ignore-config"); // don't look for global config file args.Add("--no-mark-watched"); args.Add("--no-call-home"); args.Add("--no-mtime"); // don't adjust the lmt of the file, it's confusing args.Add("--no-playlist"); if (listSupportedFormatsOnly) { args.Add("--list-formats"); args.Add("--simulate"); } else { args.Add("--format"); args.Add(format); // post-process, otherwise the m4a won't show correctly in some media players if (chkDashToM4a.Checked) { args.Add("--ffmpeg-location"); args.Add(CsDownloadVidFilepaths.GetFfmpeg()); } } if (cbUsePytube.Checked) { args.Add("--outputdir=" + txtOutputDir.Text); } else { var outputTemplate = Path.Combine(txtOutputDir.Text, txtFilenamePattern.Text); args.Add("--output"); args.Add(outputTemplate); } var sArgs = Utils.CombineProcessArguments(args.ToArray()); if (!string.IsNullOrWhiteSpace(txtAdditionalArgs.Text)) { sArgs += " " + txtAdditionalArgs.Text + " "; } sArgs += " " + Utils.CombineProcessArguments(new string[] { url }); var info = new ProcessStartInfo(); info.FileName = CsDownloadVidFilepaths.GetYtdlPath(this.cbUsePytube.Checked); info.Arguments = sArgs; info.CreateNoWindow = true; info.RedirectStandardError = true; info.RedirectStandardOutput = true; info.UseShellExecute = false; if (CsDownloadVidFilepaths.GetYtdlPath(this.cbUsePytube.Checked).EndsWith(".py")) { info.FileName = CsDownloadVidFilepaths.GetPython(); info.Arguments = "\"" + CsDownloadVidFilepaths.GetYtdlPath( this.cbUsePytube.Checked) + "\" " + sArgs; } return(info); }