Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sorting Video Formats #25959

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added --remux-video by Zocker1999NET (#7)
  • Loading branch information
pukkandan committed Sep 21, 2020
commit a0c3b7aef922ffb78d7d0029247cff812ef78d04
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,10 @@ Alternatively, refer to the [developer instructions](#developer-instructions) fo
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)
Expand Down
1 change: 1 addition & 0 deletions devscripts/fish-completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions devscripts/zsh-completion.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions youtube_dl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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',
Expand Down
4 changes: 4 additions & 0 deletions youtube_dl/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,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,
Expand Down
2 changes: 2 additions & 0 deletions youtube_dl/postprocessor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
FFmpegMergerPP,
FFmpegMetadataPP,
FFmpegVideoConvertorPP,
FFmpegVideoRemuxerPP,
FFmpegSubtitlesConvertorPP,
)
from .xattrpp import XAttrMetadataPP
Expand All @@ -35,6 +36,7 @@ def get_postprocessor(key):
'FFmpegPostProcessor',
'FFmpegSubtitlesConvertorPP',
'FFmpegVideoConvertorPP',
'FFmpegVideoRemuxerPP',
'MetadataFromTitlePP',
'XAttrMetadataPP',
]
21 changes: 21 additions & 0 deletions youtube_dl/postprocessor/ffmpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down