示例#1
0
def decode_to_yuv_mplayer(input, output, **options):
    for opt, val in [('vf', 'scale=:::0'), ('sound', False), ('benchmark', True),
                     ('quiet', False), ('lavdopts', 'skiploopfilter=none:threads=1'),
                     ('consolecontrols', False), ('noconfig', 'all'),
                     ('vo', 'yuv4mpeg:file="%s"' % output)]:
        options.setdefault(opt, val)
    # Decode jpgs with the ijpg codec, to force conversion to rgb,
    # which will then correctly convert to yuv.  The mplayer internal
    # jpg decoder would write the full range yuv data to the output
    # stream (instead of 16-235).
    if input.endswith(('.jpg', '.jpeg')):
        options.setdefault('vc', 'ijpg,')

    option_list = []
    for k, v in options.iteritems():
        if v is True:
            option_list.append('-'+k)
        elif v is False:
            option_list.append('-no'+k)
        elif not v:
            continue
        else:
            option_list.append('-'+k)
            option_list.append(str(v))

    return asynproc.run_process([which('mplayer'), input] + option_list, terminate_children=True)
示例#2
0
def decode_to_yuv_mplayer(input, output, **options):
    for opt, val in [
        ("vf", "scale=:::0"),
        ("sound", False),
        ("benchmark", True),
        ("quiet", False),
        ("lavdopts", "skiploopfilter=none:threads=1"),
        ("consolecontrols", False),
        ("noconfig", "all"),
        ("vo", 'yuv4mpeg:file="%s"' % output),
    ]:
        options.setdefault(opt, val)
    # Decode jpgs with the ijpg codec, to force conversion to rgb,
    # which will then correctly convert to yuv.  The mplayer internal
    # jpg decoder would write the full range yuv data to the output
    # stream (instead of 16-235).
    if input.endswith((".jpg", ".jpeg")):
        options.setdefault("vc", "ijpg,")

    option_list = []
    for k, v in options.iteritems():
        if v is True:
            option_list.append("-" + k)
        elif v is False:
            option_list.append("-no" + k)
        elif not v:
            continue
        else:
            option_list.append("-" + k)
            option_list.append(str(v))

    return asynproc.run_process([which("mplayer"), input] + option_list, terminate_children=True)
示例#3
0
def decode_to_yuv_ffmpeg(input, output, **options):
    for opt, val in [('f', 'yuv4mpegpipe'), ('pix_fmt', 'yuv420p'), ('y', True)]:
        options.setdefault(opt, val)
    option_list = []
    for k, v in options.iteritems():
        if v is True:
            option_list.append('-'+k)
        else:
            option_list.append('-'+k)
            option_list.append(str(v))
    return asynproc.run_process([which('ffmpeg'), '-i', input] + option_list + [output])
示例#4
0
def decode_to_yuv_ffmpeg(input, output, **options):
    for opt, val in [("f", "yuv4mpegpipe"), ("pix_fmt", "yuv420p"), ("y", True)]:
        options.setdefault(opt, val)
    option_list = []
    for k, v in options.iteritems():
        if v is True:
            option_list.append("-" + k)
        else:
            option_list.append("-" + k)
            option_list.append(str(v))
    return asynproc.run_process([which("ffmpeg"), "-i", input] + option_list + [output])
示例#5
0
def encode_yuv_to_h264(input, output, **options):
    options.setdefault('preset', 'veryslow')
    # The following defaults are for QuickTime compatibility
    options.setdefault('profile', 'main')
    options.setdefault('bframes', '2')
    options.setdefault('ref', '8')
    options.setdefault('partitions', 'p8x8,b8x8,i4x4,p4x4')

    option_list = [('--'+k, str(v)) for k, v in options.iteritems()]
    option_list = [opt for x in option_list for opt in x]

    return asynproc.run_process([which('x264'), '--output', output, input] + option_list)
示例#6
0
def encode_yuv_to_h264(input, output, **options):
    options.setdefault("preset", "veryslow")
    # The following defaults are for QuickTime compatibility
    options.setdefault("profile", "main")
    options.setdefault("bframes", "2")
    options.setdefault("ref", "8")
    options.setdefault("partitions", "p8x8,b8x8,i4x4,p4x4")

    option_list = [("--" + k, str(v)) for k, v in options.iteritems()]
    option_list = [opt for x in option_list for opt in x]

    return asynproc.run_process([which("x264"), "--output", output, input] + option_list)
示例#7
0
def probe(input):
    result = {'streams': [], 'format': {}}
    current = result['format']
    with asynproc.run_process([which('ffprobe'), '-show_format', '-show_streams', input],
                              stderr=subprocess.PIPE) as prober:
        stdout, stderr = prober.communicate()
        for line in stdout.split('\n'):
            line = line.strip()
            if not line:
                continue
            if line == '[STREAM]':
                result['streams'].append({})
                current = result['streams'][-1]
                continue
            if line == '[FORMAT]':
                current = result['format']
                continue
            if '=' not in line:
                continue
            head, sep, tail = line.partition('=')
            current[head] = tail
    result['streams'].sort(key=lambda x: int(x['index']))
    return result
示例#8
0
def probe(input):
    result = {"streams": [], "format": {}}
    current = result["format"]
    with asynproc.run_process(
        [which("ffprobe"), "-show_format", "-show_streams", input], stderr=subprocess.PIPE
    ) as prober:
        stdout, stderr = prober.communicate()
        for line in stdout.split("\n"):
            line = line.strip()
            if not line:
                continue
            if line == "[STREAM]":
                result["streams"].append({})
                current = result["streams"][-1]
                continue
            if line == "[FORMAT]":
                current = result["format"]
                continue
            if "=" not in line:
                continue
            head, sep, tail = line.partition("=")
            current[head] = tail
    result["streams"].sort(key=lambda x: int(x["index"]))
    return result