Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

c# - ffmpeg output pipeing to named windows pipe

This question is related to my previous question: Converting raw frames into webm live stream

I want to pipe a video to ffmpeg and read it back through another pipe, but I cannot pipe the output of ffmpeg.exe to a named pipe on windows.

My definition of the pipes in C#:

NamedPipeServerStream p_to_ffmpeg;
NamedPipeServerStream p_from_ffmpeg;
p_to_ffmpeg = new NamedPipeServerStream("to_ffmpeg", PipeDirection.Out, 1, PipeTransmissionMode.Byte);
p_from_ffmpeg = new NamedPipeServerStream("from_ffmpeg", PipeDirection.In, 1, PipeTransmissionMode.Byte);

And then I start ffmpeg.exe in a separate process with the following options: -f rawvideo -vcodec rawvideo -video_size 656x492 -r 10 -pix_fmt rgb24 -i \.pipeo_ffmpeg -c:v libvpx -pass 1 -f webm \.pipefrom_ffmpeg

ffmpeg.exe refuses to write to the pipe with the following error : File '\.pipefrom_ffmpeg' already exists. Overwrite ? [y/N]

When I replace the "output pipe" with a file name, it works like charm: -f rawvideo -vcodec rawvideo -video_size 656x492 -r 10 -pix_fmt rgb24 -i \.pipeo_ffmpeg -c:v libvpx -pass 1 -f webm output.webm

How do I get ffmpeg to write to a named pipe in windows?

Edit: When I force to write to the pipe with ffmpeg's -y option, I get the following error: Could not write header for output file #0 (incorrect codec parameters ?): Error number -32 occurred

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It seems like the problem can be solved by adding the -y option to the ffmpeg command and specifying a buffer size for the pipe.

My ffmpeg command (see aergistal's comment why I also removed the -pass 1 flag): -y -f rawvideo -vcodec rawvideo -video_size 656x492 -r 10 -pix_fmt rgb24 -i \.pipeo_ffmpeg -c:v libvpx -f webm \.pipefrom_ffmpeg

And defining the named pipe as follows:

p_from_ffmpeg = new NamedPipeServerStream(pipename_from, 
    PipeDirection.In, 
    1, 
    PipeTransmissionMode.Byte, 
    System.IO.Pipes.PipeOptions.WriteThrough, 
    10000, 10000);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...