47

I'm trying to make a video using a series of .png images. I found this Python script, but I am not entirely sure on how to use it:

https://sites.google.com/site/timelapsepy/home

I also tried to look into opencv, but it doesn't seem to install properly for me. Any ideas on a simple program to string several images together to create a time-lapse video? I would like to use Python for this if possible.

user1620716
  • 1,463
  • 6
  • 17
  • 26
  • 1
    The examples for that timelapsepy seem pretty straightforward. And it doesn't even seem to require much python knowledge as it is just a commandline utility set. What part are you stuck on? A pure python scripted solution is going to be more challenging that this. OpenCV or PIL would be harder for you to use if this tool set already confuses you. – jdi Nov 27 '12 at 18:50
  • The examples folder that I have only include a few images and one video. I don't entirely see how that helps. =/ – user1620716 Nov 27 '12 at 18:56
  • This script is meant to make a time lapse. Is that your goal? If all you want to do is combine the png images directly into a video, you can just use that `ffmpeg` approach from the tutorial. – jdi Nov 27 '12 at 19:01
  • 2
    @Matt: Wow, you close it, and it's immediately in the reopen-queue: http://stackoverflow.com/review/reopen/9922470 – Deduplicator Oct 20 '15 at 21:07

2 Answers2

59

If you really need a scripted python solution, you can look into using PIL

But if you just want to easily convert a sequence of png images to a movie, you can simply use ffmpeg:

ffmpeg -f image2 -r 1/5 -i image%05d.png -vcodec mpeg4 -y movie.mp4

This command takes images with 5 digit padding (image00001.png) and compresses them into an mpeg4 quicktime, at a rate of holding each frame for 5 seconds. You could do a different fps if your images are greater: -r 24 (24 frames per second)

jdi
  • 90,542
  • 19
  • 167
  • 203
  • what if I have many images with similar naming convention and want to create different videos out of them with name in a range. For example, image0001 - image 0090 as movie1, image0230 - image0320 as movie2? any idea? – Kexin Xu Jul 06 '15 at 21:26
  • @KexinXu - Then you need to use the `-start_number ` flag before the input, to tell it which frame to start at, and probably the `-t ` to tell it how long to make it. – jdi Jul 07 '15 at 01:32
  • 15
    For everyone reading this: while PIL was replaced by pillow, ffpmeg was _NOT_ replaced by libav/avconv. ffmpeg project is still going strong, having more contributions than libav. – xyzzyz Aug 15 '15 at 12:25
  • 1
    I believe the -f option is not needed. See https://ffmpeg.org/ffmpeg.html "The format is normally auto detected for input files and guessed from the file extension for output files, so this option is not needed in most cases." – DarylWM Dec 31 '16 at 02:50
  • @DarylWM have you confirmed it is not required, or just guessing? I think there are different possible image formats, and using an explicit image2 guarantees the flag support you are expecting to use. Also the documentation in that same ffmpeg link shows explicit usage – jdi Dec 31 '16 at 07:39
  • 1
    This does not work. I get this error: `[image2 @ 0x552f10b0] Could find no file with path 'image%05d.png' and index in the range 0-4 image%05d.png: No such file or directory` – Teacher of Things Jul 12 '17 at 00:44
  • @TeacherofThings it worked over 4.5 years ago in a bash shell :-) What are the actual names of your input files? My example is showing a pattern for files that are padded with 5 digits. Adjust padding as needing or just say %d if no padding – jdi Jul 12 '17 at 05:45
  • @jdi How can I run this command in Anaconda Spyder? How can I install ffmpeg in python? – MOON Jun 22 '20 at 14:43
  • @MOON ffmpeg is a command line utility. You have to install it in a platform specific way: https://ffmpeg.org/download.html – jdi Jun 23 '20 at 20:21
15

Instead of ffmpeg, you might want to use avconv

avconv -f image2 -i figMatplotlib%d.png -r 76 -s 800x600 foo.avi
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
Qin Chen
  • 183
  • 1
  • 2
  • 8
    are you sure that ffmpeg is deprecated, look here : http://git.videolan.org/?p=ffmpeg.git;a=log;h=HEAD – Oren Mar 02 '15 at 15:24
  • 1
    what if I have many images with similar naming convention and want to create different videos out of them with name in a range. For example, image0001 - image 0090 as movie1, image0230 - image0320 as movie2? any idea? – Kexin Xu Jul 06 '15 at 21:26
  • 7
    ffmpeg is not deprecated! Please see this answer: http://stackoverflow.com/questions/9477115/what-are-the-differences-and-similarities-between-ffmpeg-libav-and-avconv/9477756#9477756 – bzm3r Sep 19 '15 at 01:39