diff --git a/.vscode/settings.json b/.vscode/settings.json index ea68455..9cd63fe 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -11,6 +11,7 @@ "amix", "antiquewhite", "apad", + "asplit", "atrim", "blanchedalmond", "blueviolet", diff --git a/src/converter/content.py b/src/converter/content.py index 43263a8..03d31d0 100644 --- a/src/converter/content.py +++ b/src/converter/content.py @@ -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( @@ -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, diff --git a/src/converter/utils.py b/src/converter/utils.py index cb91eb0..66a3e72 100644 --- a/src/converter/utils.py +++ b/src/converter/utils.py @@ -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, @@ -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], }