import sys
import time
-from .utils import *
+
+from .utils import (
+ compat_subprocess_get_DEVNULL,
+ encodeFilename,
+ PostProcessingError,
+ shell_quote,
+ subtitles_filename,
+ prepend_extension,
+)
class PostProcessor(object):
files_cmd = []
for path in input_paths:
- files_cmd.extend(['-i', encodeFilename(path)])
+ files_cmd.extend(['-i', encodeFilename(path, True)])
cmd = ([self._exes['avconv'] or self._exes['ffmpeg'], '-y'] + files_cmd
+ opts +
- [encodeFilename(self._ffmpeg_filename_argument(out_path))])
+ [encodeFilename(self._ffmpeg_filename_argument(out_path), True)])
+ if self._downloader.params.get('verbose', False):
+ self._downloader.to_screen(u'[debug] ffmpeg command line: %s' % shell_quote(cmd))
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout,stderr = p.communicate()
if p.returncode != 0:
if not self._exes['ffprobe'] and not self._exes['avprobe']:
raise PostProcessingError(u'ffprobe or avprobe not found. Please install one.')
try:
- cmd = [self._exes['avprobe'] or self._exes['ffprobe'], '-show_streams', encodeFilename(self._ffmpeg_filename_argument(path))]
+ cmd = [
+ self._exes['avprobe'] or self._exes['ffprobe'],
+ '-show_streams',
+ encodeFilename(self._ffmpeg_filename_argument(path), True)]
handle = subprocess.Popen(cmd, stderr=compat_subprocess_get_DEVNULL(), stdout=subprocess.PIPE)
output = handle.communicate()[0]
if handle.wait() != 0:
extension = self._preferredcodec
more_opts = []
if self._preferredquality is not None:
- if int(self._preferredquality) < 10:
+ # The opus codec doesn't support the -aq option
+ if int(self._preferredquality) < 10 and extension != 'opus':
more_opts += [self._exes['avconv'] and '-q:a' or '-aq', self._preferredquality]
else:
more_opts += [self._exes['avconv'] and '-b:a' or '-ab', self._preferredquality + 'k']
os.rename(encodeFilename(temp_filename), encodeFilename(filename))
return True, information
+
+
+class FFmpegMetadataPP(FFmpegPostProcessor):
+ def run(self, info):
+ metadata = {}
+ if info.get('title') is not None:
+ metadata['title'] = info['title']
+ if info.get('upload_date') is not None:
+ metadata['date'] = info['upload_date']
+ if info.get('uploader') is not None:
+ metadata['artist'] = info['uploader']
+ elif info.get('uploader_id') is not None:
+ metadata['artist'] = info['uploader_id']
+
+ if not metadata:
+ self._downloader.to_screen(u'[ffmpeg] There isn\'t any metadata to add')
+ return True, info
+
+ filename = info['filepath']
+ temp_filename = prepend_extension(filename, 'temp')
+
+ options = ['-c', 'copy']
+ for (name, value) in metadata.items():
+ options.extend(['-metadata', '%s=%s' % (name, value)])
+
+ self._downloader.to_screen(u'[ffmpeg] Adding metadata to \'%s\'' % filename)
+ self.run_ffmpeg(filename, temp_filename, options)
+ os.remove(encodeFilename(filename))
+ os.rename(encodeFilename(temp_filename), encodeFilename(filename))
+ return True, info
+
+
+class FFmpegMergerPP(FFmpegPostProcessor):
+ def run(self, info):
+ filename = info['filepath']
+ args = ['-c', 'copy']
+ self.run_ffmpeg_multiple_files(info['__files_to_merge'], filename, args)
+ return True, info