def encode_yuv(input, output, decode_options=None): if decode_options is None: decode_options = OptionsBase() decode_options.options = getattr(decode_options, "options", {}) for opt, val in [("f", "mov"), ("vcodec", "rawvideo"), ("pix_fmt", "uyvy422"), ("vtag", "2vuy"), ("y", True)]: decode_options.options.setdefault(opt, val) decoder_type = decode_options.options.get("type", "ffmpeg") with sequence_as_str_repr(input, decoder_type) as input: with decode_to_yuv_ffmpeg(input, output, **decode_options.options) as decoder: decoder_handler = FFmpegHandler(decoder, decode_options.status, decode_options.error) asynproc.loop()
def encode_yuv(input, output, decode_options=None): if decode_options is None: decode_options = OptionsBase() decode_options.options = getattr(decode_options, 'options', {}) for opt, val in [('f', 'mov'), ('vcodec', 'rawvideo'), ('pix_fmt', 'uyvy422'), ('vtag', '2vuy'), ('y', True)]: decode_options.options.setdefault(opt, val) decoder_type = decode_options.options.get('type', 'ffmpeg') with sequence_as_str_repr(input, decoder_type) as input: with decode_to_yuv_ffmpeg(input, output, **decode_options.options) as decoder: decoder_handler = FFmpegHandler(decoder, decode_options.status, decode_options.error) asynproc.loop()
def encode_h264(input, output, decode_options=None, encode_options=None): if decode_options is None: decode_options = OptionsBase() if encode_options is None: encode_options = OptionsBase() decode_options.options = getattr(decode_options, "options", {}) encode_options.options = getattr(encode_options, "options", {}) decoder_type = decode_options.options.get("type", "ffmpeg") with sequence_as_str_repr(input, decoder_type) as input: with asynproc.fifo_handle("video.y4m") as named_pipe: with encode_yuv_to_h264(named_pipe, output, **encode_options.options) as encoder: with decode_to_yuv(input, named_pipe, **decode_options.options) as decoder: if decoder_type == "mplayer": decoder_handler = MPlayerHandler else: decoder_handler = FFmpegHandler decoder_handler = decoder_handler(decoder, decode_options.status, decode_options.error) encoder_handler = X264Handler(encoder, encode_options.status, encode_options.error) asynproc.set_dependant(decoder_handler, encoder_handler) asynproc.loop()
def encode_h264(input, output, decode_options=None, encode_options=None): if decode_options is None: decode_options = OptionsBase() if encode_options is None: encode_options = OptionsBase() decode_options.options = getattr(decode_options, 'options', {}) encode_options.options = getattr(encode_options, 'options', {}) decoder_type = decode_options.options.get('type', 'ffmpeg') with sequence_as_str_repr(input, decoder_type) as input: with asynproc.fifo_handle('video.y4m') as named_pipe: with encode_yuv_to_h264(named_pipe, output, **encode_options.options) as encoder: with decode_to_yuv(input, named_pipe, **decode_options.options) as decoder: if decoder_type == 'mplayer': decoder_handler = MPlayerHandler else: decoder_handler = FFmpegHandler decoder_handler = decoder_handler(decoder, decode_options.status, decode_options.error) encoder_handler = X264Handler(encoder, encode_options.status, encode_options.error) asynproc.set_dependant(decoder_handler, encoder_handler) asynproc.loop()