ffmpeg: "Input/output error" Read gif from named pipe?

523 Views Asked by At

I've been trying to debug this for hours now, and cannot seem to understand why it doesn't work.

I want to overlay a png onto all frames of a gif, and since writing all the files to disk is slow, i wanted to use pipes.

I created a named pipe using mkfifo imgstream1 and then launch ffmpeg:

ffmpeg -report -hide_banner -v 9 -loglevel 99 -y -f gif -i imgstream1 out1.gif

(This isn't actually useful as it just spits out the same gif again but it's simpler for debugging)

After ffmpeg launches it waits for data from the pipe, so i write an actual gif file to the pipe using this kotlin code

val backgroundFifo = File("imgstream1")
val inputOne = File("background.gif").readBytes()
println("background.gif -> ${inputOne.size} bytes")
val output = backgroundFifo.outputStream()
output.write(inputOne)
output.flush()
output.close()

It prints: background.gif -> 7233247 bytes

Now ffmpeg should read the bytes and spit out a gif, but it always seems to fail doing so.

Opening an input file: imgstream1.
[gif @ 0x7714180] Opening 'imgstream1' for reading
[file @ 0x7714980] Setting default whitelist 'file,crypto,data'
[AVIOContext @ 0x7724dc0] Statistics: 7233247 bytes read, 0 seeks
imgstream1: Input/output error

Sadly this does not give any further information, i'm already on the highest log level...

I've tried multiple things:

  • -f image2pipe -> Works, but only loads the first 2 frames of the gif
  • Renaming the pipe to imgstream1.gif so ffmpeg thinks it's a gif file, no change.
  • Different ffmpeg versions
  • Using the actual gif as an ffmpeg input works

At this point i have no idea what the problem might be, as ffmpeg seems to load all bytes. It's worth noting that doing cat imgstream1 > file.gif produces the desired gif.

Any help would be appreciated!

0

There are 0 best solutions below