ffmpeg_cut_stdin: Remove cut_start and duration built-in args

Of 4 users of this function, all but one set them to None.
We're about to replace that one usage with something else, so it makes more sense
to not have them as options at all and just have the user add to the encode args manually.
pull/400/head
Mike Lang 6 months ago committed by Mike Lang
parent e7a839c6cd
commit d571bbe81e

@ -390,22 +390,18 @@ def ffmpeg_cut_segment(segment, cut_start=None, cut_end=None):
return subprocess.Popen(args, stdout=subprocess.PIPE) return subprocess.Popen(args, stdout=subprocess.PIPE)
def ffmpeg_cut_stdin(output_file, cut_start, duration, encode_args): def ffmpeg_cut_stdin(output_file, encode_args):
"""Return a Popen object which is ffmpeg cutting from stdin. """Return a Popen object which is ffmpeg cutting from stdin.
This is used when doing a full cut. This is used when doing a full cut, plus various functions for transforming segment video without doing a multi-range cut.
If output_file is not subprocess.PIPE, If output_file is not subprocess.PIPE,
uses explicit output file object instead of using a pipe, uses explicit output file object instead of using a pipe,
because some video formats require a seekable file. because some output formats require a seekable file.
""" """
args = [ args = [
'ffmpeg', 'ffmpeg',
'-hide_banner', '-loglevel', 'error', # suppress noisy output '-hide_banner', '-loglevel', 'error', # suppress noisy output
'-i', '-', '-i', '-',
] ]
if cut_start is not None:
args += ['-ss', cut_start]
if duration is not None:
args += ['-t', duration]
args += list(encode_args) args += list(encode_args)
if output_file is subprocess.PIPE: if output_file is subprocess.PIPE:
@ -422,7 +418,7 @@ def ffmpeg_cut_stdin(output_file, cut_start, duration, encode_args):
'-y', '-y',
] ]
args = list(map(str, args)) args = list(map(str, args))
logging.info("Running full cut with args: {}".format(" ".join(args))) logging.info("Cutting from stdin with args: {}".format(" ".join(args)))
return subprocess.Popen(args, stdin=subprocess.PIPE, stdout=output_file) return subprocess.Popen(args, stdin=subprocess.PIPE, stdout=output_file)
@ -639,7 +635,13 @@ def full_cut_segments(segments, start, end, encode_args, stream=False):
# has finished. We create a temporary file for this. # has finished. We create a temporary file for this.
tempfile = TemporaryFile() tempfile = TemporaryFile()
ffmpeg = ffmpeg_cut_stdin(tempfile, cut_start, duration, encode_args) args = []
if cut_start is not None:
args += ['-ss', cut_start]
if duration is not None:
args += ['-t', duration]
args += list(encode_args)
ffmpeg = ffmpeg_cut_stdin(tempfile, cut_start, duration, args)
input_feeder = gevent.spawn(feed_input, segments, ffmpeg.stdin) input_feeder = gevent.spawn(feed_input, segments, ffmpeg.stdin)
# When streaming, we can return data as it is available # When streaming, we can return data as it is available
@ -696,7 +698,7 @@ def archive_cut_segments(segment_ranges, ranges, tempdir):
try: try:
tempfile = open(tempfile_name, "wb") tempfile = open(tempfile_name, "wb")
ffmpeg = ffmpeg_cut_stdin(tempfile, None, None, encode_args) ffmpeg = ffmpeg_cut_stdin(tempfile, encode_args)
input_feeder = gevent.spawn(feed_input, segments, ffmpeg.stdin) input_feeder = gevent.spawn(feed_input, segments, ffmpeg.stdin)
# since we've now handed off the tempfile fd to ffmpeg, close ours # since we've now handed off the tempfile fd to ffmpeg, close ours
@ -752,7 +754,7 @@ def render_segments_waveform(segments, size=(1024, 128), scale='sqrt', color='#0
# output as png # output as png
'-f', 'image2', '-c', 'png', '-f', 'image2', '-c', 'png',
] ]
ffmpeg = ffmpeg_cut_stdin(subprocess.PIPE, cut_start=None, duration=None, encode_args=args) ffmpeg = ffmpeg_cut_stdin(subprocess.PIPE, args)
input_feeder = gevent.spawn(feed_input, segments, ffmpeg.stdin) input_feeder = gevent.spawn(feed_input, segments, ffmpeg.stdin)
for chunk in read_chunks(ffmpeg.stdout): for chunk in read_chunks(ffmpeg.stdout):
@ -793,12 +795,14 @@ def extract_frame(segments, timestamp):
input_feeder = None input_feeder = None
try: try:
args = [ args = [
# cut to correct start frame
"-ss", cut_start,
# get a single frame # get a single frame
'-vframes', '1', '-vframes', '1',
# output as png # output as png
'-f', 'image2', '-c', 'png', '-f', 'image2', '-c', 'png',
] ]
ffmpeg = ffmpeg_cut_stdin(subprocess.PIPE, cut_start=cut_start, duration=None, encode_args=args) ffmpeg = ffmpeg_cut_stdin(subprocess.PIPE, args)
input_feeder = gevent.spawn(feed_input, segments, ffmpeg.stdin) input_feeder = gevent.spawn(feed_input, segments, ffmpeg.stdin)
for chunk in read_chunks(ffmpeg.stdout): for chunk in read_chunks(ffmpeg.stdout):

Loading…
Cancel
Save