I'm trying to read use the pipe feature of ffmpeg to not have to write files in the disk.
my inputs implementations are:
public FFMPEG input(string path)
{
parameters.Add($"-i {path}");
return this;
}
public FFMPEG input(byte[] file)
{
parameters.Add("-i pipe:.mp4");
files.Add(file);
return this;
}
my output implementation is:
public FFMPEG output(string format)
{
_output = $"-f {format} -";
return this;
}
my run implementation is:
public byte[] run()
{
if (_output == "")
{
throw new Exception("missing output format");
}
var process = new Process()
{
StartInfo =
{
FileName = @"ffmpeg.exe",
Arguments = String.Join(" ", parameters) + " " + _output,
RedirectStandardOutput = true,
RedirectStandardInput = true,
UseShellExecute = false,
}
};
process.Start();
foreach (var item in files)
{
process.StandardInput.BaseStream.Write(item);
}
byte[] result;
using(var memstream = new MemoryStream())
{
process.StandardOutput.BaseStream.CopyTo(memstream);
result = memstream.ToArray();
}
process.WaitForExit();
return result;
}
which works perfectly if I use a file as input:
var result = new FFMPEG()
.input("./assets/video.mp4")
.output("avi")
.run();
but when I try to use bytes input:
var result = new FFMPEG()
.input(File.ReadAllBytes("./assets/video.mp4"))
.output("avi")
.run();
I get the following error:
[mov,mp4,m4a,3gp,3g2,mj2 @ 00000137385a10c0] stream 1, offset 0x30: partial file
Error demuxing input file 0: Invalid data found when processing input
pipe:.mp4: Invalid data found when processing input
Cannot determine format of input stream 0:0 after EOF
Error marking filters as finished