Example #1
0
def encode(infile, options):
    """Encode infile (a MultimediaFile) with ffmpeg, using the given options."""
    cmd = 'ffmpeg'
    cmd += ' -i "%s"' % infile.filename
    if options['format'] in ['vcd', 'svcd', 'dvd']:
        cmd += ' -tvstd %s' % options['tvsys']
        cmd += ' -target %s-%s' % (options['format'], options['tvsys'])
    cmd += ' -r %g' % options['fps']
    cmd += ' -ar %s' % options['samprate']

    # Convert scale/expand to ffmpeg's padding system
    if options['scale']:
        cmd += ' -s %sx%s' % options['scale']
    if options['expand']:
        e_width, e_height = options['expand']
        s_width, s_height = options['scale']
        h_pad = (e_width - s_width) / 2
        v_pad = (e_height - s_height) / 2
        if h_pad > 0:
            cmd += ' -padleft %s -padright %s' % (h_pad, h_pad)
        if v_pad > 0:
            cmd += ' -padtop %s -padbottom %s' % (v_pad, v_pad)
    if options['widescreen']:
        cmd += ' -aspect 16:9'
    else:
        cmd += ' -aspect 4:3'

    cmd += ' -o "%s"' % options['out']

    script = Script('ffmpeg_encode')
    script.append(cmd)
    script.run()
    return script
Example #2
0
 def __init__(self, options):
     self.options = options
     self.script = Script('TextMenu')
     basename = self.options['out']
     # TODO: Store intermediate images in a temp folder
     self.bg_canvas = basename + '.bg_canvas.png'
     self.fg_canvas = basename + '.fg_canvas.png'
     self.fg_highlight = basename + '.fg_highlight.png'
     self.fg_selection = basename + '.fg_selection.png'
     print "Creating a menu with %s titles" % len(options['titles'])
     self.build_reusables()
     self.draw_background_canvas()
     self.draw_background_layer()
     self.draw_highlight_layer()
     self.draw_selection_layer()
     self.gen_video()
     self.gen_audio()
     self.gen_mpeg()
     self.script.run()
Example #3
0
def encode(infile, options):
    """Return a Script to encode infile (a MultimediaFile) with mencoder,
    using the given options."""
    cmd = 'mencoder'
    cmd += ' "%s" -o "%s"' % (infile.filename, options['out'])
    cmd += ' -oac lavc -ovc lavc -of mpeg'
    # Format
    if options['format'] in ['vcd', 'svcd']:
        cmd += ' -mpegopts format=x%s' % options['format']
    else:
        cmd += ' -mpegopts format=dvd'
    
    # Audio settings
    # Adjust sampling rate
    # TODO: Don't resample unless needed
    cmd += ' -srate %s' % options['samprate']
    cmd += ' -af lavcresample=%s' % options['samprate']

    # Video codec
    if options['format'] == 'vcd':
        lavcopts = 'vcodec=mpeg1video'
    else:
        lavcopts = 'vcodec=mpeg2video'
    # Audio codec
    if options['format'] in ['vcd', 'svcd']:
        lavcopts += ':acodec=mp2'
    else:
        lavcopts += ':acodec=ac3'
    lavcopts += ':abitrate=%s:vbitrate=%s' % \
            (options['abitrate'], options['vbitrate'])
    # Maximum video bitrate
    lavcopts += ':vrc_maxrate=%s' % options['vbitrate']
    if options['format'] == 'vcd':
        lavcopts += ':vrc_buf_size=327'
    elif options['format'] == 'svcd':
        lavcopts += ':vrc_buf_size=917'
    else:
        lavcopts += ':vrc_buf_size=1835'
    # Set appropriate target aspect
    if options['widescreen']:
        lavcopts += ':aspect=16/9'
    else:
        lavcopts += ':aspect=4/3'
    # Put all lavcopts together
    cmd += ' -lavcopts %s' % lavcopts

    # FPS
    if options['tvsys'] == 'pal':
        cmd += ' -ofps 25/1'
    elif options['tvsys'] == 'ntsc':
        cmd += ' -ofps 30000/1001' # ~= 29.97

    # Scale/expand to fit target frame
    if options['scale']:
        vfilter = 'scale=%s:%s' % options['scale']
        # Expand is not done unless also scaling
        if options['expand']:
            vfilter += ',expand=%s:%s' % options['expand']
        cmd += ' -vf ' + vfilter

    # Create the Script, and add the single command to it
    script = Script('mencoder_encode')
    script.append(cmd)
    script.run()
    return script