Compare commits

..

No commits in common. "main" and "0.1.0" have entirely different histories.
main ... 0.1.0

View file

@ -60,22 +60,6 @@ MAX_SEGMENT_LENGTH = 9
MAX_SEGMENT_PADDING = 6 MAX_SEGMENT_PADDING = 6
def run_in_bash(
cmd: str,
capture_output=False,
check=False,
text=False,
shell=False,
):
return subprocess.run(
f"/usr/bin/bash -c '{cmd}'",
capture_output=capture_output,
check=check,
text=text,
shell=shell,
)
def nonrepeating_generator(source, desired_length): def nonrepeating_generator(source, desired_length):
""" """
Creates a generator that yields one item from `source` Creates a generator that yields one item from `source`
@ -114,7 +98,7 @@ def get_video_duration(file: Path):
logger.debug(f"Getting file length for {file}") logger.debug(f"Getting file length for {file}")
try: try:
return float( return float(
run_in_bash( subprocess.run(
f'ffprobe -v error -show_entries format=duration -of csv=p=0 "{file}"', f'ffprobe -v error -show_entries format=duration -of csv=p=0 "{file}"',
capture_output=True, capture_output=True,
check=True, check=True,
@ -148,7 +132,7 @@ def split_video_segment(
): ):
"""Splits a video into segments using ffmpeg.""" """Splits a video into segments using ffmpeg."""
logger.debug(f"Splitting {file_name} - segment {idx}") logger.debug(f"Splitting {file_name} - segment {idx}")
run_in_bash( subprocess.run(
f"ffmpeg -nostats -loglevel 0 -y -ss {seconds_to_timestamp(sum(segment_lengths[:idx]))} " f"ffmpeg -nostats -loglevel 0 -y -ss {seconds_to_timestamp(sum(segment_lengths[:idx]))} "
f'-to {seconds_to_timestamp(sum(segment_lengths[:idx]) + segment_lengths[idx])} -i "{file_name}" ' f'-to {seconds_to_timestamp(sum(segment_lengths[:idx]) + segment_lengths[idx])} -i "{file_name}" '
f'-c copy "{Path(out_dir, file_name.stem, str(idx) + file_name.suffix)}"', f'-c copy "{Path(out_dir, file_name.stem, str(idx) + file_name.suffix)}"',
@ -160,7 +144,7 @@ def split_video_segment(
def get_amplitude_of_segment(clip: Path): def get_amplitude_of_segment(clip: Path):
"""Extracts the mean audio amplitude of a video segment.""" """Extracts the mean audio amplitude of a video segment."""
logger.debug(f"Analyzing amplitude for clip: {clip}") logger.debug(f"Analyzing amplitude for clip: {clip}")
res = run_in_bash( res = subprocess.run(
f'ffmpeg -i "{Path(CACHE_DIR, clip)}" -filter:a volumedetect -f null -', f'ffmpeg -i "{Path(CACHE_DIR, clip)}" -filter:a volumedetect -f null -',
shell=True, shell=True,
check=True, check=True,
@ -246,7 +230,7 @@ def run_ffmpeg_command(
# filter so that FFmpeg knows where to map the video output. # filter so that FFmpeg knows where to map the video output.
# TODO: remove that mess and put the same logic in # TODO: remove that mess and put the same logic in
# build_transition_filters_dynamic # build_transition_filters_dynamic
run_in_bash(cmd, shell=True, check=True, capture_output=True) subprocess.run(cmd, shell=True, check=True, capture_output=True)
@cli.command() @cli.command()
@ -402,7 +386,7 @@ def run(
logger.info("Creating horizontal video...") logger.info("Creating horizontal video...")
# Horizontal Pipeline: Take unmarked file and add a semitransparent watermark. # Horizontal Pipeline: Take unmarked file and add a semitransparent watermark.
run_in_bash( subprocess.run(
f'''ffmpeg -y {decode_options} -i "{CACHE_DIR / "out-unmarked.mp4"}" -i "{watermark_image}" \ f'''ffmpeg -y {decode_options} -i "{CACHE_DIR / "out-unmarked.mp4"}" -i "{watermark_image}" \
-filter_complex " \ -filter_complex " \
[1]format=rgba,colorchannelmixer=aa=0.5[logo]; \ [1]format=rgba,colorchannelmixer=aa=0.5[logo]; \
@ -417,7 +401,7 @@ def run(
# Vertical Pipeline: Crop (zoom), split & blur unmarked file for a vertical aspect ratio, # Vertical Pipeline: Crop (zoom), split & blur unmarked file for a vertical aspect ratio,
# then overlay a centered, opaque watermark at the bottom. # then overlay a centered, opaque watermark at the bottom.
run_in_bash( subprocess.run(
f'''ffmpeg -y {decode_options} -i "{CACHE_DIR / "out-unmarked.mp4"}" -i "{watermark_image}" \ f'''ffmpeg -y {decode_options} -i "{CACHE_DIR / "out-unmarked.mp4"}" -i "{watermark_image}" \
-filter_complex " \ -filter_complex " \
[0]crop=3/4*in_w:in_h[zoomed]; \ [0]crop=3/4*in_w:in_h[zoomed]; \