有没有办法使用.NET从Matlab的stdin中读取FFPLAY?

时间:2019-02-04 18:47:35

标签: .net matlab ffmpeg

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

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

此外,当我尝试从ffmpeg stdout写入文件并发送ffplay该文件时,它也不起作用。这使我怀疑从ffmpeg stdout删除了数据,但不知道如何验证。

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进程正在运行,但是没有显示视频窗口。

非常感谢您的帮助。

0 个答案:

没有答案