1
0
mirror of https://github.com/ytdl-org/youtube-dl.git synced 2025-07-11 04:46:21 +00:00

Added options to __init__.py and took into acount the possibility of not havin duration

Signed-off-by: Marcos Alfredo Núñez <mnunez@fleni.org.ar>
This commit is contained in:
Marcos Alfredo Núñez 2018-03-12 13:29:01 -03:00
parent e6d2a3aa32
commit afc763ee2e
3 changed files with 34 additions and 12 deletions

View File

@ -283,6 +283,13 @@ def _real_main(argv=None):
postprocessors.append({ postprocessors.append({
'key': 'FFmpegEmbedSubtitle', 'key': 'FFmpegEmbedSubtitle',
}) })
if opts.starttime or opts.endtime:
d = {'key': 'FFmpegCutVideo'}
if opts.starttime:
d['startTime'] = int(opts.starttime)
if opts.endtime:
d['endTime'] = int(opts.endtime)
postprocessors.append(d)
if opts.embedthumbnail: if opts.embedthumbnail:
already_have_thumbnail = opts.writethumbnail or opts.write_all_thumbnails already_have_thumbnail = opts.writethumbnail or opts.write_all_thumbnails
postprocessors.append({ postprocessors.append({

View File

@ -853,6 +853,14 @@ def parseOpts(overrideArguments=None):
'--convert-subs', '--convert-subtitles', '--convert-subs', '--convert-subtitles',
metavar='FORMAT', dest='convertsubtitles', default=None, metavar='FORMAT', dest='convertsubtitles', default=None,
help='Convert the subtitles to other format (currently supported: srt|ass|vtt|lrc)') help='Convert the subtitles to other format (currently supported: srt|ass|vtt|lrc)')
postproc.add_option(
'--start-time',
metavar='TIME', dest='starttime', default=None,
help='Cuts the video/audio starting at start-time')
postproc.add_option(
'--end-time',
metavar='TIME', dest='endtime', default=None,
help='Cuts the vidoe/audio up to end-time')
parser.add_option_group(general) parser.add_option_group(general)
parser.add_option_group(network) parser.add_option_group(network)

View File

@ -227,16 +227,20 @@ class FFmpegCutVideoPP(FFmpegPostProcessor):
return "%d:%02d:%02d" % (h, m, s) return "%d:%02d:%02d" % (h, m, s)
def run(self, information): def run(self, information):
if not self._startTime and not self._endTime: if self._startTime == 0 and self._endTime == None:
self._downloader.to_screen('[ffmpeg] No startTime or endTime. Keeping original') self._downloader.to_screen('[ffmpeg] No start time or end time. Keeping original')
return [], information return [], information
if self._endTime <= self._startTime: if self._endTime and self._endTime <= self._startTime:
raise PostProcessingError("WARNING: endTime smaller than startTime") raise PostProcessingError("end time smaller or equal to the start time")
duration = information['duration'] if self._endTime == 0:
if self._endTime and self._endTime > duration: raise PostProcessingError("end time can't be zero")
self._downloader.to_screen('WARNING: endTime greater than video duration')
duration = information.get('duration')
if self._endTime and duration and self._endTime >= duration:
self._downloader.to_screen('WARNING: end time greater than video duration')
self._endTime = None self._endTime = None
options = ['-c', 'copy'] options = ['-c', 'copy']
@ -246,12 +250,14 @@ class FFmpegCutVideoPP(FFmpegPostProcessor):
start = self.toTime(self._startTime) start = self.toTime(self._startTime)
options.extend(['-ss', start]) options.extend(['-ss', start])
message += 'from %s ' % (start) message += 'from %s ' % (start)
if duration:
duration -= self._startTime duration -= self._startTime
if self._endTime and self._endTime < duration: if self._endTime:
end = self.toTime(self._endTime) end = self.toTime(self._endTime)
options.extend(['-to', end]) options.extend(['-to', end])
message += 'to %s' % (end) message += 'to %s' % (end)
if duration:
duration -= self._endTime duration -= self._endTime
if '-to' not in options and '-ss' not in options: if '-to' not in options and '-ss' not in options:
@ -261,6 +267,7 @@ class FFmpegCutVideoPP(FFmpegPostProcessor):
path = information['filepath'] path = information['filepath']
temp_filename = prepend_extension(path, 'temp') temp_filename = prepend_extension(path, 'temp')
self._downloader.to_screen(message) self._downloader.to_screen(message)
if duration:
information['duration'] = duration information['duration'] = duration
self.run_ffmpeg(path, temp_filename, options) self.run_ffmpeg(path, temp_filename, options)
os.remove(encodeFilename(path)) os.remove(encodeFilename(path))