# How to creat a video with code

**URL:** <https://discourse.slicer.org/t/how-to-creat-a-video-with-code/14060>\
**Category:** Development\
**Created:** [October 15, 2020, 6:57pm UTC](https://discourse.slicer.org/t/how-to-creat-a-video-with-code/14060 "2020-10-15T18:57:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![aldoSanchez](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@aldoSanchez](https://discourse.slicer.org/u/aldoSanchez)\
**Post date:** [October 15, 2020, 6:57pm UTC](https://discourse.slicer.org/t/how-to-creat-a-video-with-code/14060/1 "2020-10-15T18:57:09Z")

</div>

Hi, today I was trying to make a video or gif.  
but the thing is that I couldn’t I don’t really now why but here’s the code I got:

cap = ScreenCapture.ScreenCaptureLogic().createVideo(30,‘extra’,‘C:\Program Files\Slicer 4.10.2’,‘image\_%05d.mp4’,‘vid.mp4’)

#what it’s in the repository is :  
def createVideo(self, frameRate, extraOptions, outputDir, imageFileNamePattern, videoFileName)

it gives me the next error:

Traceback (most recent call last):  
File “”, line 1, in   
File “C:/Program Files/Slicer 4.10.2/bin/…/lib/Slicer-4.10/qt-scripted-modules/ScreenCapture.py”, line 1100, in createVideo  
raise ValueError("Video creation failed: ffmpeg executable path is invalid: "+ffmpegPath)  
ValueError: Video creation failed: ffmpeg executable path is invalid: C:\Program Files\Slicer 4.10.2

if someone could give me an example of how to use it, that would help a lot.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [October 15, 2020, 7:10pm UTC](https://discourse.slicer.org/t/how-to-creat-a-video-with-code/14060/2 "2020-10-15T19:10:00Z")

</div>

You need to install ffmpeg (it cannot be bundled with Slicer due to video codec licensing issues) and tell the module where to find it. The easiest is to export a video using the Screen Capture module GUI first, which will offer automatic download and install of ffmpeg.

---

<div class="post-metadata">

**Author:** ![aldoSanchez](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@aldoSanchez](https://discourse.slicer.org/u/aldoSanchez)\
**Post date:** [October 15, 2020, 7:35pm UTC](https://discourse.slicer.org/t/how-to-creat-a-video-with-code/14060/3 "2020-10-15T19:35:52Z")

</div>

ScreenCapture.ScreenCaptureLogic().ffmpegDownload()  
#that gives me this but it dose not open  
Requesting download ffmpeg from [http://ffmpeg.zeranoe.com/builds/win64/static/ffmpeg-3.2.4-win64-static.zip](http://ffmpeg.zeranoe.com/builds/win64/static/ffmpeg-3.2.4-win64-static.zip)…

#so i went to :

> **[Download FFmpeg](https://ffmpeg.org/download.html)**

i don’t really undertand how to install this

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [October 15, 2020, 7:56pm UTC](https://discourse.slicer.org/t/how-to-creat-a-video-with-code/14060/4 "2020-10-15T19:56:42Z")

</div>

You can download and unzip any of the ffmpeg packages and set the path to ffmpeg.exe in the Screen Capture module GUI.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/0/e/0e8da3f85b8e3012fc8f5aae5d3cbbf42c813d7e.png)

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [October 15, 2020, 8:07pm UTC](https://discourse.slicer.org/t/how-to-creat-a-video-with-code/14060/5 "2020-10-15T20:07:58Z")

</div>

Alternatively, you can update the download URL in ScreenCapture.py file in your installed Slicer:

> <https://github.com/Slicer/Slicer/blob/403902710ce34505795044485881efdf915722a1/Modules/Scripted/ScreenCapture/ScreenCapture.py#L888>

---

<div class="post-metadata">

**Author:** ![aldoSanchez](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@aldoSanchez](https://discourse.slicer.org/u/aldoSanchez)\
**Post date:** [October 15, 2020, 8:29pm UTC](https://discourse.slicer.org/t/how-to-creat-a-video-with-code/14060/7 "2020-10-15T20:29:23Z")

</div>

i got it, thanks for the information it was really helpfull  
i leave the code:  
cap = ScreenCapture.ScreenCaptureLogic().createVideo(30,’-codec mpeg4 -qscale 3’,‘C:/Users/aldot/Desktop/ICBM/python/img’,‘image\_%05d.png’,‘vid.mp4’)
