Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Diagnostics;
- using System.IO;
- using System.Threading;
- namespace ConsoleApp4
- {
- class Program
- {
- static string[] types = { ".mp4", ".mkv", ".flv", ".mov", ".webm", ".avi" };
- static Process current_proc = null;
- static void check_thread()
- {
- while(true)
- {
- if (current_proc != null)
- {
- string input_ = Console.ReadLine();
- current_proc.StandardInput.WriteLine(input_);
- }
- Thread.Sleep(50);
- }
- }
- static bool is_video(string file)
- {
- foreach(string type in types)
- {
- if (file.Contains(type))
- return true;
- }
- return false;
- }
- static string get_file_type(string file)
- {
- foreach (string type in types)
- {
- if (file.Contains(type))
- return type;
- }
- return "";
- }
- static void Main(string[] args)
- {
- Console.WriteLine("Would you like to delete the original files after they have been formatted? (y/n)");
- string szDeleteFileAfter = Console.ReadLine();
- bool bDeleteFileAfter = szDeleteFileAfter.Contains("y");
- string path = Directory.GetCurrentDirectory() + "\\";
- string[] files = Directory.GetFiles(path);
- string[] filtered = { };
- foreach(string file in files)
- {
- if(is_video(file))
- {
- Array.Resize(ref filtered, filtered.Length + 1);
- filtered[filtered.Length - 1] = file;
- }
- }
- Thread t = new Thread((ThreadStart)check_thread);
- t.Start();
- foreach (string file in filtered)
- {
- string file_type = get_file_type(file);
- string output = (file.Replace(file_type, "") + "_output" + file_type);
- string input = file;
- string command = "ffmpeg -i \u201D" + input + "\u201D \u201D" + output + "\u201D & exit";
- Process p = new Process();
- p.StartInfo.UseShellExecute = false;
- p.StartInfo.CreateNoWindow = false;
- p.StartInfo.RedirectStandardOutput = true;
- p.StartInfo.RedirectStandardInput = true;
- p.StartInfo.FileName = "cmd.exe";
- p.StartInfo.Arguments = command;
- p.Start();
- p.StandardInput.WriteLine(command);
- current_proc = p;
- p.WaitForExit();
- if (bDeleteFileAfter)
- {
- File.Delete(file);
- }
- }
- t.Abort();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement