Redirecting stdin and stdout where stdin closes first

后端 未结 2 1444
南方客
南方客 2021-01-19 19:01

This is actually related to another question I had that was already answered. That question is here: Redirecting stdout of one process object to stdin of another

My

相关标签:
2条回答
  • 2021-01-19 19:24

    For anyone who wants to do something similar, here is the new version with KeeperOfTheSoul's advice applied:

            Process tccatProcess = new Process();           
            tccatProcess.StartInfo.FileName = "tccat";
            tccatProcess.StartInfo.Arguments = String.Format("-i {0} -T {1}", devNode, title);
            tccatProcess.StartInfo.UseShellExecute = false;
            tccatProcess.StartInfo.RedirectStandardOutput = true;
    
            Process ffmpegProcess = new Process();
            string bashSafePreviewTemplate = slasher.bashSlash(previewTempDir + "/test%03d.jpg");
            ffmpegProcess.StartInfo.FileName = "ffmpeg";
            ffmpegProcess.StartInfo.Arguments = String.Format("-i - -r 1 -t 1 -s {1}x{2} -ss {3} {0}", 
                bashSafePreviewTemplate, width, height, timePosition);
            ffmpegProcess.StartInfo.UseShellExecute = false;
            ffmpegProcess.StartInfo.RedirectStandardInput = true;
    
            Console.WriteLine("tccat command: {0} {1}", tccatProcess.StartInfo.FileName, tccatProcess.StartInfo.Arguments);
            Console.WriteLine("ffmpeg command: {0} {1}", ffmpegProcess.StartInfo.FileName, ffmpegProcess.StartInfo.Arguments);
    
            //return true;
    
            try{
                tccatProcess.Start();
                ffmpegProcess.Start();
    
                BinaryReader tccatOutput = new BinaryReader(tccatProcess.StandardOutput.BaseStream);
                BinaryWriter ffmpegInput = new BinaryWriter(ffmpegProcess.StandardInput.BaseStream);
                int buffSize = 4096;
                byte[] buff = new byte[buffSize];
    
    
                while(!ffmpegProcess.HasExited)
                {
                    ffmpegProcess.Refresh();
                    buff = tccatOutput.ReadBytes(buffSize);
                    ffmpegInput.Write(buff);
                    ffmpegInput.Flush();
                }
    
    
                tccatProcess.Kill();
                tccatProcess.Close();
                ffmpegProcess.Close();
    
    
            }catch(Exception e){
                        //uninteresting log code
                        return false;
    
            }
    
    0 讨论(0)
  • 2021-01-19 19:42

    Doesn't tccat output binary data since you're working with video and images? If so shouldn't you be reading/writing to the input/output streams directly rather than wrapping them in a text reader?

    If so you want to be using Can i put binary in stdin? C#

    0 讨论(0)
提交回复
热议问题