mirror of
https://github.com/yt-dlp/yt-dlp
synced 2024-12-26 21:59:08 +01:00
Fixed comments and added more supported formats
This commit is contained in:
parent
fc46f24dc5
commit
523c7e1d44
1 changed files with 19 additions and 8 deletions
|
@ -1047,21 +1047,32 @@ class FFmpegSplitChaptersPP(FFmpegPostProcessor):
|
||||||
['-ss', str(chapter['start_time']),
|
['-ss', str(chapter['start_time']),
|
||||||
'-t', str(chapter['end_time'] - chapter['start_time'])])
|
'-t', str(chapter['end_time'] - chapter['start_time'])])
|
||||||
|
|
||||||
|
# Extends opts with chapter specific metadata for the supported formats.
|
||||||
|
#
|
||||||
|
# Tested and supported on opus, m4a, webm and mp4.
|
||||||
|
def _set_metadata_arg(self, opts, ext, key, value):
|
||||||
|
if ext == 'opus':
|
||||||
|
# opus file requires a stream to keep title, artist etc metadata.
|
||||||
|
# FFmpegMetadataPP already set metadata and created that stream.
|
||||||
|
# Futher metadata updates should be set on the stream(:s)
|
||||||
|
# -metadata will do nothing and needs to be -metadata:s
|
||||||
|
opts.extend(['-metadata:s', f'{key}={value}'])
|
||||||
|
elif ext in ['m4a', 'webm', 'mp4']:
|
||||||
|
opts.extend(['-metadata', f'{key}={value}'])
|
||||||
|
|
||||||
# FFmpeg adds metadata about all chapters from parent file to all split m4a files.
|
# FFmpeg adds metadata about all chapters from parent file to all split m4a files.
|
||||||
# This is incorrect since there must be only single chapter in each file after split.
|
# This is incorrect since there must be only single chapter in each file after split.
|
||||||
# Such behavior confuses players who think multiple chapters present
|
# Such behavior confuses players who think multiple chapters present
|
||||||
def _set_out_opts(self, ext, chapter_title):
|
def _set_out_opts(self, ext, chapter_title, track_number):
|
||||||
out_opts = [*self.stream_copy_opts()]
|
out_opts = [*self.stream_copy_opts()]
|
||||||
out_opts.extend(['-map_metadata', '0'])
|
out_opts.extend(['-map_metadata', '0'])
|
||||||
# exclude chapters metadata but keep everything else
|
# exclude chapters metadata but keep everything else
|
||||||
out_opts.extend(['-map_chapters', '-1'])
|
out_opts.extend(['-map_chapters', '-1'])
|
||||||
if not chapter_title:
|
|
||||||
return out_opts
|
|
||||||
# replace global title with chapter specific title in split files
|
# replace global title with chapter specific title in split files
|
||||||
if ext == 'm4a':
|
if chapter_title:
|
||||||
out_opts.extend(['-metadata', 'title={}'.format(chapter_title)])
|
self._set_metadata_arg(out_opts, ext, "title", chapter_title)
|
||||||
if ext == 'opus':
|
self._set_metadata_arg(out_opts, ext, "track", track_number)
|
||||||
out_opts.extend(['-metadata:s', 'title={}'.format(chapter_title)])
|
|
||||||
return out_opts
|
return out_opts
|
||||||
|
|
||||||
@PostProcessor._restrict_to(images=False)
|
@PostProcessor._restrict_to(images=False)
|
||||||
|
@ -1078,7 +1089,7 @@ class FFmpegSplitChaptersPP(FFmpegPostProcessor):
|
||||||
self.to_screen('Splitting video by chapters; %d chapters found' % len(chapters))
|
self.to_screen('Splitting video by chapters; %d chapters found' % len(chapters))
|
||||||
for idx, chapter in enumerate(chapters):
|
for idx, chapter in enumerate(chapters):
|
||||||
destination, opts = self._ffmpeg_args_for_chapter(idx + 1, chapter, info)
|
destination, opts = self._ffmpeg_args_for_chapter(idx + 1, chapter, info)
|
||||||
out_file_opts = self._set_out_opts(info['ext'], chapter.get('title', ''))
|
out_file_opts = self._set_out_opts(info['ext'], chapter.get('title', ''), str(idx + 1))
|
||||||
self.real_run_ffmpeg([(in_file, opts)], [(destination, out_file_opts)])
|
self.real_run_ffmpeg([(in_file, opts)], [(destination, out_file_opts)])
|
||||||
if in_file != info['filepath']:
|
if in_file != info['filepath']:
|
||||||
self._delete_downloaded_files(in_file, msg=None)
|
self._delete_downloaded_files(in_file, msg=None)
|
||||||
|
|
Loading…
Reference in a new issue