首页 > 解决方案 > 有没有办法使用 .NET 从 Matlab 中的标准输入读取 FFPLAY?

问题描述

我正在尝试从 FFMPEG 输出中读取原始 h.264 流,在 Matlab 中对其进行处理,将其发送到 FFPLAY 并从那里显示。我在 Matlab 中使用 .NET 库,并且能够将流从 FFMPEG 标准输出读取到 Matlab 中。但是,我无法将处理后的数据发送到 FFPLAY 的标准输入。我究竟做错了什么?

我在 Matlab 中使用 System.Diagnostics of .NET 设置了一个 ffmpeg 进程来读取其输出。同样,我为ffplay设置了另一个进程。我重定向了ffmpeg的标准输出和ffplay的标准输入。然后,我从 ffmpeg 中读取行并将其写入 ffplay。但是,ffplay 没有显示任何内容。

此外,当我尝试从 ffmpeg stdout 写入文件并发送 ffplay 该文件时,它也不起作用。这让我怀疑数据从 ffmpeg 标准输出中丢失,但不知道如何验证这一点。

pFFMPEG = System.Diagnostics.Process();
pFFMPEG.StartInfo = System.Diagnostics.ProcessStartInfo;
pFFMPEG.StartInfo.FileName = 'ffmpeg.exe';
pFFMPEG.StartInfo.Arguments = '-y -nostdin -f dshow -framerate 5 -i video="Logitech Webcam C925e" -vf scale=160:120 -vcodec h264 -an -map 0:v -f nut -';
pFFMPEG.StartInfo.UseShellExecute = false;
pFFMPEG.StartInfo.RedirectStandardOutput = true;
pFFMPEG.StartInfo.RedirectStandardInput = false;
pFFMPEG.StartInfo.RedirectStandardError = false;
pFFMPEG.StartInfo.CreateNoWindow = true;

pFFPLAY = System.Diagnostics.Process();
pFFPLAY.StartInfo = System.Diagnostics.ProcessStartInfo;
pFFPLAY.StartInfo.FileName = 'ffplay.exe';
pFFPLAY.StartInfo.Arguments = '-i - -autoexit';
pFFPLAY.StartInfo.UseShellExecute = false;
pFFPLAY.StartInfo.RedirectStandardInput = true;
pFFPLAY.StartInfo.RedirectStandardOutput = false;
pFFPLAY.StartInfo.RedirectStandardError = false;
pFFPLAY.StartInfo.CreateNoWindow = false;

t = zeros(150,1);
ctr = 0;
L = 0;
arr = zeros(10000, 1);

pFFMPEG.Start();
ffmpegOut = pFFMPEG.StandardOutput;

temp = ffmpegOut.ReadLine();
temp_arr = uint8(char(temp));
%here, process temp_arr and convert back to char arr temp%
pFFPLAY.Start();
ffplayIn = pFFPLAY.StandardInput;
ffplayIn.WriteLine(temp);

while ~(isempty(temp)) && ctr < 150 && L < length(arr)
    L_end = L+temp.Length;
    arr(L+1:L_end) = temp_arr;
    temp = ffmpegOut.ReadLine();
    L = L_end;
    temp_arr = uint8(char(temp));
    %here, process temp_arr and convert back to char arr temp %
    ffplayIn.WriteLine(temp);
    ctr = ctr + 1;
end    

当我查看 Matlab 工作区时,我似乎将 ffmpeg 的输出输入到 arr 中的 Matlab 中,尽管我不确定是否有任何下降。当我尝试将数据发送到 ffplay 时,没有任何反应。我可以看到 ffplay 进程正在运行,但没有显示视频窗口。

任何帮助深表感谢。

标签: .netmatlabffmpeg

解决方案


推荐阅读