FFMpegCore
FFMpegCore copied to clipboard
How to skip saving image to file after conversion
How would i skip saving a converted image to disk?
I tried to out OutputToPipe, but the MemoryStream I put into the StreamPipeSink is either empty, or contains errors.
I'm specifically doing a png to webp conversion.
I tried:
public static async Task<byte[]> ConvertInMemory(Stream inputStream, bool lossless = true)
{
MemoryStream outputStream = new MemoryStream();
await FFMpegArguments
.FromPipeInput(new StreamPipeSource(inputStream))
.OutputToPipe(new StreamPipeSink(outputStream), options => options
.ForceFormat("webp")
.WithCustomArgument($"-lossless {(lossless ? 1 : 0)}")
.WithFastStart()
).ProcessAsynchronously();
return outputStream.ToArray();
}
however, when writing this byte array to a file (for testing), it saves it as either a broken or empty .webp file.
Am I missing something, or is this just not possible?
I have the same problem.
Did you seek the memorystream to position 0 after the conversion, before reading from it?