Skip to content

Commit

Permalink
How to put background.png in slithy module dir?
Browse files Browse the repository at this point in the history
  • Loading branch information
emuller committed Jun 20, 2010
1 parent 5e60996 commit 783ab1e
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 8 deletions.
25 changes: 22 additions & 3 deletions README.movies
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,33 @@ MPEG-1 video, and MPEG-2 audio ... and even then it is rather fussy.

In short, encode mpegs for this module as the following example:

mencoder something_completely.flv -vf scale=320:240 -of mpeg -mpegopts
mencoder something_completely.flv -vf scale=320:240 -of mpeg -mpegopts \
format=mpeg1:tsaf:muxrate=2000 \
-o test.mpg -srate 44100 -af lavcresample=44100 -oac twolame
-o test.mpg -srate 44100 -af lavcresample=44100 -oac twolame \
-twolameopts br=160 \
-ovc lavc -lavcopts vcodec=mpeg1video:vbitrate=1152:keyint=15:mbd=2

For cutting:

Mencoder docs:
-endpos <[[hh:]mm:]ss[.ms]|size[b|kb|mb]> (also see -ss and -sb)
Stop at given time or byte position.
NOTE: Byte position is enabled only for MEncoder and will not be
accurate, as it can only stop at a frame boundary. When used in
conjunction with -ss option, -endpos time will shift forward by
seconds specified with -ss.

EXAMPLE:
-endpos 56
Stop at 56 seconds.
-endpos 01:10:00
Stop at 1 hour 10 minutes.
-ss 10 -endpos 56
Stop at 1 minute 6 seconds.
-endpos 100mb
Encode only 100 MB.
Example: start at 20 secons, take 50seconds

-ss 00:00:20 -endpos 00:00:50

Remove the current audio track:
Expand All @@ -21,7 +40,7 @@ mencoder -ovc copy -nosound video.avi -o video_nosound.avi

Place a new audio track:

mencoder -ovc copy -audiofile soundtrack.mp3 -oac copy
mencoder -ovc copy -audiofile soundtrack.mp3 -oac copy \
video_nosound.avi -o video_new.avi

Blank time
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from distutils.core import setup
setup(name = "slithy", version = "20030706",
setup(name = "slithy", version = "slithy-hg-tip",
packages = ["slithy"],
package_data={'slithy': ['*.so', 'fonts/*']})
package_data={'slithy': ['*.so', 'fonts/*','rst2pdf_*']})
93 changes: 90 additions & 3 deletions slithy/slidereader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

import yaml

import slithy
import slithy.presentation as presenter
import slithy.library as sylib
import slithy.fonts
Expand All @@ -16,6 +17,8 @@
#this has to be configure by the user by load_env
image_library = {'default':{},'pdf':{},'svg':{}}
font_library = {'default':slithy.fonts.fonts}
rst_config = {'rst_default_style':os.path.join(slithy.__path__[0],'rst2pdf_default.style')}


#from yamlclasses import *

Expand Down Expand Up @@ -90,6 +93,9 @@ def load_env(filename):
if 'font_library' in env:
load_font_library(env['font_library'])

if 'rst_config' in env:
rst_config.update(env['rst_config'])



def include_slides(filename):
Expand Down Expand Up @@ -131,7 +137,11 @@ def include_slides(filename):
lib = 'default'
p.play(load_image_slides(slide['images'],library=lib, background=background))
p.pause()


elif 'rst' in slide:
images = rst2ppm_cache(i,slide['title'],slide['rst'])
p.play(load_image_slides(images,library='pdf',background=background))
p.pause()

else:
p.play(load_slide_content(slide['content']))
Expand Down Expand Up @@ -186,9 +196,11 @@ def setup_cachedir(path):




def pdf2ppm_cache(filename,slides):

import os.path
import time

cache_dir = './.slithy_pdfcache'
if not cache_dir in sylib.fontpath:
sylib.fontpath.append(cache_dir)
Expand All @@ -207,7 +219,9 @@ def pdf2ppm_cache(filename,slides):
for slide in slides:

target_file = gen_ppm_name(cache_dir,pdf_name,slide)
if os.path.exists(target_file):

# skip if cache exists and newer than pdf
if os.path.exists(target_file) and os.path.getmtime(filename)<os.path.getmtime(target_file):
print target_file," exists. Skipping."
else:
final_cmd = cmd % (slide,slide)
Expand Down Expand Up @@ -261,6 +275,79 @@ def svg2png_cache(svgs):
return images


def rst2pdf(rst_file, pdf_file, style_file):
# rst2pdf slides.rst -b1 -s slides.style

cmd = "rst2pdf %s -b1 -o %s -s %s" % (rst_file, pdf_file, style_file)

os.system(cmd)




def rst2ppm_cache(slide_num,slide_title, rst_content):

# directory for caching rst files, etc
cache_dir = './.slithy_rstcache'
if not cache_dir in sylib.fontpath:
sylib.fontpath.append(cache_dir)

setup_cachedir(cache_dir)

# rst target filename
base_filename = 'slide%d' % slide_num

# clear white space
slide_title = slide_title.strip()

# len of title for rst underline
underline = '_'*len(slide_title)

slide_text = """
%(title)s
%(underline)s
%(content)s
""" % {'title':slide_title, 'underline':underline,'content':rst_content}

rst_target = os.path.join(cache_dir, base_filename+'.rst')
pdf_target = os.path.join(cache_dir, base_filename+'.pdf')

# logic below to set changed to False
# if pdf doesn't need updating
changed = True
# check if rst content file differs from slide_text.
if os.path.exists(rst_target):
f = file(rst_target,'r')
old_slide_text = f.read()
f.close()

if old_slide_text==slide_text:
changed = False
else:
# write new content
f = file(rst_target,'w')
f.write(slide_text)
f.close()
else:
# write rst ... it doesn't exists
f = file(rst_target,'w')
f.write(slide_text)
f.close()

# if somehow pdf is missing, force generate
if not os.path.exists(pdf_target):
changed = True

# generate pdf if 'changed', i.e. needs updating
if changed:
rst2pdf(rst_target, pdf_target, rst_config['rst_default_style'])


return pdf2ppm_cache(pdf_target,[0])





def load_image_slides(images,library='default',background='bg'):
Expand Down

0 comments on commit 783ab1e

Please sign in to comment.