14
Aug
Posted by Derek@TheDailyLinux in Scripting » 3 Comments »
Python Script to Recursively Search For and Generate Thumbnails for Video Files
This script will recursively search for files based on listed extension names and then use the ‘ffmpegthumbnailer’ program to generate a thumbnail for each file it finds.
If you’re on a Ubuntu system, you should be able to install ffmpegthumbnailer using apt-get install ffmpegthumbnailer.
#!/usr/bin/python
import os
for root, dirnames, filenames in os.walk('/var/www/media/'):
for filename in filenames:
if filename.lower().endswith(('.m4v', '.mov', '.mpeg', 'mp4')):
ifile = os.path.join(root, filename)
ofile = os.path.splitext(ifile)[0] + ".jpg"
try:
with open(ofile) as f: pass
except IOError as e:
print "Generating thumbnail for: " + ifile
fftoptions = "-s0 -f"
command = "ffmpegthumbnailer -i %s -o %s %s" % (ifile, ofile, fftoptions)
p = os.popen(command,"r")
while 1:
line = p.readline()
if not line: break
print line
I had a specific purpose for this script, but you could easily modify it to fit your needs. When you save the file, don’t forget to mark it as executable with chmod +x scriptname.py.
Feel free to donate if this post prevented any headaches! Another way to show your appreciation is to take a gander at these relative ads that you may be interested in:
Here are some similar posts that you may be interested in:
There's 3 Comments So Far
August 16th, 2012 at 8:36 am
How do you get your code to display via colors?
August 16th, 2012 at 8:43 am
It’s a plugin called “Syntax Highlighter for WordPress”. Then, I just surround my code in the language I want to use like [PYTHON], [CPP], [BASH], etc…
December 14th, 2012 at 6:04 pm
Thanks man !
You saved my night !
Share your thoughts, leave a comment!