def mkcod_subtitle(path, subpath, styles, outpath): cod = utils.CommandOptionDict([ ('i', path), ('c:a', 'copy'), ('vf', vf_subtitle(subpath, styles)), ]) return cod('ffmpeg', outpath)
def mkcod_convert_to_mp4(path, outpath): if path.endswith('.ts'): return _mkcod_convert_ts_mp4(path, outpath) if path.endswith('.gif'): return _mkcod_convert_gif_mp4(path, outpath) cod = utils.CommandOptionDict([('i', path)]) return cod('ffmpeg', outpath)
def mkcod_video_poster(path, outpath, pos): cod = utils.CommandOptionDict([ ('i', path), ('ss', pos), ('vframes', 1), ]) return cod('ffmpeg', outpath)
def _mkcod_convert_ts_mp4(path, outpath): cod = utils.CommandOptionDict([ ('i', path), ('c:v', 'libx264'), ('c:a', 'copy'), ('bsf:a', 'aac_adtstoasc'), ]) return cod('ffmpeg', outpath)
def _mkcod_convert_gif_mp4(path, outpath): cod = utils.CommandOptionDict([ ('i', path), ('movflags', 'faststart'), ('pix_fmt', 'yuv420p'), ('vf', 'scale=trunc(iw/2)*2:trunc(ih/2)*2'), ('c:v', 'libx264'), ('an', []), ]) return cod('ffmpeg', outpath)
def split(self, position_pairs): position_pairs = list(position_pairs) precise = any(pair[0] % 60 for pair in position_pairs) for start, length in position_pairs: cod = utils.CommandOptionDict([ ('i', self.px), ('ss', start), ('t', length), ('c:v', 'copy'), ('c:a', 'copy'), ]) label = '.SPLIT-' + self._fmt_label(start, precise) px_out = self.px.with_suffix(label + self.px.suffix) yield cod('ffmpeg', px_out)
def mkcod_video_thumbnail(path, outpath, tspan, count=None, size=None): fps = 1 / float(tspan) cod = utils.CommandOptionDict([ ('i', path), ('vf', 'fps={}'.format(fps)), ]) if count is not None: cod['vframes'] = count if size is not None: cod['s'] = '{}x{}'.format(*size) if outpath == '-': cod['vcodec'] = 'png' cod['f'] = 'image2pipe' elif count != 1 and '%' not in str(outpath): pm, ext = os.path.splitext(outpath) outpath = pm + '.Thumb_%04d' + ext return cod('ffmpeg', outpath)
def mkcod_crop(path, outpath, head, tail, *margins): xinfo = MediaInfo(path) width = xinfo.video.width height = xinfo.video.height duration = xinfo.get_video_duration() cod = utils.CommandOptionDict([ ('i', path), ('ss', head), ('t', duration - head - tail), ('c:a', 'copy'), ]) if margins: cod['vf'] = vf_crop(width, height, *margins) else: cod['c:v'] = 'copy' return cod('ffmpeg', outpath)
def mkcod_pipe_thumbnail(path, pos, w, h): cod = utils.CommandOptionDict([('i', path), ('ss', pos), ('vframes', 1), ('vcodec', 'png'), ('f', 'image2pipe'), ('s', '{}x{}'.format(w, h))]) return cod('ffmpeg', '-')
def mkcod_convert_to_audio(path, outpath): cod = utils.CommandOptionDict([('i', path)]) if outpath.endswith('.mp3'): cod['c:a'] = 'libmp3lame' return cod('ffmpeg', outpath)
def mkcod_image_convert(path, outpath): cmd = 'convert' if sys.platform.startswith('win'): cmd = 'imagemagick' cod = utils.CommandOptionDict() return cod(cmd, path, outpath)
def mkcod_convert(path, outpath): cod = utils.CommandOptionDict([('i', path)]) return cod('ffmpeg', outpath)