Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2014
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.19 KB | None | 0 0
  1. private void Encoding(string[] GetFile)
  2. {
  3. using(AutoResetEvent OpusCheck = new AutoResetEvent(false))
  4. using (QU = new BlockingCollection<byte[]>())
  5. using (OpusEncoder = new Process())
  6. for (int i = 0; i < GetFile.Length; i++)
  7. {
  8. try
  9. {
  10. ReadBuffer = new byte[4096];
  11. string filename = Path.GetDirectoryName(GetFile[i]) + "\" + Path.GetFileNameWithoutExtension(GetFile[i]);
  12.  
  13. using (cmdCommands = new Process())
  14. {
  15.  
  16. cmdCommands.StartInfo.UseShellExecute = false;
  17. cmdCommands.StartInfo.CreateNoWindow = false;
  18. cmdCommands.StartInfo.FileName = SC.GetAVS4x264Path();
  19. cmdCommands.StartInfo.Arguments = string.Format(""{0}" --x264-binary "{1}" --colormatrix=bt709 {2} --output="{3}" -", filename + ".avs", SC.Getx264Path(), SC.Getx264Settings(true), filename + ".mkv");
  20. cmdCommands.Start();
  21. cmdCommands.WaitForExit();
  22.  
  23. if (EncodingStopped)
  24. break;
  25.  
  26. cmdCommands.StartInfo.UseShellExecute = false;
  27. cmdCommands.StartInfo.CreateNoWindow = true;
  28. cmdCommands.StartInfo.RedirectStandardOutput = true;
  29. cmdCommands.StartInfo.FileName = SC.GetAVS2PipeModPath();
  30. cmdCommands.StartInfo.Arguments = string.Format("{0} "{1}" -wav", SC.GetAVS2PipeModPath(), filename + ".avs");
  31. cmdCommands.Start();
  32.  
  33. Thread OpusThread = new Thread(() => OpusEncode(filename, OpusCheck));
  34. OpusThread.Start();
  35.  
  36. cmdCommands.StandardOutput.BaseStream.BeginRead(ReadBuffer, 0, ReadBuffer.Length, PipeWrite, null);
  37. cmdCommands.WaitForExit();
  38. OpusCheck.WaitOne();
  39. if (EncodingStopped)
  40. break;
  41.  
  42. cmdCommands = new Process();
  43. cmdCommands.StartInfo.UseShellExecute = false;
  44. cmdCommands.StartInfo.RedirectStandardError = true;
  45. cmdCommands.StartInfo.FileName = SC.GetMKVMergePath();
  46. cmdCommands.StartInfo.Arguments = (" -o "" + filename + "-muxed.mkv" "" + filename + ".mkv" " + """ + filename + ".opus"");
  47. cmdCommands.Start();
  48. cmdCommands.WaitForExit();
  49.  
  50.  
  51.  
  52. File.Delete(filename + ".mkv");
  53. File.Delete(filename + ".opus");
  54. }
  55. }
  56. catch (Exception e)
  57. {
  58. MessageBox.Show(e.Message);
  59.  
  60. }
  61. }
  62. StopEncoding.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new System.Action(() => { StopEncoding.IsEnabled = false; Encode.IsEnabled = true; }));
  63. }
  64.  
  65. private void PipeWrite(IAsyncResult ar)
  66. {
  67. int read = cmdCommands.StandardOutput.BaseStream.EndRead(ar);
  68. if (read != 0)
  69. {
  70. QU.Add((byte[])ReadBuffer.Clone());
  71. cmdCommands.StandardOutput.BaseStream.BeginRead(ReadBuffer, 0, ReadBuffer.Length, PipeWrite, null);
  72. cmdCommands.StandardOutput.BaseStream.Flush();
  73. }
  74. else
  75. {
  76. ReadBuffer = new byte[0];
  77. QU.Add(ReadBuffer);
  78. cmdCommands.StandardOutput.BaseStream.Close();
  79. }
  80. }
  81.  
  82. private void OpusEncode(string filename,AutoResetEvent OpusCheck)
  83. {
  84. OpusEncoder.StartInfo.UseShellExecute = false;
  85. OpusEncoder.StartInfo.RedirectStandardInput = true;
  86. OpusEncoder.StartInfo.FileName = SC.GetOpusEncPath();
  87. OpusEncoder.StartInfo.Arguments = string.Format("{0} - "{1}"", SC.GetOpusSettings(true), filename + ".opus");
  88. OpusEncoder.Start();
  89. byte[] temp;
  90. while (QU.TryTake(out temp, Timeout.Infinite))
  91. {
  92. if (temp.Length == 0)
  93. break;
  94. OpusEncoder.StandardInput.BaseStream.Write(temp, 0, temp.Length);
  95.  
  96. }
  97. OpusEncoder.StandardInput.Close();
  98. OpusEncoder.WaitForExit();
  99. OpusCheck.Set();
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement