From f05d29c932a73588a09e196e70edb94383bfac96 Mon Sep 17 00:00:00 2001
From: Pierre Mdawar
Date: Wed, 6 Feb 2019 09:58:48 +0200
Subject: [PATCH] [postprocessor/ffmpeg] added option --force-recode-video to
force recoding a video
---
youtube_dl/__init__.py | 1 +
youtube_dl/options.py | 4 ++++
youtube_dl/postprocessor/ffmpeg.py | 9 ++++++---
3 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/youtube_dl/__init__.py b/youtube_dl/__init__.py
index ba435ea42..6129ae74b 100644
--- a/youtube_dl/__init__.py
+++ b/youtube_dl/__init__.py
@@ -263,6 +263,7 @@ def _real_main(argv=None):
postprocessors.append({
'key': 'FFmpegVideoConvertor',
'preferedformat': opts.recodevideo,
+ 'force_recode': opts.force_recode_video
})
# FFmpegMetadataPP should be run after FFmpegVideoConvertorPP and
# FFmpegExtractAudioPP as containers before conversion may not support
diff --git a/youtube_dl/options.py b/youtube_dl/options.py
index e7d8e8910..4e3704282 100644
--- a/youtube_dl/options.py
+++ b/youtube_dl/options.py
@@ -794,6 +794,10 @@ def parseOpts(overrideArguments=None):
'--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)')
+ postproc.add_option(
+ '--force-recode-video',
+ action='store_true', dest='force_recode_video', default=False,
+ help='Force recoding a video if it is already in the target format')
postproc.add_option(
'--postprocessor-args',
dest='postprocessor_args', metavar='ARGS',
diff --git a/youtube_dl/postprocessor/ffmpeg.py b/youtube_dl/postprocessor/ffmpeg.py
index 5bcb00ac0..7ff9d3701 100644
--- a/youtube_dl/postprocessor/ffmpeg.py
+++ b/youtube_dl/postprocessor/ffmpeg.py
@@ -350,13 +350,16 @@ class FFmpegExtractAudioPP(FFmpegPostProcessor):
class FFmpegVideoConvertorPP(FFmpegPostProcessor):
- def __init__(self, downloader=None, preferedformat=None):
+ def __init__(self, downloader=None, preferedformat=None, force_recode=False):
super(FFmpegVideoConvertorPP, self).__init__(downloader)
self._preferedformat = preferedformat
+ self._force_recode = force_recode
def run(self, information):
path = information['filepath']
- if information['ext'] == self._preferedformat:
+ if self._force_recode:
+ self._downloader.to_screen('[ffmpeg] Forcing video file recoding as %s' % (self._preferedformat))
+ if information['ext'] == self._preferedformat and not self._force_recode:
self._downloader.to_screen('[ffmpeg] Not converting video file %s - already is in target format %s' % (path, self._preferedformat))
return [], information
options = []
@@ -364,7 +367,7 @@ class FFmpegVideoConvertorPP(FFmpegPostProcessor):
options.extend(['-c:v', 'libxvid', '-vtag', 'XVID'])
prefix, sep, ext = path.rpartition('.')
outpath = prefix + sep + self._preferedformat
- self._downloader.to_screen('[' + 'ffmpeg' + '] Converting video from %s to %s, Destination: ' % (information['ext'], self._preferedformat) + outpath)
+ self._downloader.to_screen('[ffmpeg] 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