diff --git a/common/common/__init__.py b/common/common/__init__.py index 3d8edb8..85529ba 100644 --- a/common/common/__init__.py +++ b/common/common/__init__.py @@ -7,7 +7,7 @@ import errno import os import random -from .segments import get_best_segments, cut_segments, parse_segment_path, SegmentInfo +from .segments import get_best_segments, fast_cut_segments, full_cut_segments, parse_segment_path, SegmentInfo from .stats import timed, PromLogCountsHandler, install_stacksampler diff --git a/common/common/segments.py b/common/common/segments.py index 950c212..ef115a6 100644 --- a/common/common/segments.py +++ b/common/common/segments.py @@ -286,18 +286,19 @@ def ffmpeg_cut_segment(segment, cut_start=None, cut_end=None): return subprocess.Popen(args, stdout=subprocess.PIPE) -def ffmpeg_cut_stdin(cut_start, cut_end, encode_args): +def ffmpeg_cut_stdin(cut_start, duration, encode_args): """Return a Popen object which is ffmpeg cutting from stdin. This is used when doing a full cut.""" args = [ 'ffmpeg', '-hide_banner', '-loglevel', 'fatal', # suppress noisy output - '-i', '-' + '-i', '-', '-ss', cut_start, - '-to', cut_end, + '-t', duration, ] + list(encode_args) + [ '-', # output to stdout ] + args = map(str, args) logging.info("Running full cut with args: {}".format(" ".join(args))) return subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE) @@ -400,13 +401,13 @@ def feed_input(segments, pipe): def full_cut_segments(segments, start, end, encode_args): # how far into the first segment to begin cut_start = max(0, (start - segments[0].start).total_seconds()) - # how much of final segment should be cut off - cut_end = max(0, (segments[-1].end - end).total_seconds()) + # duration + duration = (end - start).total_seconds() ffmpeg = None input_feeder = None try: - ffmpeg = ffmpeg_cut_stdin(cut_start, cut_end, encode_args) + ffmpeg = ffmpeg_cut_stdin(cut_start, duration, encode_args) input_feeder = gevent.spawn(feed_input, segments, ffmpeg.stdin) # stream the output until it is closed for chunk in read_chunks(ffmpeg.stdout):