ffmpeg 输出管道到命名的 Windows 管道 [英] ffmpeg output pipeing to named windows pipe
问题描述
这个问题与我之前的问题有关:将原始帧转换为 webm 直播
我想将视频传输到 ffmpeg 并通过另一个管道读回,但我无法将 ffmpeg.exe
的输出通过管道传输到 Windows 上的命名管道.
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.
我在 C# 中对管道的定义:
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);
然后我在一个单独的进程中使用以下选项启动 ffmpeg.exe
:-f rawvideo -vcodec rawvideo -video_size 656x492 -r 10 -pix_fmt rgb24 -i \.pipe o_ffmpeg -c:v libvpx -pass 1 -f webm \.pipefrom_ffmpeg
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 \.pipe o_ffmpeg -c:v libvpx -pass 1 -f webm \.pipefrom_ffmpeg
ffmpeg.exe 拒绝写入管道并出现以下错误:File '\.pipefrom_ffmpeg' already exists.覆盖?[是/否]
ffmpeg.exe refuses to write to the pipe with the following error : File '\.pipefrom_ffmpeg' already exists. Overwrite ? [y/N]
当我用文件名替换输出管道"时,它的作用就像魅力一样:-f rawvideo -vcodec rawvideo -video_size 656x492 -r 10 -pix_fmt rgb24 -i \.pipe o_ffmpeg -c:v libvpx -pass 1 -f webm output.webm
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 \.pipe o_ffmpeg -c:v libvpx -pass 1 -f webm output.webm
如何让 ffmpeg 写入 Windows 中的命名管道?
当我使用 ffmpeg 的 -y
选项强制写入管道时,出现以下错误:无法为输出文件 #0 写入标头(编解码器参数不正确?): 发生错误号 -32
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
推荐答案
看起来这个问题可以通过在 ffmpeg 命令中添加 -y
选项并指定管道的缓冲区大小来解决.
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.
我的 ffmpeg 命令(请参阅 aergistal 的评论为什么我还删除了 -pass 1
标志):-y -f rawvideo -vcodec rawvideo -video_size 656x492 -r 10 -pix_fmt rgb24 -i\.pipe o_ffmpeg -c:v libvpx -f webm \.pipefrom_ffmpeg
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 \.pipe o_ffmpeg -c:v libvpx -f webm \.pipefrom_ffmpeg
并定义命名管道如下:
p_from_ffmpeg = new NamedPipeServerStream(pipename_from,
PipeDirection.In,
1,
PipeTransmissionMode.Byte,
System.IO.Pipes.PipeOptions.WriteThrough,
10000, 10000);
这篇关于ffmpeg 输出管道到命名的 Windows 管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!