def run_ffmpeg_multiple_files(self, input_paths, out_path, opts): self.check_version() oldest_mtime = min( os.stat(encodeFilename(path)).st_mtime for path in input_paths) # opts += self._configuration_args() -- postprocessor_args files_cmd = [] for path in input_paths: files_cmd.extend([ encodeArgument('-i'), encodeFilename(self._ffmpeg_filename_argument(path), True) ]) cmd = ( [encodeFilename(self.executable, True), encodeArgument('-y')] + files_cmd + [encodeArgument(o) for o in opts] + [encodeFilename(self._ffmpeg_filename_argument(out_path), True)]) # if self._downloader.params.get('verbose', False): self.logger.debug('[debug] ffmpeg command line: %s' % shell_quote(cmd)) p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) stdout, stderr = p.communicate() if p.returncode != 0: stderr = stderr.decode('utf-8', 'replace') msg = stderr.strip().split('\n')[-1] raise SaneFFmpegPostProcessorError(msg) self.try_utime(out_path, oldest_mtime, oldest_mtime)
def get_audio_codec(self, path): if not self.probe_available: raise PostProcessingError( 'ffprobe or avprobe not found. Please install one.') try: cmd = [ encodeFilename(self.probe_executable, True), encodeArgument('-show_streams'), encodeFilename(self._ffmpeg_filename_argument(path), True) ] # if self._downloader.params.get('verbose', False): self.logger.debug('%s command line: %s' % (self.basename, shell_quote(cmd))) handle = subprocess.Popen(cmd, stderr=compat_subprocess_get_DEVNULL(), stdout=subprocess.PIPE, stdin=subprocess.PIPE) output = handle.communicate()[0] if handle.wait() != 0: return None except (IOError, OSError): return None audio_codec = None for line in output.decode('ascii', 'ignore').split('\n'): if line.startswith('codec_name='): audio_codec = line.split('=')[1].strip() elif line.strip( ) == 'codec_type=audio' and audio_codec is not None: return audio_codec return None
def test_cmdline_umlauts(self): p = subprocess.Popen([ sys.executable, 'youtube_dl/__main__.py', encodeArgument('ä'), '--version' ], cwd=rootDir, stdout=_DEV_NULL, stderr=subprocess.PIPE) _, stderr = p.communicate() self.assertFalse(stderr)
def run_ffmpeg_multiple_files(self, input_paths, out_path, opts, opts_before=[]): self.check_version() # sanitize file path out_path = pathvalidate.sanitize_filepath(out_path) oldest_mtime = min( os.stat(encodeFilename(path)).st_mtime for path in input_paths) opts += self._configuration_args() files_cmd = [] for path in input_paths: files_cmd.extend([ encodeArgument('-i'), encodeFilename(self._ffmpeg_filename_argument(path), True) ]) cmd = [ encodeFilename(self.executable, True), encodeArgument('-y'), ] # without -y there is a error callen, if the file exists if self.basename == 'ffmpeg': cmd += [encodeArgument('-loglevel'), encodeArgument('repeat+info')] cmd += ( [encodeArgument(o) for o in opts_before] + files_cmd + [encodeArgument(o) for o in opts] + [encodeFilename(self._ffmpeg_filename_argument(out_path), True)]) if self._downloader.params.get('verbose', False): self._downloader.to_screen('[debug] ffmpeg command line: %s' % shell_quote(cmd)) p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, universal_newlines=True) last_line = '' for line in p.stderr: # line = line.decode('utf-8', 'replace') if line.find('time=') > 0: print('\033[K' + line.replace('\n', '') + '\r', end='') last_line = line print('') std_out, std_err = p.communicate() if p.returncode != 0: msg = last_line.strip().split('\n')[-1] raise FFmpegPostProcessorError(msg) self.try_utime(out_path, oldest_mtime, oldest_mtime)
def test_cmdline_umlauts(self): p = subprocess.Popen( [sys.executable, 'youtube_dl/__main__.py', encodeArgument('ä'), '--version'], cwd=rootDir, stdout=_DEV_NULL, stderr=subprocess.PIPE) _, stderr = p.communicate() self.assertFalse(stderr)