Skip to content
This repository has been archived by the owner on Jul 6, 2024. It is now read-only.

Commit

Permalink
update: audioも同じinputを受けた時splitで保持するよう更新
Browse files Browse the repository at this point in the history
  • Loading branch information
PigeonsHouse committed Dec 29, 2023
1 parent 1e5d94b commit 40f3941
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"amix",
"antiquewhite",
"apad",
"asplit",
"atrim",
"blanchedalmond",
"blueviolet",
Expand Down
8 changes: 4 additions & 4 deletions src/converter/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
time_space_start_filter,
width_height_filter,
)
from .utils import get_background_process, get_graphical_process
from .utils import get_background_process, get_source_process


def get_process_by_source(
Expand All @@ -27,14 +27,14 @@ def get_process_by_source(
audio_process = None
match type:
case SourceType.IMAGE:
source = get_graphical_process(src_path, False, loop=1)
source = get_source_process(src_path, True, False, loop=1)
video_process = source["video"].filter("setsar", "1/1")
case SourceType.VIDEO:
source = get_graphical_process(src_path, exist_audio)
source = get_source_process(src_path, True, exist_audio)
video_process = source["video"]
audio_process = source["audio"]
case SourceType.AUDIO:
audio_process = ffmpeg.input(src_path).audio
audio_process = get_source_process(src_path, False, True)["audio"]
case SourceType.TEXT:
(
width_with_padding,
Expand Down
23 changes: 17 additions & 6 deletions src/converter/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

def get_background_process(
resolution_text: str, background_color: Optional[Color] = None
):
) -> Any:
global origin_background_process
key = "{}/{}".format(
resolution_text,
Expand Down Expand Up @@ -40,21 +40,32 @@ def get_background_process(
return background_processes[0]


def get_graphical_process(src_path: str, exist_audio: bool, **option):
def get_source_process(
src_path: str, exist_video: bool, exist_audio: bool, **option
) -> dict[str, Any]:
global origin_graphic_processes
origin_graphic_process = origin_graphic_processes.get(src_path)
if origin_graphic_process is None:
process = ffmpeg.input(src_path, **option)
origin_graphic_process = {
"video": process.video,
"video": process.video if exist_video else None,
"audio": process.audio if exist_audio else None,
}
video_graphic_processes = origin_graphic_process["video"].split()
video_graphic_processes = (
origin_graphic_process["video"].split()
if origin_graphic_process["video"] is not None
else (None, None)
)
audio_graphic_processes = (
origin_graphic_process["audio"].asplit()
if origin_graphic_process["audio"] is not None
else (None, None)
)
origin_graphic_processes[src_path] = {
"video": video_graphic_processes[1],
"audio": origin_graphic_process["audio"],
"audio": audio_graphic_processes[1],
}
return {
"video": video_graphic_processes[0],
"audio": origin_graphic_process["audio"],
"audio": audio_graphic_processes[0],
}

0 comments on commit 40f3941

Please sign in to comment.