diff options
author | Felix Stupp <felix.stupp@outlook.com> | 2020-05-16 18:09:12 +0200 |
---|---|---|
committer | Felix Stupp <felix.stupp@outlook.com> | 2020-05-16 18:45:40 +0200 |
commit | efe87a10ae57fa74d7aa038109079a17a3c4fad2 (patch) | |
tree | 180e331360c00c8678d4fd7165780f90923fd4fc /youtube_dl | |
parent | 52c50a10af5de16165621f8929b64dc726774276 (diff) | |
download | hypervideo-pre-efe87a10ae57fa74d7aa038109079a17a3c4fad2.tar.lz hypervideo-pre-efe87a10ae57fa74d7aa038109079a17a3c4fad2.tar.xz hypervideo-pre-efe87a10ae57fa74d7aa038109079a17a3c4fad2.zip |
Added --remux-video option
Fixes #6996
- Supported formats declared: mp4, mkv
- Added FFmpegVideoRemuxerPP as postprocessor
- Added option to README and shell-completion scripts
Diffstat (limited to 'youtube_dl')
-rw-r--r-- | youtube_dl/__init__.py | 8 | ||||
-rw-r--r-- | youtube_dl/options.py | 4 | ||||
-rw-r--r-- | youtube_dl/postprocessor/__init__.py | 2 | ||||
-rw-r--r-- | youtube_dl/postprocessor/ffmpeg.py | 21 |
4 files changed, 35 insertions, 0 deletions
diff --git a/youtube_dl/__init__.py b/youtube_dl/__init__.py index 9a659fc65..838df9e56 100644 --- a/youtube_dl/__init__.py +++ b/youtube_dl/__init__.py @@ -209,6 +209,9 @@ def _real_main(argv=None): opts.audioquality = opts.audioquality.strip('k').strip('K') if not opts.audioquality.isdigit(): parser.error('invalid audio quality specified') + if opts.remuxvideo is not None: + if opts.remuxvideo not in ['mp4', 'mkv']: + parser.error('invalid video container format specified') if opts.recodevideo is not None: if opts.recodevideo not in ['mp4', 'flv', 'webm', 'ogg', 'mkv', 'avi']: parser.error('invalid video recode format specified') @@ -261,6 +264,11 @@ def _real_main(argv=None): 'preferredquality': opts.audioquality, 'nopostoverwrites': opts.nopostoverwrites, }) + if opts.remuxvideo: + postprocessors.append({ + 'key': 'FFmpegVideoRemuxer', + 'preferedformat': opts.remuxvideo, + }) if opts.recodevideo: postprocessors.append({ 'key': 'FFmpegVideoConvertor', diff --git a/youtube_dl/options.py b/youtube_dl/options.py index 6d5ac62b3..3b4125f2f 100644 --- a/youtube_dl/options.py +++ b/youtube_dl/options.py @@ -791,6 +791,10 @@ def parseOpts(overrideArguments=None): dest='audioquality', default='5', help='Specify ffmpeg/avconv audio quality, insert a value between 0 (better) and 9 (worse) for VBR or a specific bitrate like 128K (default %default)') postproc.add_option( + '--remux-video', + metavar='FORMAT', dest='remuxvideo', default=None, + help='Remux the video to another container format if necessary (currently supported: mp4|mkv, target container format must support video / audio encoding, remuxing may fail)') + postproc.add_option( '--recode-video', metavar='FORMAT', dest='recodevideo', default=None, help='Encode the video to another format if necessary (currently supported: mp4|flv|ogg|webm|mkv|avi)') diff --git a/youtube_dl/postprocessor/__init__.py b/youtube_dl/postprocessor/__init__.py index 3ea518399..2c4702823 100644 --- a/youtube_dl/postprocessor/__init__.py +++ b/youtube_dl/postprocessor/__init__.py @@ -11,6 +11,7 @@ from .ffmpeg import ( FFmpegMergerPP, FFmpegMetadataPP, FFmpegVideoConvertorPP, + FFmpegVideoRemuxerPP, FFmpegSubtitlesConvertorPP, ) from .xattrpp import XAttrMetadataPP @@ -35,6 +36,7 @@ __all__ = [ 'FFmpegPostProcessor', 'FFmpegSubtitlesConvertorPP', 'FFmpegVideoConvertorPP', + 'FFmpegVideoRemuxerPP', 'MetadataFromTitlePP', 'XAttrMetadataPP', ] diff --git a/youtube_dl/postprocessor/ffmpeg.py b/youtube_dl/postprocessor/ffmpeg.py index fd3f921a8..ab9721305 100644 --- a/youtube_dl/postprocessor/ffmpeg.py +++ b/youtube_dl/postprocessor/ffmpeg.py @@ -349,6 +349,27 @@ class FFmpegExtractAudioPP(FFmpegPostProcessor): return [path], information +class FFmpegVideoRemuxerPP(FFmpegPostProcessor): + def __init__(self, downloader=None, preferedformat=None): + super(FFmpegVideoRemuxerPP, self).__init__(downloader) + self._preferedformat = preferedformat + + def run(self, information): + path = information['filepath'] + if information['ext'] == self._preferedformat: + self._downloader.to_screen('[ffmpeg] Not remuxing video file %s - already is in target format %s' % (path, self._preferedformat)) + return [], information + options = ['-c', 'copy'] + prefix, sep, ext = path.rpartition('.') + outpath = prefix + sep + self._preferedformat + self._downloader.to_screen('[' + 'ffmpeg' + '] Remuxing 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 FFmpegVideoConvertorPP(FFmpegPostProcessor): def __init__(self, downloader=None, preferedformat=None): super(FFmpegVideoConvertorPP, self).__init__(downloader) |