]> jfr.im git - yt-dlp.git/commitdiff
Added --remux-video option
authorFelix Stupp <redacted>
Sat, 16 May 2020 16:09:12 +0000 (18:09 +0200)
committerFelix Stupp <redacted>
Sat, 16 May 2020 16:45:40 +0000 (18:45 +0200)
Fixes #6996

- Supported formats declared: mp4, mkv
- Added FFmpegVideoRemuxerPP as postprocessor
- Added option to README and shell-completion scripts

README.md
devscripts/fish-completion.py
devscripts/zsh-completion.in
youtube_dl/__init__.py
youtube_dl/options.py
youtube_dl/postprocessor/__init__.py
youtube_dl/postprocessor/ffmpeg.py

index 45326c69ec5bf3fa6665cca18e808a06546ce8ea..c928b7f0051412b04e987755e1dd8030a7098366 100644 (file)
--- a/README.md
+++ b/README.md
@@ -396,6 +396,10 @@ ## Post-processing Options:
                                      a value between 0 (better) and 9 (worse)
                                      for VBR or a specific bitrate like 128K
                                      (default 5)
+    --remux-video FORMAT             Remux the video to another container format
+                                     if necessary (currently supported: mp4|mkv,
+                                     target container format must support video
+                                     / audio encoding, remuxing may fail)
     --recode-video FORMAT            Encode the video to another format if
                                      necessary (currently supported:
                                      mp4|flv|ogg|webm|mkv|avi)
index 51d19dd33d3bf5c05fc86f3c63e23c00871fda90..f69c9b2323e1ca3682b8eb54102278e87c911f87 100755 (executable)
@@ -14,6 +14,7 @@
 FISH_COMPLETION_TEMPLATE = 'devscripts/fish-completion.in'
 
 EXTRA_ARGS = {
+    'remux-video': ['--arguments', 'mp4 mkv', '--exclusive'],
     'recode-video': ['--arguments', 'mp4 flv ogg webm mkv', '--exclusive'],
 
     # Options that need a file parameter
index b394a1ae7447797273cda4178de08b27ced26735..2658b3119df0f55a141e3de750b1e3d4ae64c9aa 100644 (file)
@@ -16,6 +16,8 @@ __youtube_dl() {
                 _path_files
             elif [[ ${prev} =~ ${diropts} ]]; then
                 _path_files -/
+            elif [[ ${prev} == "--remux-video" ]]; then
+                _arguments '*: :(mp4 mkv)'
             elif [[ ${prev} == "--recode-video" ]]; then
                 _arguments '*: :(mp4 flv ogg webm mkv)'
             else
index 9a659fc654d2a3af5d63e47363f8cdfdcdc0c333..838df9e5602cc466f28e4bcc71a063f7b73f0327 100644 (file)
@@ -209,6 +209,9 @@ def parse_retries(retries):
         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 parse_retries(retries):
             'preferredquality': opts.audioquality,
             'nopostoverwrites': opts.nopostoverwrites,
         })
+    if opts.remuxvideo:
+        postprocessors.append({
+            'key': 'FFmpegVideoRemuxer',
+            'preferedformat': opts.remuxvideo,
+        })
     if opts.recodevideo:
         postprocessors.append({
             'key': 'FFmpegVideoConvertor',
index 6d5ac62b3bab68de226060c6bcd3cd9299f02825..3b4125f2f4d6899c5a5845fa18c6c5dbda58c44c 100644 (file)
@@ -790,6 +790,10 @@ def _comma_separated_values_options_callback(option, opt_str, value, parser):
         '--audio-quality', metavar='QUALITY',
         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,
index 3ea5183999d5ed2adacbb05bccc6af93e8ac6750..2c470282378cbca61b29ef6e0921cde1d7d92688 100644 (file)
@@ -11,6 +11,7 @@
     FFmpegMergerPP,
     FFmpegMetadataPP,
     FFmpegVideoConvertorPP,
+    FFmpegVideoRemuxerPP,
     FFmpegSubtitlesConvertorPP,
 )
 from .xattrpp import XAttrMetadataPP
@@ -35,6 +36,7 @@ def get_postprocessor(key):
     'FFmpegPostProcessor',
     'FFmpegSubtitlesConvertorPP',
     'FFmpegVideoConvertorPP',
+    'FFmpegVideoRemuxerPP',
     'MetadataFromTitlePP',
     'XAttrMetadataPP',
 ]
index fd3f921a8a11da2e8c31573889ea4d7f5a9fea25..ab9721305dd17efa8bda692c39f53392d9f00099 100644 (file)
@@ -349,6 +349,27 @@ def run(self, information):
         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)