Hi, I've finally found the time to adpot a script (from "derpeter" who used it for cccamp2011) to generate preroles for our pentabarf xml schedule data. It creates 7 seconds prerole files for all events, I've made one available at: http://layer-acht.org/809.dv I just think the background picture could and should be improved ;) Currently I use the ttf-prociono font for text (available in wheezy and sid) and the pink-red is the color from http://wiki.debian.org/DebianLogo while the DebConf11 text and logo is the one from http://wiki.debconf.org/wiki/DebConf11/Logo The template to edit (background.svg) is attached to this mail. The scripts are attached as well, you want to run xml2prerole.py without any arguments :) the schedule url is hard-coded... dont forget to run this first: apt-get install python-argparse ttf-prociono ffmpeg I'd be delighted to see improved backgrounds! I was also thinking of creating postroles(?) saying "copyright 2011, the debconf videoteam $list_of_names_in_random_order_each_time - archive at http://video.debian.net" or such. For that I'd probably use the group picture as backgroud... What do you think? cheers, Holger
Attachment:
background.svg
Description: image/svg
#!/usr/bin/env python # Copyright (C) 2011 derpeter # # This program 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. # # This program 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 this program. If not, see <http://www.gnu.org/licenses/>. import argparse import fileinput import commands import sys import os import re parser = argparse.ArgumentParser(description='Generate prerole file: make sure you have ffmpeg and inkscape in $PATH') parser.add_argument('-f', action="store", dest="background", help="background SVG. Default background.svg", default='background.svg' ) parser.add_argument('-t', action="store", dest="title", help="talk title") parser.add_argument('-s', action="store", dest="subtitle", help="talk subtitle", default = '') parser.add_argument('-p', action="store", dest="speakers", help="person(s). Persons are separated with a blank.", nargs="+") parser.add_argument('-d', action="store", dest="date", help="date of the talk") parser.add_argument('-b', action="store", dest="begin", help="begin of the talk") parser.add_argument('-i', action="store", dest="id", help="talk id") parser.add_argument('-o', action="store", dest="output", help="output dir", default='') parser.add_argument('-w', action="store", dest="workdir", help="working dir", default='') args = parser.parse_args() output=[] # line lengths linelen64pt = 37 linelen48pt = 40 wide_linelen48pt = 49 def html_protect(vstr): vstr = "&".join(vstr.split("&")) vstr = "<".join(vstr.split("<")) vstr = ">".join(vstr.split(">")) vstr = """.join(vstr.split('"')) vstr = "'".join(vstr.split("'")) return vstr # replace the string in a given svg def build_svg(): #check the inputs filds if args.id == None: print "id not defined" sys.exit(1) else: print "working on %s_prerole.dv now..." % args.id if args.title == None: print "title not defined" sys.exit(1) if args.subtitle == None: print "subtitle not defined" args.subtitle = '' if args.speakers == None: print "WARNING: person not defined" #sys.exit(1) if args.date == None: print "date not defined" args.date='' if args.begin == None: print "begin not defined" args.begin = '' # build the speaker name list speakers1 = '' speakers2 = '' speakers3 = '' speakers4 = '' speakers5 = '' speakers6 = '' if args.speakers is not None: speakers = [] tmp = '' for spk in args.speakers: if len(tmp) + 3 + len(spk) > linelen48pt: speakers.append(tmp) # + ' -') tmp = '' # append if tmp != '': tmp = tmp + ' - ' tmp = tmp + spk if tmp != '': speakers.append(tmp) if len(speakers) == 1: speakers1 = speakers[0] speakers2 = '' elif len(speakers) == 2: speakers1 = speakers[0] speakers2 = speakers[1] elif len(speakers) == 3: speakers1 = speakers[0] speakers2 = speakers[1] speakers3 = speakers[2] elif len(speakers) == 4: speakers1 = speakers[0] speakers2 = speakers[1] speakers3 = speakers[2] speakers4 = speakers[3] elif len(speakers) == 5: speakers1 = speakers[0] speakers2 = speakers[1] speakers3 = speakers[2] speakers4 = speakers[3] speakers5 = speakers[4] elif len(speakers) == 6: speakers1 = speakers[0] speakers2 = speakers[1] speakers3 = speakers[2] speakers4 = speakers[3] speakers5 = speakers[4] speakers6 = speakers[5] else: print "too many authors for event %s" % args.id sys.exit(1) # if len(args.speakers) == 1: # speaker = args.speakers[0] # elif len(args.speakers) == 2: # speaker = args.speakers[0] + ' ' + args.speakers[1] # elif len(args.speakers) == 3: # speaker = args.speakers[0] + ' - ' + args.speakers[1] + ' - ' + args.speakers[2] # elif len(args.speakers) == 4: # speaker = args.speakers[0] + ' - ' + args.speakers[1] + ' - ' + args.speakers[2] + ' - ' + args.speakers[3] # # in the rare case that we have more than 4 speaker we replace the last speakers with et al. # elif len(args.speakers) > 4: # speaker = args.speakers[0] + ' - ' + args.speakers[1] + ' - ' + args.speakers[2] + ' - ' + args.speakers[3] + ' - et al.' # split title into two lines if necessary if len(args.title) > linelen64pt: titleRE = re.compile(r'^(.{0,'+str(linelen64pt)+r'}) (.*)$') titles = titleRE.search(args.title).groups() title1 = titles[0] title2 = titles[1] if len(title2) > linelen64pt: print "WARNING: title too long (2nd line)" title2 = title2[:linelen64pt]+"..." else: title1 = args.title title2 = '' # split subtitle into two lines if necessary if len(args.subtitle) > wide_linelen48pt: subtitleRE = re.compile(r'^(.{0,'+str(wide_linelen48pt)+r'}) (.*)$') subtitles = subtitleRE.search(args.subtitle).groups() subtitle1 = subtitles[0] subtitle2 = subtitles[1] if len(subtitle2) > wide_linelen48pt+10: print "WARNING: subtitle too long (2nd line)" subtitle2 = subtitle2[:wide_linelen48pt]+"..." else: subtitle1 = args.subtitle subtitle2 = '' # replace the strings in the svg # add here some filtering to precent to long names for line in fileinput.FileInput(args.background,inplace=0): if "%title$1%" in line: line=line.replace('%title$1%', html_protect(title1)) elif "%title$2%" in line: line=line.replace('%title$2%', html_protect(title2)) elif "%subtitle$1%" in line: line=line.replace('%subtitle$1%', html_protect(subtitle1)) elif "%subtitle$2%" in line: line=line.replace('%subtitle$2%', html_protect(subtitle2)) elif "%speaker$1%" in line: line=line.replace('%speaker$1%', html_protect(speakers1)) elif "%speaker$2%" in line: line=line.replace('%speaker$2%', html_protect(speakers2)) elif "%speaker$3%" in line: line=line.replace('%speaker$3%', html_protect(speakers3)) elif "%speaker$4%" in line: line=line.replace('%speaker$4%', html_protect(speakers4)) elif "%speaker$5%" in line: line=line.replace('%speaker$5%', html_protect(speakers5)) elif "%speaker$6%" in line: line=line.replace('%speaker$6%', html_protect(speakers6)) elif "%date%" in line: line=line.replace('%date%', args.date+' '+args.begin) output.append(line) outfileName = args.workdir+args.id+".svg" outfile = file(outfileName, 'w') outfile.writelines(output) # create a png out of the svg def build_png(): result = commands.getstatusoutput("inkscape "+ args.workdir+args.id +".svg -e "+args.workdir+args.id+".png") if result[0] != 0: print "png not created" print result[1] sys.exit(1) # build the dv file def build_dv(): prerole_duration = "7s" # check if tmp file already present and remove it if os.path.exists(args.workdir+args.id+".tmp"): commands.getstatusoutput("rm -f "+args.workdir+args.id+".tmp") result = commands.getstatusoutput("ffmpeg -qscale 3 -loop_input -i "+ args.workdir+args.id +".png -target dv-pal "+args.workdir+args.id+".tmp -t "+prerole_duration+" -r 25 -an -threads 2") if result[0] != 0: print "inital dv file not created" print result[1] sys.exit(1) #check if silence file is present, if not generate it if not os.path.exists('silence'): os.system('dd if=/dev/zero of=silence ibs=10240 count=10240') #check if prerole file is present if yes delete it if os.path.exists(args.output+args.id+"prerole.dv"): commands.getstatusoutput("rm -f "+args.output+args.id+"prerole.dv") #cat the first part of the prerole in front of the edittedt one result = commands.getstatusoutput('cat preprerole.dv '+ args.workdir+args.id +'.tmp > '+ args.workdir+args.id +'.tmp1') result = commands.getstatusoutput("ffmpeg -f dv -target pal-dv -i "+args.workdir+args.id+".tmp1 -f u16le -i silence -vcodec copy -t "+prerole_duration+" "+args.workdir+args.id+"_prerole.dv") #if result[0] == 1: # no idea why ffmpeg is not returning 0 at this call if True: commands.getstatusoutput("rm -f "+args.workdir+args.id+".tmp "+args.workdir+args.id+".tmp1") else: print "audio fix not applied" print result[1] sys.exit(1) #clean up commands.getstatusoutput("rm -f "+args.workdir+args.id+".png") commands.getstatusoutput("rm -f "+args.workdir+args.id+".svg") build_svg() build_png() build_dv() sys.exit(0)
#!/usr/bin/env python # -*- coding:utf8 -*- import urllib import lxml.etree from subprocess import Popen rohdaten = urllib.urlopen("http://penta.debconf.org/dc11_schedule/schedule.en.xml").read() #daten = unicode(rohdaten, "latin1") daten = rohdaten root = lxml.etree.fromstring(daten).getroottree() SCRIPT_FULLPATH = "genPrerole.py" EXTRA_ARGS = [ "-o", "../prerole/", #"-w", "/tmp/workdir" ] def call_genPrerole(info): command = ["python", SCRIPT_FULLPATH] arguments = dict(t="title", s="subtitle", p="speakers", d="date", b="start", i="id") # if info["id"] != str(4451): # return for flag, key in arguments.iteritems(): #if flag == 'speakers' and key == []: # key = '_' flag = "-" + flag data = None try: data = info[key] except KeyError: print "key %s does not exist for %s" % (key, info["id"]) if data is None or data == []: #print "value %s was None for %s" % (key, info["id"]) pass # data = " " # flag = " " elif isinstance(data, list): command += [flag] + data elif isinstance(data, basestring): command += [flag, data] else: raise ValueError("unexpected datatype") command += EXTRA_ARGS process = Popen(command) returncode = process.wait() if returncode != 0: print "returncode %d != 0 for %r" % (returncode, command) def daten_von_event(event, upper_info): info = upper_info.copy() info["id"] = event.get("id") things = "start room title subtitle".split(" ") for thing in things: thing_tag = event.find(thing) if thing_tag is None: print "ERROR: no tag %s in %r" % (thing, event) else: if event.find(thing).text is not None: info[thing] = event.find(thing).text info["speakers"] = [] persons = event.find("persons") for person in list(persons): info["speakers"].append(person.text) call_genPrerole(info) def daten_von_raum(raum, upper_info): info = upper_info.copy() info["name"] = raum.get("name") for event in list(raum): daten_von_event(event, info) def daten_von_tag(tag): info = {} info["date"] = tag.get("date") info["index"] = tag.get("index") for raum in list(tag): daten_von_raum(raum, info) def daten_von_schedule(schedule): for tag in schedule.xpath("day"): daten_von_tag(tag) daten_von_schedule(root)