Example #1
0
def _init_config():
    with open('config.ini', 'r') as conf_file:
        c = ConfigParser.ConfigParser()
        c.readfp(conf_file)
        if not _get_config(c, 'input', 'video_dir'):
            raise ValueError('video_dir not specified')
        video_dir = pathutil.fullpath(_get_config(c, 'input', 'video_dir'))
        return {
            'video_dir': video_dir,
            'input_videos': files.input_videos(
                video_dir, _get_config(c, 'input', 'video_postfix',
                                       'mov,mkv,mp4,avi,rm,rmvb').split(',')),
            'bgm': pathutil.fullpath(_get_config(c, 'input', 'bgm')),
            'sequence': pathutil.fullpath(_get_config(c, 'input', 'sequence')),
            'avconv': _get_config(c, 'exec', 'avconv'),
            'mencoder': _get_config(c, 'exec', 'mencoder'),
            'display': _get_config(c, 'exec', 'display'),
            'resolution': _get_config(c, 'output', 'resolution', '640:360'),
            'bitrate': _get_config(c, 'output', 'bitrate', '1.6M'),
            'fps': _get_config(c, 'output', 'fps', '24'),
            'vcodec': _get_config(c, 'output', 'vcodec', 'copy'),
        }, _logger(c)
Example #2
0
import os

from config import config, logger
import audio_slice
import video_slice
import sequence
import pathutil
import shell

OUTPUT_FILE = pathutil.fullpath('./output/output.mp4')


def avmerge(audio_file, video_file, output_file=OUTPUT_FILE,
            force_encoder=None, sync=True):
    logger.info('Zip video and audio')
    pathutil.rm(output_file)
    p = shell.Process([
        config['avconv'],
        '-i', audio_file,
        '-i', video_file,
        '-acodec', 'copy',
        '-vcodec', 'copy' if force_encoder is None else force_encoder,
        output_file], sync)
    p.execute()
    if sync and p.returncode != 0:
        raise ValueError('fail')
    return output_file


def _merge_sections(sections, audio_file):
    video_file = video_slice.merge_segments(slice_partial(sections))
Example #3
0
import os
import re

from config import config, logger
import pathutil
import shell

_vfilters = dict()
VIDEO_OUTPUT_DIR = pathutil.fullpath(os.path.join('output', 'video'))
FRAME_OUTPUT_DIR = pathutil.fullpath(os.path.join('output', 'frame'))


def _vfilter(f):
    _vfilters[f.__name__[1:].lower()] = f
    return f


@_vfilter
def _repeatframe(i, seg, inp, args):
    image = save_frame_to(0, inp, inp + '_rf.png')
    if image is None:
        raise ValueError('process fail at %d : %s' % (i, p.stderr))
    tmp_file = inp + '_repeat_frame.mp4'
    if os.path.exists(tmp_file):
        return tmp_file
    p = shell.execute(
        config['avconv'],
        '-loop', '1',
        '-i', image,
        '-vcodec', config['vcodec'],
        '-t', str(seg.duration),
Example #4
0
import os
import re
from pydub import AudioSegment

from config import config
import pathutil
import sequence
import shell

_DURATION_RE = re.compile('Duration: (?P<h>[0-9]+):(?P<m>[0-9]+):' +
                          r'(?P<s>[0-9]+\.[0-9]+)')
OUTPUT_DIR = pathutil.fullpath(os.path.join('output', 'audio'))


def audio_len(f):
    return len(AudioSegment.from_mp3(f)) / 10 / 100.0


def _audio_from_to(input_file, ext, start, end, output_dir):
    output_path = os.path.join(output_dir, ''.join([
        'audio_', str(start), '-', str(end), ext]))
    if pathutil.isfile(output_path):
        return output_path
    AudioSegment.from_mp3(input_file)[
        int(start * 1000): int(end * 1000)].export(output_path, format='mp3')
    return output_path


def slice(input_file, start, end_time, output_dir=OUTPUT_DIR):
    pathname, ext = os.path.splitext(input_file)
    return _audio_from_to(input_file, ext, start, end_time, output_dir)