Created
December 28, 2010 01:26
-
-
Save hugs/756763 to your computer and use it in GitHub Desktop.
Code I used to record time-lapse webcam images, and then convert them all into a movie.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # 1) Take pictures | |
| # | |
| # Hardware: Logitech Webcam | |
| # Software: | |
| # a) OS X 10.6.8 | |
| # b) Python 2.6+ | |
| # c) isightcapture | |
| # I use a freeware program for OS X called "isightcapture". It's not open source, | |
| # but you can find open source equivalents with a wee bit of googling. | |
| # The image capture itself takes about 3 seconds to complete, combined with a 1 second sleep, | |
| # I recorded one image about every 4 seconds. | |
| #!/usr/bin/python | |
| import os | |
| import time | |
| def take_picture(counter): | |
| try: | |
| os.system("/usr/local/bin/isightcapture ./pics/time-lapse-%010d.jpg" % counter) | |
| except: | |
| print "Exception!" | |
| i = 0 | |
| while True: | |
| print i | |
| time.sleep(3) | |
| take_picture(i) | |
| i += 1 | |
| # | |
| # 2) Find 'missing' files | |
| # | |
| # Find the places in the sequence where an image didn't get taken by the webcam. | |
| # Why? Well, you need to have a perfect, unbreaking chain of increasing sequence | |
| # numbers for ffmpeg to encode the entire directory of jpgs into a movie. To | |
| # fix the problem, I find where the chain was broken and duplicate the previous | |
| # image, using the 'missing' file name to fill the gap. If I had planned ahead, | |
| # I would have accounted for this issue in step 1. | |
| #!/usr/bin/python | |
| from glob import glob | |
| files = glob('time-lapse-*.jpg') | |
| for i, file in enumerate(files): | |
| file_number = int(file.split('time-lapse-')[1].split('.jpg')[0]) | |
| if i != file_number: | |
| print file | |
| break | |
| # | |
| # 3) Convert all images files into one movie | |
| # | |
| # At a command prompt: | |
| ffmpeg -sameq -f image2 -i time-lapse-%010d.jpg -r 12 -s 640x480 your-awesome-movie.mp4 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment