2009-04-16 5 views
1

Process 클래스를 사용하여 openRTSP를 실행할 작은 GUI 래퍼를 작성했습니다. 내가 겪고있는 문제는 출력을 mpeg4 비디오 파일로 리디렉션하는 것입니다. 명령 행에서 openRTSP를 실행하여 전달하는 매개 변수가 올바른지 확인했습니다.C# 프로세스 클래스가 비디오 파일로 출력을 리디렉션합니다.

openRTSP.exe - 일부 -parameters -for - 비디오 -4 RTSP : //video.from.server video.mp4

은 "> video.mp4"나는 문제가 재현를 데 것입니다>.

Process 클래스를 사용하는 다른 예제를 살펴 보았지만 ASCII 텍스트로만 작동하는 것처럼 보입니다.

편집 --- 여기에 좀 더 세부입니다

this.outputStream = new StreamWriter(fileNameToUse, false, Encoding.Default); 

try 
{ 
    byte[] buffer; 

    // Start the process with the info we specified. 
    // Call WaitForExit and then the using statement will close. 
    using (Process exeProcess = new Process()) 
    { 
     // Assign start info to the process 
     exeProcess.StartInfo = startInfo; 

     // Set up the event handler to call back with each line of output 
     exeProcess.OutputDataReceived += new DataReceivedEventHandler(OnDataReceived); 

     // Start the Process 
     exeProcess.Start(); 

     exeProcess.BeginOutputReadLine(); 
     exeProcess.WaitForExit(); 
    } 
} 
catch (Exception ex) { PrintException(ex); } 
finally 
{ 
    this.outputStream.Flush(); 
    this.outputStream.Close(); 
} 

// Called asynchronously with a line of data 
private void OnDataReceived(object Sender, DataReceivedEventArgs e) 
{ 
    lock (this) 
    { 
     if (!string.IsNullOrEmpty(e.Data) && (this.outputStream != null)) 
      this.outputStream.WriteLine(e.Data); 
    } 
} 

데이터를 쓰기를 WriteLine을 이용하여 수신, 내 응용 프로그램은 파일 크기가 내가 명령 줄에서 openRTSP을 실행할 때와 동일한 종료 할 때 어떤 "올바른"출력, 즉 재생할 수있는 mpeg4 비디오를 생성합니다. 명령 줄에서 실행하면 openRTSP에서 mpeg4 파일을 출력하고 있는데 mpeg4 파일로 리디렉션하고 있습니다.

startInfo.Arguments에 할당 된 문자열의 끝에 "> fileNameToUse"를 추가했지만 openRTSP가 즉시 실패했습니다.

감사합니다, 매트

+0

재미있는 [MedallionShell] (https://github.com/madelson/MedallionShell) 라이브러리가 있습니다. 프로세스 스트림의 리다이렉션은 작업하기 매우 간단합니다. – ChaseMedallion

답변

0

대신 명령 줄에서> paramater를 전달하는, 표준 출력을 캡처 파일에 기록 할 수 있습니다.

프로세스 클래스에는 액세스 할 수있는 StandardOutput 스트림이 있으며이를 파일에 덤프 할 수 있어야합니다.

임시 배치 파일을 작성하고 대신 Process.Start()를 사용하여 시작할 수도 있습니다. 분명히

public void Example() { 
     //Prepare the Process 
     ProcessStartInfo start = new ProcessStartInfo(); 
     if (!_graphvizdir.Equals(String.Empty)) { 
      start.FileName = this._graphvizdir + "dot.exe"; 
     } else { 
      start.FileName = "dot.exe"; 
     } 
     start.Arguments = "-T" + this._format; 
     start.UseShellExecute = false; 
     start.RedirectStandardInput = true; 
     start.RedirectStandardOutput = true; 

     //Prepare the GraphVizWriter and Streams 
     GraphVizWriter gvzwriter = new GraphVizWriter(); 
     BinaryWriter output = new BinaryWriter(new FileStream(filename, FileMode.Create)); 

     //Start the Process 
     Process gvz = new Process(); 
     gvz.StartInfo = start; 
     gvz.Start(); 

     //Write to the Standard Input 
     gvzwriter.Save(g, gvz.StandardInput); 

     //Read the Standard Output 
     StreamCopy(gvz.StandardOutput.BaseStream, output.BaseStream); 
     output.Close(); 

     gvz.Close(); 
    } 

    public void StreamCopy(Stream input, Stream output) { 
     int i; 
     byte b; 

     i = input.ReadByte(); 

     while (i != -1) 
     { 
      b = (byte)i; 
      output.WriteByte(b); 

      i = input.ReadByte(); 
     } 
    } 

당신의 쓰기를 남길 수 있습니다 : 다음

2

내 자신의 코드에서 비슷한 일을 내 예, 그것은 올바른 출력을 얻을하기 위해 바이트로 스트림을 복사하는 것이 필요 표준 입력 비트는 필요하지 않으므로 가장 중요한 것은 RedirectStandardOutput을 설정 한 다음 출력을 원하는 출력 파일의 FileStream에 쓰는 BinaryWriter에 복사하는 것입니다.

0

나는 같은 질문을하고 (매뉴얼에있는) 대답을 발견했다. 그래서 나는 내가 나눌 것이라고 생각했다.

인수에 -v를 추가하면 데이터를 표준 출력으로 출력하므로 프로그램에서 읽을 수 있습니다.

세션에서만 오디오 스트림을 기록하는 단일 스트림을 추출은 "-a" 명령 줄 옵션을 사용합니다. (마찬가지로 비디오 스트림 만 기록하려면 "-v"옵션을 사용하십시오.)이 경우 출력 오디오 (또는 비디오) 스트림 은 파일이 아닌 'stdout'에 기록됩니다 (" -P "옵션이 제공됩니다 (아래 참조).

또한 이진 데이터이므로 Process.OutputStream의 BaseStream을 가져 와서 작업하십시오.

관련 문제