Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void Encoding(string[] GetFile)
- {
- using(AutoResetEvent OpusCheck = new AutoResetEvent(false))
- using (QU = new BlockingCollection<byte[]>())
- using (OpusEncoder = new Process())
- for (int i = 0; i < GetFile.Length; i++)
- {
- try
- {
- ReadBuffer = new byte[4096];
- string filename = Path.GetDirectoryName(GetFile[i]) + "\" + Path.GetFileNameWithoutExtension(GetFile[i]);
- using (cmdCommands = new Process())
- {
- cmdCommands.StartInfo.UseShellExecute = false;
- cmdCommands.StartInfo.CreateNoWindow = false;
- cmdCommands.StartInfo.FileName = SC.GetAVS4x264Path();
- cmdCommands.StartInfo.Arguments = string.Format(""{0}" --x264-binary "{1}" --colormatrix=bt709 {2} --output="{3}" -", filename + ".avs", SC.Getx264Path(), SC.Getx264Settings(true), filename + ".mkv");
- cmdCommands.Start();
- cmdCommands.WaitForExit();
- if (EncodingStopped)
- break;
- cmdCommands.StartInfo.UseShellExecute = false;
- cmdCommands.StartInfo.CreateNoWindow = true;
- cmdCommands.StartInfo.RedirectStandardOutput = true;
- cmdCommands.StartInfo.FileName = SC.GetAVS2PipeModPath();
- cmdCommands.StartInfo.Arguments = string.Format("{0} "{1}" -wav", SC.GetAVS2PipeModPath(), filename + ".avs");
- cmdCommands.Start();
- Thread OpusThread = new Thread(() => OpusEncode(filename, OpusCheck));
- OpusThread.Start();
- cmdCommands.StandardOutput.BaseStream.BeginRead(ReadBuffer, 0, ReadBuffer.Length, PipeWrite, null);
- cmdCommands.WaitForExit();
- OpusCheck.WaitOne();
- if (EncodingStopped)
- break;
- cmdCommands = new Process();
- cmdCommands.StartInfo.UseShellExecute = false;
- cmdCommands.StartInfo.RedirectStandardError = true;
- cmdCommands.StartInfo.FileName = SC.GetMKVMergePath();
- cmdCommands.StartInfo.Arguments = (" -o "" + filename + "-muxed.mkv" "" + filename + ".mkv" " + """ + filename + ".opus"");
- cmdCommands.Start();
- cmdCommands.WaitForExit();
- File.Delete(filename + ".mkv");
- File.Delete(filename + ".opus");
- }
- }
- catch (Exception e)
- {
- MessageBox.Show(e.Message);
- }
- }
- StopEncoding.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new System.Action(() => { StopEncoding.IsEnabled = false; Encode.IsEnabled = true; }));
- }
- private void PipeWrite(IAsyncResult ar)
- {
- int read = cmdCommands.StandardOutput.BaseStream.EndRead(ar);
- if (read != 0)
- {
- QU.Add((byte[])ReadBuffer.Clone());
- cmdCommands.StandardOutput.BaseStream.BeginRead(ReadBuffer, 0, ReadBuffer.Length, PipeWrite, null);
- cmdCommands.StandardOutput.BaseStream.Flush();
- }
- else
- {
- ReadBuffer = new byte[0];
- QU.Add(ReadBuffer);
- cmdCommands.StandardOutput.BaseStream.Close();
- }
- }
- private void OpusEncode(string filename,AutoResetEvent OpusCheck)
- {
- OpusEncoder.StartInfo.UseShellExecute = false;
- OpusEncoder.StartInfo.RedirectStandardInput = true;
- OpusEncoder.StartInfo.FileName = SC.GetOpusEncPath();
- OpusEncoder.StartInfo.Arguments = string.Format("{0} - "{1}"", SC.GetOpusSettings(true), filename + ".opus");
- OpusEncoder.Start();
- byte[] temp;
- while (QU.TryTake(out temp, Timeout.Infinite))
- {
- if (temp.Length == 0)
- break;
- OpusEncoder.StandardInput.BaseStream.Write(temp, 0, temp.Length);
- }
- OpusEncoder.StandardInput.Close();
- OpusEncoder.WaitForExit();
- OpusCheck.Set();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement