cutter: Add support for smart cuts

pull/347/head
Mike Lang 1 year ago
parent dce0b3a5fc
commit a201a2d4c9

@ -17,7 +17,7 @@ from psycopg2 import sql
import common import common
from common.database import DBManager, query, get_column_placeholder from common.database import DBManager, query, get_column_placeholder
from common.segments import get_best_segments, fast_cut_segments, full_cut_segments, extract_frame, ContainsHoles from common.segments import get_best_segments, fast_cut_segments, full_cut_segments, smart_cut_segments, extract_frame, ContainsHoles
from common.images import compose_thumbnail_template from common.images import compose_thumbnail_template
from common.stats import timed from common.stats import timed
@ -396,11 +396,16 @@ class Cutter(object):
nonlocal upload_finished nonlocal upload_finished
try: try:
if upload_backend.encoding_settings is None: if upload_backend.encoding_settings in ("fast", "smart"):
self.logger.debug("No encoding settings, using fast cut") self.logger.debug("No encoding settings, using fast cut")
if any(transition is not None for transition in job.video_transitions): if any(transition is not None for transition in job.video_transitions):
raise ValueError("Fast cuts do not support complex transitions") raise ValueError("Fast cuts do not support complex transitions")
cut = fast_cut_segments(job.segment_ranges, job.video_ranges)
cut_fn = {
"fast": fast_cut_segments,
"smart": smart_cut_segments,
}[upload_backend.encoding_settings]
cut = cut_fn(job.segment_ranges, job.video_ranges)
else: else:
self.logger.debug("Using encoding settings for {} cut: {}".format( self.logger.debug("Using encoding settings for {} cut: {}".format(
"streamable" if upload_backend.encoding_streamable else "non-streamable", "streamable" if upload_backend.encoding_streamable else "non-streamable",
@ -934,9 +939,9 @@ def main(
else: else:
raise ValueError("Unknown upload backend type: {!r}".format(backend_type)) raise ValueError("Unknown upload backend type: {!r}".format(backend_type))
backend = backend_type(credentials, **backend_config) backend = backend_type(credentials, **backend_config)
if cut_type == 'fast': if cut_type in ('fast', 'smart'):
# mark for fast cut by clearing encoding settings # mark for the given cut type by replacing encoding settings
backend.encoding_settings = None backend.encoding_settings = cut_type
elif cut_type != 'full': elif cut_type != 'full':
raise ValueError("Unknown cut type: {!r}".format(cut_type)) raise ValueError("Unknown cut type: {!r}".format(cut_type))
upload_locations[location] = backend upload_locations[location] = backend

@ -76,8 +76,10 @@ class UploadBackend(object):
The upload backend also determines the encoding settings for the cutting The upload backend also determines the encoding settings for the cutting
process, this is given as a list of ffmpeg args process, this is given as a list of ffmpeg args
under the 'encoding_settings' attribute. under the 'encoding_settings' attribute.
If this is None, instead uses the 'fast cut' strategy where nothing If this is not a list but the string "fast", instead uses the 'fast cut' strategy where nothing
is transcoded. is transcoded.
Similarly, the string "smart" uses the 'smart cut' strategy which is a fast cut with an additional
pass to prevent timestamp issues.
In addition, if the output format doesn't need a seekable file, In addition, if the output format doesn't need a seekable file,
you should set encoding_streamable = True so we know we can stream the output directly. you should set encoding_streamable = True so we know we can stream the output directly.

Loading…
Cancel
Save