|
|
@ -399,62 +399,55 @@ class FFmpegExtractAudioPP(FFmpegPostProcessor):
|
|
|
|
return [path], information
|
|
|
|
return [path], information
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FFmpegVideoRemuxerPP(FFmpegPostProcessor):
|
|
|
|
class FFmpegVideoConvertorPP(FFmpegPostProcessor):
|
|
|
|
|
|
|
|
_action = 'converting'
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, downloader=None, preferedformat=None):
|
|
|
|
def __init__(self, downloader=None, preferedformat=None):
|
|
|
|
super(FFmpegVideoRemuxerPP, self).__init__(downloader)
|
|
|
|
super(FFmpegVideoConvertorPP, self).__init__(downloader)
|
|
|
|
self._preferedformats = preferedformat.lower().split('/')
|
|
|
|
self._preferedformats = preferedformat.lower().split('/')
|
|
|
|
|
|
|
|
|
|
|
|
def run(self, information):
|
|
|
|
def _target_ext(self, source_ext):
|
|
|
|
path = information['filepath']
|
|
|
|
|
|
|
|
sourceext, targetext = information['ext'].lower(), None
|
|
|
|
|
|
|
|
for pair in self._preferedformats:
|
|
|
|
for pair in self._preferedformats:
|
|
|
|
kv = pair.split('>')
|
|
|
|
kv = pair.split('>')
|
|
|
|
if len(kv) == 1 or kv[0].strip() == sourceext:
|
|
|
|
if len(kv) == 1 or kv[0].strip() == source_ext:
|
|
|
|
targetext = kv[-1].strip()
|
|
|
|
return kv[-1].strip()
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|
|
|
def _options(target_ext):
|
|
|
|
|
|
|
|
if target_ext == 'avi':
|
|
|
|
|
|
|
|
return ['-c:v', 'libxvid', '-vtag', 'XVID']
|
|
|
|
|
|
|
|
return []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def run(self, information):
|
|
|
|
|
|
|
|
path = information['filepath']
|
|
|
|
|
|
|
|
target_ext = self._target_ext(information['ext'].lower())
|
|
|
|
_skip_msg = (
|
|
|
|
_skip_msg = (
|
|
|
|
'could not find a mapping for %s' if not targetext
|
|
|
|
'could not find a mapping for %s' if not target_ext
|
|
|
|
else 'already is in target format %s' if sourceext == targetext
|
|
|
|
else 'already is in target format %s' if source_ext == target_ext
|
|
|
|
else None)
|
|
|
|
else None)
|
|
|
|
if _skip_msg:
|
|
|
|
if _skip_msg:
|
|
|
|
self.to_screen('Not remuxing media file %s; %s' % (path, _skip_msg % sourceext))
|
|
|
|
self.to_screen('Not %s media file %s; %s' % (self._action, path, _skip_msg % source_ext))
|
|
|
|
return [], information
|
|
|
|
return [], information
|
|
|
|
|
|
|
|
|
|
|
|
options = ['-c', 'copy', '-map', '0', '-dn']
|
|
|
|
|
|
|
|
if targetext in ['mp4', 'm4a', 'mov']:
|
|
|
|
|
|
|
|
options.extend(['-movflags', '+faststart'])
|
|
|
|
|
|
|
|
prefix, sep, oldext = path.rpartition('.')
|
|
|
|
prefix, sep, oldext = path.rpartition('.')
|
|
|
|
outpath = prefix + sep + targetext
|
|
|
|
outpath = prefix + sep + target_ext
|
|
|
|
self.to_screen('Remuxing video from %s to %s; Destination: %s' % (sourceext, targetext, outpath))
|
|
|
|
self.to_screen('%s video from %s to %s; Destination: %s' % (self._action.title(), source_ext, target_ext, outpath))
|
|
|
|
self.run_ffmpeg(path, outpath, options)
|
|
|
|
self.run_ffmpeg(path, outpath, self._options(target_ext))
|
|
|
|
|
|
|
|
|
|
|
|
information['filepath'] = outpath
|
|
|
|
information['filepath'] = outpath
|
|
|
|
information['format'] = targetext
|
|
|
|
information['format'] = information['ext'] = target_ext
|
|
|
|
information['ext'] = targetext
|
|
|
|
|
|
|
|
return [path], information
|
|
|
|
return [path], information
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FFmpegVideoConvertorPP(FFmpegPostProcessor):
|
|
|
|
class FFmpegVideoRemuxerPP(FFmpegVideoConvertorPP):
|
|
|
|
def __init__(self, downloader=None, preferedformat=None):
|
|
|
|
_action = 'remuxing'
|
|
|
|
super(FFmpegVideoConvertorPP, self).__init__(downloader)
|
|
|
|
|
|
|
|
self._preferedformat = preferedformat
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def run(self, information):
|
|
|
|
@staticmethod
|
|
|
|
path = information['filepath']
|
|
|
|
def _options(target_ext):
|
|
|
|
if information['ext'] == self._preferedformat:
|
|
|
|
options = ['-c', 'copy', '-map', '0', '-dn']
|
|
|
|
self.to_screen('Not converting video file %s - already is in target format %s' % (path, self._preferedformat))
|
|
|
|
if target_ext in ['mp4', 'm4a', 'mov']:
|
|
|
|
return [], information
|
|
|
|
options.extend(['-movflags', '+faststart'])
|
|
|
|
options = []
|
|
|
|
return options
|
|
|
|
if self._preferedformat == 'avi':
|
|
|
|
|
|
|
|
options.extend(['-c:v', 'libxvid', '-vtag', 'XVID'])
|
|
|
|
|
|
|
|
prefix, sep, ext = path.rpartition('.')
|
|
|
|
|
|
|
|
outpath = prefix + sep + self._preferedformat
|
|
|
|
|
|
|
|
self.to_screen('Converting video from %s to %s, Destination: ' % (information['ext'], self._preferedformat) + outpath)
|
|
|
|
|
|
|
|
self.run_ffmpeg(path, outpath, options)
|
|
|
|
|
|
|
|
information['filepath'] = outpath
|
|
|
|
|
|
|
|
information['format'] = self._preferedformat
|
|
|
|
|
|
|
|
information['ext'] = self._preferedformat
|
|
|
|
|
|
|
|
return [path], information
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FFmpegEmbedSubtitlePP(FFmpegPostProcessor):
|
|
|
|
class FFmpegEmbedSubtitlePP(FFmpegPostProcessor):
|
|
|
|