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 command(self): if self._command is None: self._init_command() self._add_analyze_options() self._add_infiles_options() self._add_stream_options() self._add_duration_option() self._add_framerate_options() self._command.extend(['-threads', '0', new_temporary_file(self._container.extension)]) return self._command
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