def smi_to_srt(sub_path): def _detect(file_path): detector = UniversalDetector() fp = open(file_path, 'rb') for line in fp: line = line.replace(b'\r', b'') detector.feed(line) if detector.done: break fp.close() detector.close() return detector.result['encoding'] srt_path = new_temporary_file('.srt') tmp_sub_path = new_temporary_file('.smi') char_type = _detect(sub_path) context = open(sub_path, 'r', encoding=char_type, errors='ignore').read() open(tmp_sub_path, 'w', encoding='utf8').write(context) sub_path = tmp_sub_path cmd = ['/usr/local/bin/ffmpeg', '-y', '-i', sub_path, srt_path] processutil.call(cmd) return srt_path
def get_mean_volume(src): ret, out, err = processutil.call(['/usr/local/bin/ffmpeg', '-i', src, '-af', 'volumedetect', '-f', 'null', '/dev/null']) vol_info = err vol_info = vol_info[vol_info.find('mean_volume:'):] vol_info = vol_info[:vol_info.find('\n')] return float(vol_info.split(' ')[1])
def execute(self): processutil.call(self.command) return self.command[-1]
def change_container(src, container): dst = new_temporary_file(container.extension) processutil.call(['/usr/local/bin/ffmpeg', '-y', '-i', src, '-map', '0', '-c', 'copy', dst]) return dst