Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disabled transitions if the transition duration is too short. #222

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions augly/video/augmenters/ffmpeg/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,28 @@ def __init__(
)
self.transition = transition

def _create_null_transition_filters(
self,
video_streams: List[str],
audio_streams: List[str],
) -> List[str]:
# Interleave the video and audio streams.
all_streams = [v for pair in zip(video_streams, audio_streams) for v in pair]
filters = [
f"{''.join(all_streams)}concat=n={len(self.video_paths)}:v=1:a=1[v][a]"
]
return filters

def _create_transition_filters(
self,
video_streams: List[str],
audio_streams: List[str],
out_video: str = "[v]",
out_audio: str = "[a]",
) -> List[str]:
assert self.transition is not None, "Transition cannot be None here."
if self.transition is None:
return self._create_null_transition_filters(video_streams, audio_streams)

transition = self.transition
effect = transition.effect.name.lower()

Expand All @@ -107,6 +121,12 @@ def _create_transition_filters(
if td > min(video_durations):
# Decrease transition duration (with padding) to prevent hung ffmpeg calls.
new_td = max(0, min(video_durations) - 0.1)
if new_td < 0.5:
log.warn("Disabling transitions due to low duration: %f", new_td)
return self._create_null_transition_filters(
video_streams, audio_streams
)

log.info(
f"Transition duration {td} > {min(video_durations)}. Decreasing to {new_td}."
)
Expand Down Expand Up @@ -172,16 +192,7 @@ def get_command(self, video_path: str, output_path: str) -> List[str]:
video_streams.append(f"[{i}vf]")
audio_streams.append(f"[{i}:a]")

# Interleave the video and audio streams.
if self.transition is None:
all_streams = [
v for pair in zip(video_streams, audio_streams) for v in pair
]
filters += [
f"{''.join(all_streams)}concat=n={len(self.video_paths)}:v=1:a=1[v][a]"
]
else:
filters += self._create_transition_filters(video_streams, audio_streams)
filters += self._create_transition_filters(video_streams, audio_streams)

return [
"-y",
Expand Down