Merge d2fdec2f09
into d65d89183f
This commit is contained in:
commit
989cc7489f
|
@ -285,6 +285,13 @@ def _real_main(argv=None):
|
|||
postprocessors.append({
|
||||
'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:
|
||||
already_have_thumbnail = opts.writethumbnail or opts.write_all_thumbnails
|
||||
postprocessors.append({
|
||||
|
|
|
@ -858,6 +858,14 @@ def parseOpts(overrideArguments=None):
|
|||
'--convert-subs', '--convert-subtitles',
|
||||
metavar='FORMAT', dest='convertsubtitles', default=None,
|
||||
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(network)
|
||||
|
|
|
@ -3,6 +3,7 @@ from __future__ import unicode_literals
|
|||
from .embedthumbnail import EmbedThumbnailPP
|
||||
from .ffmpeg import (
|
||||
FFmpegPostProcessor,
|
||||
FFmpegCutVideoPP,
|
||||
FFmpegEmbedSubtitlePP,
|
||||
FFmpegExtractAudioPP,
|
||||
FFmpegFixupStretchedPP,
|
||||
|
@ -26,6 +27,7 @@ __all__ = [
|
|||
'EmbedThumbnailPP',
|
||||
'ExecAfterDownloadPP',
|
||||
'FFmpegEmbedSubtitlePP',
|
||||
'FFmpegCutVideoPP',
|
||||
'FFmpegExtractAudioPP',
|
||||
'FFmpegFixupM3u8PP',
|
||||
'FFmpegFixupM4aPP',
|
||||
|
|
|
@ -246,6 +246,65 @@ class FFmpegPostProcessor(PostProcessor):
|
|||
return 'file:' + fn if fn != '-' else fn
|
||||
|
||||
|
||||
class FFmpegCutVideoPP(FFmpegPostProcessor):
|
||||
def __init__(self, downloader=None, startTime=0, endTime=None):
|
||||
FFmpegPostProcessor.__init__(self, downloader)
|
||||
self._startTime = startTime
|
||||
self._endTime = endTime
|
||||
|
||||
if self._endTime and self._endTime <= self._startTime:
|
||||
raise PostProcessingError("end time smaller or equal to the start time")
|
||||
if self._endTime == 0:
|
||||
raise PostProcessingError("end time can't be zero")
|
||||
|
||||
def toTime(self, seconds):
|
||||
m, s = divmod(seconds, 60)
|
||||
h, m = divmod(m, 60)
|
||||
return "%d:%02d:%02d" % (h, m, s)
|
||||
|
||||
def run(self, information):
|
||||
if self._startTime == 0 and self._endTime == None:
|
||||
self._downloader.to_screen('[ffmpeg] No start time or end time. Keeping original')
|
||||
return [], information
|
||||
|
||||
duration = information.get('duration')
|
||||
|
||||
if self._endTime and duration and self._endTime >= duration:
|
||||
self._downloader.to_screen('WARNING: end time greater or equal to duration')
|
||||
self._endTime = None
|
||||
|
||||
options = ['-c', 'copy']
|
||||
message = '[ffmpeg] Cutting video '
|
||||
|
||||
if self._startTime:
|
||||
start = self.toTime(self._startTime)
|
||||
options.extend(['-ss', start])
|
||||
message += 'from %s ' % (start)
|
||||
if duration:
|
||||
duration -= self._startTime
|
||||
|
||||
if self._endTime:
|
||||
end = self.toTime(self._endTime)
|
||||
options.extend(['-to', end])
|
||||
message += 'to %s' % (end)
|
||||
if duration:
|
||||
duration = self._endTime - (duration - self._endTime)
|
||||
|
||||
if '-to' not in options and '-ss' not in options:
|
||||
self._downloader.to_screen('[ffmpeg] Nothing to cut. Keeping original')
|
||||
return [], information
|
||||
|
||||
path = information['filepath']
|
||||
temp_filename = prepend_extension(path, 'temp')
|
||||
self._downloader.to_screen(message)
|
||||
if duration:
|
||||
information['duration'] = duration
|
||||
self.run_ffmpeg(path, temp_filename, options)
|
||||
os.remove(encodeFilename(path))
|
||||
os.rename(encodeFilename(temp_filename), encodeFilename(path))
|
||||
return [], information
|
||||
|
||||
|
||||
class FFmpegExtractAudioPP(FFmpegPostProcessor):
|
||||
def __init__(self, downloader=None, preferredcodec=None, preferredquality=None, nopostoverwrites=False):
|
||||
FFmpegPostProcessor.__init__(self, downloader)
|
||||
|
|
Loading…
Reference in New Issue