Advertisement
Guest User

Untitled

a guest
Oct 3rd, 2020
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. using System;
  2. using System.Diagnostics;
  3. using System.IO;
  4. using System.Threading;
  5.  
  6. namespace ConsoleApp4
  7. {
  8. class Program
  9. {
  10. static string[] types = { ".mp4", ".mkv", ".flv", ".mov", ".webm", ".avi" };
  11. static Process current_proc = null;
  12. static void check_thread()
  13. {
  14. while(true)
  15. {
  16. if (current_proc != null)
  17. {
  18. string input_ = Console.ReadLine();
  19. current_proc.StandardInput.WriteLine(input_);
  20. }
  21. Thread.Sleep(50);
  22. }
  23. }
  24. static bool is_video(string file)
  25. {
  26. foreach(string type in types)
  27. {
  28. if (file.Contains(type))
  29. return true;
  30. }
  31. return false;
  32. }
  33. static string get_file_type(string file)
  34. {
  35. foreach (string type in types)
  36. {
  37. if (file.Contains(type))
  38. return type;
  39. }
  40. return "";
  41. }
  42. static void Main(string[] args)
  43. {
  44. Console.WriteLine("Would you like to delete the original files after they have been formatted? (y/n)");
  45. string szDeleteFileAfter = Console.ReadLine();
  46. bool bDeleteFileAfter = szDeleteFileAfter.Contains("y");
  47.  
  48. string path = Directory.GetCurrentDirectory() + "\\";
  49. string[] files = Directory.GetFiles(path);
  50. string[] filtered = { };
  51. foreach(string file in files)
  52. {
  53. if(is_video(file))
  54. {
  55. Array.Resize(ref filtered, filtered.Length + 1);
  56. filtered[filtered.Length - 1] = file;
  57. }
  58. }
  59. Thread t = new Thread((ThreadStart)check_thread);
  60. t.Start();
  61.  
  62.  
  63. foreach (string file in filtered)
  64. {
  65. string file_type = get_file_type(file);
  66. string output = (file.Replace(file_type, "") + "_output" + file_type);
  67. string input = file;
  68. string command = "ffmpeg -i \u201D" + input + "\u201D \u201D" + output + "\u201D & exit";
  69.  
  70. Process p = new Process();
  71. p.StartInfo.UseShellExecute = false;
  72. p.StartInfo.CreateNoWindow = false;
  73. p.StartInfo.RedirectStandardOutput = true;
  74. p.StartInfo.RedirectStandardInput = true;
  75. p.StartInfo.FileName = "cmd.exe";
  76. p.StartInfo.Arguments = command;
  77. p.Start();
  78.  
  79. p.StandardInput.WriteLine(command);
  80. current_proc = p;
  81.  
  82. p.WaitForExit();
  83. if (bDeleteFileAfter)
  84. {
  85. File.Delete(file);
  86. }
  87. }
  88. t.Abort();
  89. }
  90. }
  91. }
  92.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement