Skip to content

Instantly share code, notes, and snippets.

@pkarl
Last active August 29, 2015 13:56
Show Gist options
  • Save pkarl/9044049 to your computer and use it in GitHub Desktop.
Save pkarl/9044049 to your computer and use it in GitHub Desktop.
ffmpeg + ImageMagick + python stuffs

So here's what I did. I don't know if it's anywhere NEAR what you're getting at, but I think it's neato. Thanks for the source images :)

I created a bunch of interstitial 50% blended frames, and at higher rates (like 24fps) I see a difference!

Here's what I did:

  1. dumped all the images to a dir
  2. wrote a python script (attached)
  3. created an /output dir
  4. ran the python script, which copies source images + generates blended images using ImageMagick CLI junk
  5. ran ffmpeg within the /output dir
  6. video! --> https://dl.dropboxusercontent.com/u/126879/glob_test.mkv

My ffmpeg command: ffmpeg -f image2 -framerate 16 -pattern_type glob -i "*.jpg" glob_test.mkv

"""
This is a little script to help smooth out ffmpeg time lapse input.
It grabs a bunch of files, copies them, and generates blended
versions of each frame at 50%/50% using imagemagick composite operations.
"""
from os import listdir
from os.path import isfile, join
import subprocess
imgPath = './' # this is the dir that contains source images
outputPath = './output' # this is the dir we're dumping copies + blended images into
imgFiles = [ f for f in listdir(imgPath) if isfile(join(imgPath,f)) and f[-3:] == 'jpg' ]
def copyImageToOutput(srcImg):
subprocess.call("cp %s %s/" % (srcImg, outputPath), shell=True)
iterImgs = iter(imgFiles)
for currentImg in iterImgs:
try:
# if the iterator will let us, grab the next file (and advance the iterator pointer)
nextImg = next(iterImgs)
copyImageToOutput(nextImg)
# use imagemagick to composite the two images and dump the result into the output dir
subprocess.call("composite -dissolve 50 -gravity South %s %s %s/%s_blended.jpg" % (currentImg, nextImg, outputPath, currentImg), shell=True)
except StopIteration, e:
# the iterator tried to get the 'next' image WHEN THERE WAS NO SUCH IMAGE
# lol
print 'hit the last image..'
pass
# dump the current image to the output dir
copyImageToOutput(currentImg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment