You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

128 lines
4.1 KiB

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2009 Marc Poulhiès
#
# This file is part of Plopifier.
#
# Plopifier is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Plopifier is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Plopifier. If not, see <http://www.gnu.org/licenses/>.
import sys
import os
import optparse
import tempfile
from datetime import datetime,timedelta
from subprocess import Popen
from plopifier import request,vimeo
#mencoder mf://@filelist.ok
# -mf w=640:h=480:fps=25:type=jpg
# -ovc lavc
# -lavcopts vcodec=mpeg4:mbd=2:trell
# -oac copy
# -o saint-eynard-2008-05-04.avi
def down_sample(list, num):
r = float(len(list))/float(num)
return [list[int(i*r)] for i in xrange(num)]
def build_video (file_list, duration, output_filename, fps=25):
nframe = duration * fps
print "max frame:", nframe, "got :", len(file_list)
if len(file_list) > nframe:
file_list = down_sample(file_list, nframe)
fd,flist = tempfile.mkstemp(prefix="plopificator")
fh = os.fdopen(fd, "w")
fh.write("\n".join(file_list))
fh.write("\n")
fh.close()
cmd = "mencoder mf://@%s " %flist
cmdargs = "-mf w=640:h=480:fps=%d:type=jpg " %fps
cmdargs += "-ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell -oac copy "
cmd += cmdargs
cmd += "-o " + output_filename
p = Popen(cmd, shell=True)
print "finished with %s" %cmd
sts = os.waitpid(p.pid, 0)
os.unlink(flist)
def main(argv):
parser = optparse.OptionParser(
usage='Usage: %prog [options]',
description="A cloud movi3 generat0r ")
parser.add_option('-k', '--vimeo-apikey', metavar='api-key',
help='set the "api_key" for vimeo')
parser.add_option('-s', '--vimeo-secret', metavar='api-secret',
help='set the "secret" for vimeo')
parser.add_option('-t', '--vimeo-authtoken', metavar='authtok',
help='set the "auth_token" for vimeo')
parser.add_option('-d', '--sqldb-file', metavar='FILE',
help='set the sqlite file',
default="/mnt/ft-1/webcam/test.sqlite")
parser.add_option('-r', '--sqldb-root', metavar='PATH',
help='set the root for relative paths in db',
default="/mnt/ft-1/webcam")
parser.add_option('--delta', metavar='TIME',
help='set the time between two sequential beginings')
parser.add_option('-b', '--begin', metavar='DATE',
help='set the start date')
parser.add_option('-e', '--end', metavar='DATE',
help='set the end date')
parser.add_option('-u', '--only-upload', metavar='FILE',
help='only upload FILE to vimeo')
(options, args) = parser.parse_args(argv[1:])
v = vimeo.Vimeo(options.vimeo_apikey,
options.vimeo_secret,
options.vimeo_authtoken)
tags = ["SaintEynard", "nuages", "clouds"]
if options.only_upload != None:
v.upload(options.only_upload, "Forced upload", tags)
return
print "use: ", options.sqldb_file, options.sqldb_root
sq = request.Request(options.sqldb_file, options.sqldb_root)
delta = timedelta(1)
start = datetime(2008,02,16)
morning = timedelta(0,0,0,0,0,6)
full_day = timedelta(0,0,0,0,0,15)
today = start
for i in xrange(20):
files = sq.get_files(today+morning, today + morning + full_day)
today += delta
build_video(files, 120, "/tmp/saint-eynard.avi")
v.upload("/tmp/saint-eynard.avi", str(today.strftime("%d%m%Y")), tags)
if __name__ == '__main__':
main(sys.argv)