Add FFmpegSlice postprocessor
This commit is contained in:
parent
bbd7706898
commit
215b093fdf
@ -252,6 +252,12 @@ def _real_main(argv=None):
|
||||
'preferredquality': opts.audioquality,
|
||||
'nopostoverwrites': opts.nopostoverwrites,
|
||||
})
|
||||
if opts.slicestart or opts.sliceend:
|
||||
postprocessors.append({
|
||||
'key': 'FFmpegSlice',
|
||||
'slice_start_time': opts.slicestart,
|
||||
'slice_end_time': opts.sliceend,
|
||||
})
|
||||
if opts.recodevideo:
|
||||
postprocessors.append({
|
||||
'key': 'FFmpegVideoConvertor',
|
||||
|
@ -756,6 +756,14 @@ def parseOpts(overrideArguments=None):
|
||||
'--recode-video',
|
||||
metavar='FORMAT', dest='recodevideo', default=None,
|
||||
help='Encode the video to another format if necessary (currently supported: mp4|flv|ogg|webm|mkv|avi)')
|
||||
postproc.add_option(
|
||||
'--slice-start',
|
||||
metavar='START_TIME', dest='slicestart', default=None,
|
||||
help='Slice start time')
|
||||
postproc.add_option(
|
||||
'--slice-end',
|
||||
metavar='END_TIME', dest='sliceend', default=None,
|
||||
help='Slice end time')
|
||||
postproc.add_option(
|
||||
'--postprocessor-args',
|
||||
dest='postprocessor_args', metavar='ARGS',
|
||||
|
@ -12,6 +12,7 @@ from .ffmpeg import (
|
||||
FFmpegMetadataPP,
|
||||
FFmpegVideoConvertorPP,
|
||||
FFmpegSubtitlesConvertorPP,
|
||||
FFmpegSlicePP,
|
||||
)
|
||||
from .xattrpp import XAttrMetadataPP
|
||||
from .execafterdownload import ExecAfterDownloadPP
|
||||
@ -33,6 +34,7 @@ __all__ = [
|
||||
'FFmpegMergerPP',
|
||||
'FFmpegMetadataPP',
|
||||
'FFmpegPostProcessor',
|
||||
'FFmpegSlicePP',
|
||||
'FFmpegSubtitlesConvertorPP',
|
||||
'FFmpegVideoConvertorPP',
|
||||
'MetadataFromTitlePP',
|
||||
|
@ -278,7 +278,7 @@ class FFmpegExtractAudioPP(FFmpegPostProcessor):
|
||||
|
||||
prefix, sep, ext = path.rpartition('.') # not os.path.splitext, since the latter does not work on unicode in all setups
|
||||
new_path = prefix + sep + extension
|
||||
|
||||
|
||||
information['filepath'] = new_path
|
||||
information['ext'] = extension
|
||||
|
||||
@ -577,3 +577,25 @@ class FFmpegSubtitlesConvertorPP(FFmpegPostProcessor):
|
||||
}
|
||||
|
||||
return sub_filenames, info
|
||||
|
||||
|
||||
class FFmpegSlicePP(FFmpegPostProcessor):
|
||||
|
||||
def __init__(self, downloader, slice_start_time, slice_end_time):
|
||||
super(FFmpegSlicePP, self).__init__(downloader)
|
||||
self.slice_start_time = slice_start_time
|
||||
self.slice_end_time = slice_end_time
|
||||
|
||||
def run(self, info):
|
||||
filename = info['filepath']
|
||||
temp_filename = prepend_extension(filename, 'temp')
|
||||
start_time = self.slice_start_time or "0"
|
||||
end_time = self.slice_end_time or "{}".format(info['duration'])
|
||||
options = ['-ss', start_time, '-to', end_time]
|
||||
self.run_ffmpeg(filename, temp_filename, options)
|
||||
msg = '[ffmpeg] Sliced: from ({}) seconds to ({}) seconds'.format(
|
||||
start_time, end_time)
|
||||
self._downloader.to_screen(msg)
|
||||
os.remove(encodeFilename(filename))
|
||||
os.rename(encodeFilename(temp_filename), encodeFilename(filename))
|
||||
return [], info
|
||||
|
Loading…
x
Reference in New Issue
Block a user