Browse Source

feat: [VP] make compiling clips into a video optional

main
Rob Hallam 2 months ago
parent
commit
c1ec2adb9f
1 changed files with 12 additions and 9 deletions
  1. +12
    -9
      pipeline/producers.py

+ 12
- 9
pipeline/producers.py View File

@@ -28,6 +28,14 @@ class VideoProducer(Producer):
class FfmpegVideoProducer(VideoProducer): class FfmpegVideoProducer(VideoProducer):
"""Produce videos using ffmpeg""" """Produce videos using ffmpeg"""
# TODO: consider output filename options # TODO: consider output filename options
_CONFIG_COMPILE_CLIPS = True

def __init__(self, features, compile_clips=_CONFIG_COMPILE_CLIPS) -> None:
if not features:
raise ValueError("No features provided")
# TODO: consider if we want to permit empty features (producing no video)
self.features = features
self._compile_clips = compile_clips


def _run_no_output(self, cmd: list, cwd:str=".") -> None: def _run_no_output(self, cmd: list, cwd:str=".") -> None:
"""Run a command and return the output as a string """Run a command and return the output as a string
@@ -36,12 +44,6 @@ class FfmpegVideoProducer(VideoProducer):
""" """
subprocess.run(cmd, stdout=None, stderr=None, cwd=cwd) subprocess.run(cmd, stdout=None, stderr=None, cwd=cwd)


def __init__(self, features):
if not features:
raise ValueError("No features provided")
# TODO: consider if we want to permit empty features (producing no video)
self.features = features

def _ffmpeg_feature_to_clip(self, feature=None, output_filepath=None): def _ffmpeg_feature_to_clip(self, feature=None, output_filepath=None):
"""use ffmpeg to produve a video clip from a feature""" """use ffmpeg to produve a video clip from a feature"""
OVERWRITE = True # TODO: consider making this a config option OVERWRITE = True # TODO: consider making this a config option
@@ -99,9 +101,10 @@ class FfmpegVideoProducer(VideoProducer):
clips.append(output_filepath) clips.append(output_filepath)


# concatenate the clips # concatenate the clips
output_filepath = f"{OUTPUT_DIR}/highlights.mp4"
self._ffmpeg_concat_clips(clips, output_filepath)
logging.info(f"Produced video: {output_filepath}")
if self._compile_clips:
output_filepath = f"{OUTPUT_DIR}/highlights.mp4"
self._ffmpeg_concat_clips(clips, output_filepath)
logging.info(f"Produced video: {output_filepath}")


class VisualisationProducer(Producer): class VisualisationProducer(Producer):
"""Visualisation producer -- illustrate the features we have extracted""" """Visualisation producer -- illustrate the features we have extracted"""


Loading…
Cancel
Save