FFMpegCore icon indicating copy to clipboard operation
FFMpegCore copied to clipboard

How to skip saving image to file after conversion

Open MrDj200 opened this issue 3 years ago • 2 comments

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?

MrDj200 avatar May 06 '22 07:05 MrDj200

I have the same problem.

sametunay avatar May 09 '22 19:05 sametunay

Did you seek the memorystream to position 0 after the conversion, before reading from it?

rosenbjerg avatar Feb 04 '23 21:02 rosenbjerg