aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/utils.py
diff options
context:
space:
mode:
authordirkf <fieldhouse@gmx.net>2025-11-19 20:38:14 +0000
committerdirkf <fieldhouse@gmx.net>2025-11-21 01:52:11 +0000
commit6315f4b1dfaa735f3ce07ddbcde5e1e2d3b8cef8 (patch)
treee756fccdf21656dbc3b1b7d777d466e396576bfe /youtube_dl/utils.py
parentaeb1254fcf89ea43876522371ca6d1e3c2bff25f (diff)
[utils] Support additional codecs and dynamic_range
Diffstat (limited to 'youtube_dl/utils.py')
-rw-r--r--youtube_dl/utils.py51
1 files changed, 33 insertions, 18 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py
index b93f4be5c..02a49ff49 100644
--- a/youtube_dl/utils.py
+++ b/youtube_dl/utils.py
@@ -4744,30 +4744,45 @@ def parse_codecs(codecs_str):
if not codecs_str:
return {}
split_codecs = list(filter(None, map(
- lambda str: str.strip(), codecs_str.strip().strip(',').split(','))))
- vcodec, acodec = None, None
+ lambda s: s.strip(), codecs_str.strip().split(','))))
+ vcodec, acodec, hdr = None, None, None
for full_codec in split_codecs:
- codec = full_codec.split('.')[0]
- if codec in ('avc1', 'avc2', 'avc3', 'avc4', 'vp9', 'vp8', 'hev1', 'hev2', 'h263', 'h264', 'mp4v', 'hvc1', 'av01', 'theora'):
- if not vcodec:
- vcodec = full_codec
- elif codec in ('mp4a', 'opus', 'vorbis', 'mp3', 'aac', 'ac-3', 'ec-3', 'eac3', 'dtsc', 'dtse', 'dtsh', 'dtsl'):
+ codec, rest = full_codec.partition('.')[::2]
+ codec = codec.lower()
+ full_codec = '.'.join((codec, rest)) if rest else codec
+ codec = re.sub(r'0+(?=\d)', '', codec)
+ if codec in ('avc1', 'avc2', 'avc3', 'avc4', 'vp9', 'vp8', 'hev1', 'hev2',
+ 'h263', 'h264', 'mp4v', 'hvc1', 'av1', 'theora', 'dvh1', 'dvhe'):
+ if vcodec:
+ continue
+ vcodec = full_codec
+ if codec in ('dvh1', 'dvhe'):
+ hdr = 'DV'
+ elif codec in ('av1', 'vp9'):
+ n, m = {
+ 'av1': (2, '10'),
+ 'vp9': (0, '2'),
+ }[codec]
+ if (rest.split('.', n + 1)[n:] or [''])[0].lstrip('0') == m:
+ hdr = 'HDR10'
+ elif codec in ('flac', 'mp4a', 'opus', 'vorbis', 'mp3', 'aac', 'ac-4',
+ 'ac-3', 'ec-3', 'eac3', 'dtsc', 'dtse', 'dtsh', 'dtsl'):
if not acodec:
acodec = full_codec
else:
- write_string('WARNING: Unknown codec %s\n' % full_codec, sys.stderr)
- if not vcodec and not acodec:
- if len(split_codecs) == 2:
- return {
- 'vcodec': split_codecs[0],
- 'acodec': split_codecs[1],
- }
- else:
- return {
+ write_string('WARNING: Unknown codec %s\n' % (full_codec,), sys.stderr)
+
+ return (
+ filter_dict({
'vcodec': vcodec or 'none',
'acodec': acodec or 'none',
- }
- return {}
+ 'dynamic_range': hdr,
+ }) if vcodec or acodec
+ else {
+ 'vcodec': split_codecs[0],
+ 'acodec': split_codecs[1],
+ } if len(split_codecs) == 2
+ else {})
def urlhandle_detect_ext(url_handle):