Unityで名前付きパイプを使用して、プロセス間通信を行いたいのですがうまくいきません。
Piping to ffmpeg.exe with C#の記事の「Piping multiple streams」を参考に、
@keijiroさんが作成されたFFmpegOut(Unityの録画)にオーディオも録音できるようにしようと思っております。
一応、VideoとAudioそれぞれにFFmpegのプロセスを立ち上げて、別々にエンコードしmp4及びmp3の出力を行うことができました。
これを、一つのmp4ファイルで出力できるようにしたいと思っております。
名前付きパイプを扱うのはこれが初めてなので、私の理解が間違っている可能性もありますので、確認のため要点となるコードと合わせて書いたコードの概要を説明すると
###まずNamedPipeServerStreamを先に作成し、待機させておく。
C#
1videoPipe = new NamedPipeServerStream(videoPipeName, PipeDirection.Out, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous, 10000, 10000); 2videoPipe.BeginWaitForConnection(ar => 3 { 4 using (var conn = (NamedPipeServerStream)ar.AsyncState) 5 { 6 try 7 { 8 conn.EndWaitForConnection(ar); 9 videoPipeConnecting = true; 10 } 11 catch (Exception e) 12 { 13 UnityEngine.Debug.Log(e.Message); 14 } 15 16 // do business with the client 17 conn.WaitForPipeDrain(); 18 } 19 }, videoPipe);
その後FFmpegのiオプションにパイプ名を設定してプロセスを起動する
C#
1const string pipePrefix = @"\.\pipe\"; 2const string videoPipeName = "univpipe"; 3 4var opt = $"-f rawvideo -r 30 -pix_fmt rgba -s 1280x720 -i {pipePrefix}{videoPipeName} -f s16le -ac 2 -ar 48000 -i {pipePrefix}{audioPipeName} unirec__.mp4"; 5var info = new ProcessStartInfo((string)binPath, opt); 6info.UseShellExecute = true; 7info.CreateNoWindow = false; 8info.RedirectStandardInput = true; 9info.RedirectStandardError = true; 10 11_namedPipeFFmpegProcess = Process.Start(info); 12_namedPipeFFmpegProcess.ErrorDataReceived += (s, e) => UnityEngine.Debug.Log(e.Data); 13_namedPipeFFmpegProcess.BeginErrorReadLine(); 14UnityEngine.Debug.Log("NamedPipe FFmpeg process start");
FFmpegの起動により、名前付きパイプのクライアント側が起動し接続されると思っているのですが、FFmpegのプロセスを起動してもそもそも
\.\pipe\univpipe: No such file or directory
と、名前付きパイプが見つからないというメッセージが表示されてしまいます。
Windows Sysinternalsにあるpiplistツール(pipelist64.exe)で確認しても"univpipe"が見当たりません。
pipelistツールで"unipipe"が作成されいるのを確認できました。
書いたコードのプロジェクトです。
googleドライブ
Unityだと名前付きパイプは使えないのでしょうか?
以上、よろしくお願いします。
あなたの回答
tips
プレビュー