Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Converting GIF buffer to MP4 buffer without writing to file first #567
I am trying to convert animated GIF's to MP4 videos, on the fly, as the user requests them, after resizing/processing the GIF's first as requested.
After all processing on the GIF is complete I have its contents stored in a
Currently, I have to write the
This is terribly inefficient and I would like to avoid writing to disk. How can I simply convert the
I tried using streamifier and passing in the GIF
Here is a stripped down version of the current method I am using which involves writing the files to disk before processing:
Any help would be greatly appreciated.
Unfortunately there aren't many options here. Remember fluent-ffmpeg is just a wrapper library for the ffmpeg executable, so we have to work with what we have. Plus there is no reliable way of connecting both to stdin and stdout without risking deadlocks. So in the end you'll have to write either the input or the output to disk. This may be mitigated by writing to something that's likely to be a ramdisk (eg. /tmp).
If you really want performance, what you need is libav* bindings. I don't think those exist in nodejs.
Can you show your code, as well as the full ffmpeg output (as returned in the 'error' handler 2nd and 3rd args) ?
Thanks for the response njoyard. As requested here is the full console output:
And here is the example code I am using to test this. For now I have not hooked up the output stream to create a new Buffer, but my understanding is that this should still work.
Have you tried commenting out the event:
I use fluent-ffmpeg to do similar: Chrome with WebRTC (webM/opus codec) -> Express (string base64) -> stream -> fluent-ffmpeg WebM to OGG -> stream -> IBM Watson speech to text -> res.send()
If you receive the gif file through a request in base64, I would also try to replace usage of streamifier:
@GordoRank You can avoid writing the GIF to disk by inputting it as a readable stream, but you will have to write the MP4 to disk. The reason is that the MP4 muxer requires a seekable output, as it jumps around while writing the output, as opposed to only appending it. That means
As hinted at by @njoyard, a direct node-libav binding would work because a Buffer would be a seekable output, but there's no way to accomplish that with a library that wraps the ffmpeg program.