Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/yt-dlp/yt-dlp into ytdlp
Browse files Browse the repository at this point in the history
* 'master' of https://github.com/yt-dlp/yt-dlp:
  [cleanup, docs] Minor fixes
  [ffmpeg] Standardize use of `-map 0`
  [CeskaTelevize] Use `http` for manifests
  • Loading branch information
Lesmiscore committed Jan 12, 2022
2 parents fea3a08 + ed8d87f commit 67b460a
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 35 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1501,10 +1501,10 @@ The available fields are:

- `hasvid`: Gives priority to formats that has a video stream
- `hasaud`: Gives priority to formats that has a audio stream
- `ie_pref`: The format preference as given by the extractor
- `lang`: Language preference as given by the extractor
- `quality`: The quality of the format as given by the extractor
- `source`: Preference of the source as given by the extractor
- `ie_pref`: The format preference
- `lang`: The language preference
- `quality`: The quality of the format
- `source`: The preference of the source
- `proto`: Protocol used for download (`m3u8_native`/`m3u8` > `https`/`ftps` > `http`/`ftp` > `http_dash_segments`> `websocket_frag` > `mms`/`rtsp` > `f4f`/`f4m`)
- `vcodec`: Video Codec (`av01` > `vp9.2` > `vp9` > `h265` > `h264` > `vp8` > `h263` > `theora` > other)
- `acodec`: Audio Codec (`flac`/`alac` > `wav`/`aiff` > `opus` > `vorbis` > `aac` > `mp4a` > `mp3` > `eac3` > `ac3` > `dts` > other)
Expand Down Expand Up @@ -1809,7 +1809,7 @@ with YoutubeDL(ydl_opts) as ydl:
ydl.download(['https://www.youtube.com/watch?v=BaW_jenozKc'])
```

Most likely, you'll want to use various options. For a list of options available, have a look at [`yt_dlp/YoutubeDL.py`](yt_dlp/YoutubeDL.py#L162).
Most likely, you'll want to use various options. For a list of options available, have a look at [`yt_dlp/YoutubeDL.py`](yt_dlp/YoutubeDL.py#L191).

Here's a more complete example demonstrating various functionality:

Expand Down
4 changes: 2 additions & 2 deletions yt_dlp/YoutubeDL.py
Original file line number Diff line number Diff line change
Expand Up @@ -1721,7 +1721,7 @@ def iter_playlistitems(format):

ie_entries = ie_result['entries']
if isinstance(ie_entries, list):
playlist_count = len(ie_result)
playlist_count = len(ie_entries)
msg = f'Collected {playlist_count} videos; downloading %d of them'
ie_result['playlist_count'] = ie_result.get('playlist_count') or playlist_count

Expand Down Expand Up @@ -2501,7 +2501,7 @@ def sanitize_numeric_fields(info):
if not self.params.get('allow_unplayable_formats'):
formats = [f for f in formats if not f.get('has_drm')]

# backward compatibility, or for backing up original title modified below
# backward compatibility
info_dict['fulltitle'] = info_dict['title']

if info_dict.get('is_live'):
Expand Down
1 change: 1 addition & 0 deletions yt_dlp/extractor/ceskatelevize.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ def _real_extract(self, url):
is_live = item.get('type') == 'LIVE'
formats = []
for format_id, stream_url in item.get('streamUrls', {}).items():
stream_url = stream_url.replace('https://', 'http://')
if 'playerType=flash' in stream_url:
stream_formats = self._extract_m3u8_formats(
stream_url, playlist_id, 'mp4', 'm3u8_native',
Expand Down
3 changes: 2 additions & 1 deletion yt_dlp/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ def _dict_from_options_callback(
action='store_true', dest='ignoreconfig',
help=(
'Don\'t load any more configuration files except those given by --config-locations. '
'For backward compatibility, if this option is found inside the system configuration file, the user configuration is not loaded'))
'For backward compatibility, if this option is found inside the system configuration file, the user configuration is not loaded. '
'(Alias: --no-config'))
general.add_option(
'--no-config-locations',
action='store_const', dest='config_locations', const=[],
Expand Down
4 changes: 2 additions & 2 deletions yt_dlp/postprocessor/embedthumbnail.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def run(self, info):
self.run_ffmpeg_multiple_files([filename, thumbnail_filename], temp_filename, options)

elif info['ext'] in ['mkv', 'mka']:
options = ['-c', 'copy', '-map', '0', '-dn']
options = list(self.stream_copy_opts())

mimetype = 'image/%s' % ('png' if thumbnail_ext == 'png' else 'jpeg')
old_stream, new_stream = self.get_stream_number(
Expand Down Expand Up @@ -184,7 +184,7 @@ def run(self, info):
if not success:
success = True
try:
options = ['-c', 'copy', '-map', '0', '-dn', '-map', '1']
options = [*self.stream_copy_opts(), '-map', '1']

old_stream, new_stream = self.get_stream_number(
filename, ('disposition', 'attached_pic'), 1)
Expand Down
52 changes: 28 additions & 24 deletions yt_dlp/postprocessor/ffmpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from ..compat import compat_str
from ..utils import (
determine_ext,
dfxp2srt,
encodeArgument,
encodeFilename,
Expand Down Expand Up @@ -213,6 +214,18 @@ def probe_available(self):
def probe_executable(self):
return self._paths[self.probe_basename]

@staticmethod
def stream_copy_opts(copy=True, *, ext=None):
yield from ('-map', '0')
# Don't copy Apple TV chapters track, bin_data
# See https://github.com/yt-dlp/yt-dlp/issues/2, #19042, #19024, https://trac.ffmpeg.org/ticket/6016
yield '-dn'
if copy:
yield from ('-c', 'copy')
# For some reason, '-c copy -map 0' is not enough to copy subtitles
if ext in ('mp4', 'mov'):
yield from ('-c:s', 'mov_text')

def get_audio_codec(self, path):
if not self.probe_available and not self.available:
raise PostProcessingError('ffprobe and ffmpeg not found. Please install or provide the path using --ffmpeg-location')
Expand Down Expand Up @@ -410,8 +423,9 @@ def force_keyframes(self, filename, timestamps):
timestamps = timestamps[1:]
keyframe_file = prepend_extension(filename, 'keyframes.temp')
self.to_screen(f'Re-encoding "{filename}" with appropriate keyframes')
self.run_ffmpeg(filename, keyframe_file, ['-force_key_frames', ','.join(
f'{t:.6f}' for t in timestamps)])
self.run_ffmpeg(filename, keyframe_file, [
*self.stream_copy_opts(False, ext=determine_ext(filename)),
'-force_key_frames', ','.join(f'{t:.6f}' for t in timestamps)])
return keyframe_file

def concat_files(self, in_files, out_file, concat_opts=None):
Expand All @@ -426,10 +440,7 @@ def concat_files(self, in_files, out_file, concat_opts=None):
with open(concat_file, 'wt', encoding='utf-8') as f:
f.writelines(self._concat_spec(in_files, concat_opts))

out_flags = ['-c', 'copy']
if out_file.rpartition('.')[-1] in ('mp4', 'mov'):
# For some reason, '-c copy' is not enough to copy subtitles
out_flags.extend(['-c:s', 'mov_text'])
out_flags = list(self.stream_copy_opts(ext=determine_ext(out_file)))

try:
self.real_run_ffmpeg(
Expand Down Expand Up @@ -640,7 +651,7 @@ class FFmpegVideoRemuxerPP(FFmpegVideoConvertorPP):

@staticmethod
def _options(target_ext):
return ['-c', 'copy', '-map', '0', '-dn']
return FFmpegPostProcessor.stream_copy_opts()


class FFmpegEmbedSubtitlePP(FFmpegPostProcessor):
Expand Down Expand Up @@ -702,16 +713,11 @@ def run(self, info):
input_files = [filename] + sub_filenames

opts = [
'-c', 'copy', '-map', '0', '-dn',
*self.stream_copy_opts(ext=info['ext']),
# Don't copy the existing subtitles, we may be running the
# postprocessor a second time
'-map', '-0:s',
# Don't copy Apple TV chapters track, bin_data (see #19042, #19024,
# https://trac.ffmpeg.org/ticket/6016)
'-map', '-0:d',
]
if info['ext'] == 'mp4':
opts += ['-c:s', 'mov_text']
for i, (lang, name) in enumerate(zip(sub_langs, sub_names)):
opts.extend(['-map', '%d:0' % (i + 1)])
lang_code = ISO639Utils.short2long(lang) or lang
Expand Down Expand Up @@ -740,11 +746,10 @@ def __init__(self, downloader, add_metadata=True, add_chapters=True, add_infojso

@staticmethod
def _options(target_ext):
yield from ('-map', '0', '-dn')
if target_ext == 'm4a':
audio_only = target_ext == 'm4a'
yield from FFmpegPostProcessor.stream_copy_opts(not audio_only)
if audio_only:
yield from ('-vn', '-acodec', 'copy')
else:
yield from ('-c', 'copy')

@PostProcessor._restrict_to(images=False)
def run(self, info):
Expand Down Expand Up @@ -932,16 +937,15 @@ def run(self, info):
stretched_ratio = info.get('stretched_ratio')
if stretched_ratio not in (None, 1):
self._fixup('Fixing aspect ratio', info['filepath'], [
'-c', 'copy', '-map', '0', '-dn', '-aspect', '%f' % stretched_ratio])
*self.stream_copy_opts(), '-aspect', '%f' % stretched_ratio])
return [], info


class FFmpegFixupM4aPP(FFmpegFixupPostProcessor):
@PostProcessor._restrict_to(images=False, video=False)
def run(self, info):
if info.get('container') == 'm4a_dash':
self._fixup('Correcting container', info['filepath'], [
'-c', 'copy', '-map', '0', '-dn', '-f', 'mp4'])
self._fixup('Correcting container', info['filepath'], [*self.stream_copy_opts(), '-f', 'mp4'])
return [], info


Expand All @@ -961,7 +965,7 @@ def _needs_fixup(self, info):
def run(self, info):
if all(self._needs_fixup(info)):
self._fixup('Fixing MPEG-TS in MP4 container', info['filepath'], [
'-c', 'copy', '-map', '0', '-dn', '-f', 'mp4', '-bsf:a', 'aac_adtstoasc'])
*self.stream_copy_opts(), '-f', 'mp4', '-bsf:a', 'aac_adtstoasc'])
return [], info


Expand All @@ -982,7 +986,7 @@ def run(self, info):
opts = ['-vf', 'setpts=PTS-STARTPTS']
else:
opts = ['-c', 'copy', '-bsf', 'setts=ts=TS-STARTPTS']
self._fixup('Fixing frame timestamp', info['filepath'], opts + ['-map', '0', '-dn', '-ss', self.trim])
self._fixup('Fixing frame timestamp', info['filepath'], opts + [*self.stream_copy_opts(False), '-ss', self.trim])
return [], info


Expand All @@ -991,7 +995,7 @@ class FFmpegCopyStreamPostProcessor(FFmpegFixupPostProcessor):

@PostProcessor._restrict_to(images=False)
def run(self, info):
self._fixup(self.MESSAGE, info['filepath'], ['-c', 'copy', '-map', '0', '-dn'])
self._fixup(self.MESSAGE, info['filepath'], self.stream_copy_opts())
return [], info


Expand Down Expand Up @@ -1119,7 +1123,7 @@ def run(self, info):
self.to_screen('Splitting video by chapters; %d chapters found' % len(chapters))
for idx, chapter in enumerate(chapters):
destination, opts = self._ffmpeg_args_for_chapter(idx + 1, chapter, info)
self.real_run_ffmpeg([(in_file, opts)], [(destination, ['-c', 'copy'])])
self.real_run_ffmpeg([(in_file, opts)], [(destination, self.stream_copy_opts())])
if in_file != info['filepath']:
os.remove(in_file)
return [], info
Expand Down
3 changes: 2 additions & 1 deletion yt_dlp/postprocessor/modify_chapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def run(self, info):
self.write_debug('Expected and actual durations mismatch')

concat_opts = self._make_concat_opts(cuts, real_duration)
self.write_debug('Concat spec = %s' % ', '.join(f'{c.get("inpoint", 0.0)}-{c.get("outpoint", "inf")}' for c in concat_opts))

def remove_chapters(file, is_sub):
return file, self.remove_chapters(file, cuts, concat_opts, self._force_keyframes and not is_sub)
Expand Down Expand Up @@ -332,6 +333,6 @@ def _make_concat_opts(chapters_to_remove, duration):
continue
opts[-1]['outpoint'] = f'{s["start_time"]:.6f}'
# Do not create 0 duration chunk at the end.
if s['end_time'] != duration:
if s['end_time'] < duration:
opts.append({'inpoint': f'{s["end_time"]:.6f}'})
return opts

0 comments on commit 67b460a

Please sign in to comment.