How to genarate a .gif from video with penFrameworks and OpenCV?

Hi,

I’m trying to create an app with openframeworks, which has a live camera, and when it detects motion starts to record the video for 3 seconds and creates a.gif.

Does anybody know how to to this?

The part of motion detection is done with OpenCV.

Thanks!!

I did something similar a couple times. But I stored the raw pixels from an FBO into a vector of ofPixels. Then I pass it to a function which saves them all as images to a temp location, sends it to FFMPEG to process into a video then removes the temp files and gives you a video out of it. I believe FFMPEG can also handle gif’s.

There is also this library.

Hi,
I highly recommend to use an ofxVideoRecorder addon which is based on ffmpeg. After that you can use the same ffmpeg to convert a movie to gif file. Ffmpeg is a command line tool. This is a very simple command:

ffmpeg -i small.mp4 small.gif

Here you can find some more options.

On OF you can do it like that:

stringstream convertCmd;
convertCmd << ffmpegLocation << " -i " << movieFileName.mp4 << gifFileName.gif
system(convertCmd.str().c_str());
1 Like

ThanksSebastian!This is what i’m trying, but when i build the project with visual studio 2015 and run it, it’s says that #include <unistd.h> #include <fcntl.h> are missed, and these are used at ofxVideoRecorder…

Finally I get to use ofxVideoRecorder! Many thanks! Next step is to convert the mp4 to gif!! Let’s do it!

Happy to hear that. It should be a piece of cake ;D

1 Like

Hey ryanww, I tried to use it, but it says that i have a missed file… the file it’s ofxGifFrame …