# Outputting video/gif

**URL:** <https://discourse.processing.org/t/outputting-video-gif/11301>\
**Category:** Processing.py\
**Created:** [May 16, 2019, 10:28am UTC](https://discourse.processing.org/t/outputting-video-gif/11301 "2019-05-16T10:28:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Avatrin](https://avatars.discourse-cdn.com/v4/letter/a/97f17d/32.png) [@Avatrin](https://discourse.processing.org/u/Avatrin)\
**Post date:** [May 16, 2019, 10:28am UTC](https://discourse.processing.org/t/outputting-video-gif/11301/1 "2019-05-16T10:28:24Z")

</div>

Hi

I have an animation which run in Processing.py. How can I output a video of the, lets say, first n seconds of that animation? I would prefer a gif, but any format would do.

---

<div class="post-metadata">

**Author:** ![humayung](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/humayung/32/6089_2.png) [@humayung](https://discourse.processing.org/u/humayung)\
**Post date:** [May 16, 2019, 11:04am UTC](https://discourse.processing.org/t/outputting-video-gif/11301/2 "2019-05-16T11:04:26Z")

</div>

Hi avatrin!

well, i’m not very sure you can output video format of animation in processing, but you can save every frame you get and combine it into video or gif.  
see: [https://processing.org/reference/saveFrame\_.html](https://processing.org/reference/saveFrame_.html)

for combining, i’m usually using ffmpeg  
see: [https://stackoverflow.com/questions/24961127/how-to-create-a-video-from-images-with-ffmpeg](https://stackoverflow.com/questions/24961127/how-to-create-a-video-from-images-with-ffmpeg)

probably you will need frameCount to limit frames elapsed of the animation  
[https://processing.org/reference/frameCount.html](https://processing.org/reference/frameCount.html)

---

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [May 16, 2019, 11:29am UTC](https://discourse.processing.org/t/outputting-video-gif/11301/3 "2019-05-16T11:29:30Z")

</div>

The _Video Export_ library essentially automates the steps @humayung has described.

You can install it via the library menu ( **Sketch \> Import Library \> Add Library** ). Then, you’ll need to download FFmpeg:  
[https://ffmpeg.org/download.html](https://ffmpeg.org/download.html)

Here’s some code to try out. When it runs, Processing will prompt you to locate/browse-to your ffmpeg executable:

```auto
add_library('VideoExport')

def setup():
    size(600, 600)
    global videoExport
    videoExport = VideoExport(this)
    videoExport.startMovie()

x = 0

def draw():
    global x
    background(0)
    rect(x, 10, 50, 50)
    videoExport.saveFrame()
    x += 1

def keyPressed():
  if (key == 'q'):
    videoExport.endMovie()
    exit()

```

For animated GIFs, it’s probably easiest to go the `saveFrame()` route, then compile the images into a GIF using whatever (i.e. [https://ezgif.com/maker](https://ezgif.com/maker)). There are also Python [libraries](http://imageio.github.io/) for creating animated GIFs, should you wish to automate the process.
