首先 - 我的英语不是很好,对不起。
我使用c#中的ffmpeg将图像转换为视频。要与ffmpeg交互,我使用管道。
router.get('/', checkAuthentication, function(req, res){
res.render('index');
});
动作“sendDataUsingPipe”看起来像
public async Task<byte[]> ExecuteCommand(
string arguments,
Action<NamedPipeServerStream> sendDataUsingPipe)
{
var inStream = new NamedPipeServerStream(
"from_ffmpeg",
PipeDirection.In,
1,
PipeTransmissionMode.Byte,
PipeOptions.Asynchronous,
PipeBufferSize,
PipeBufferSize);
var outStream = new NamedPipeServerStream(
"to_ffmpeg",
PipeDirection.Out,
1,
PipeTransmissionMode.Byte,
PipeOptions.Asynchronous,
PipeBufferSize,
PipeBufferSize);
var waitInConnectionTask = inStream.WaitForConnectionAsync();
var waitOutConnectionTask = outStream.WaitForConnectionAsync();
byte[] byteData;
using (inStream)
using (outStream)
using (var inStreamReader = new StreamReader(inStream))
using (var process = new Process())
{
process.StartInfo = new ProcessStartInfo
{
RedirectStandardOutput = true,
RedirectStandardError = true,
RedirectStandardInput = true,
FileName = PathToFfmpeg,
Arguments = arguments,
UseShellExecute = false,
CreateNoWindow = true
};
process.Start();
await waitOutConnectionTask;
sendDataUsingPipe.Invoke(outStream);
outStream.Disconnect();
outStream.Close();
await waitInConnectionTask;
var logTask = Task.Run(() => process.StandardError.ReadToEnd());
var dataBuf = ReadAll(inStream);
var shouldBeEmpty = inStreamReader.ReadToEnd();
if (!string.IsNullOrEmpty(shouldBeEmpty))
throw new Exception();
var processExitTask = Task.Run(() => process.WaitForExit());
await Task.WhenAny(logTask, processExitTask);
var log = logTask.Result;
byteData = dataBuf;
process.Close();
inStream.Disconnect();
inStream.Close();
}
return byteData;
}
当我发送10/20/30图像(无论大小)时,ffmpeg会处理所有内容。 当我需要传输600/700 / ..图像时,然后在ffmpeg日志中我看到它只收到189-192,而在视频中也只有189-192个图像。 代码中的日志或异常没有错误。
这种行为可能是什么原因?