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

Commit

Permalink
fix: 同名のsrcを指定したときに出力できない不具合の修正
Browse files Browse the repository at this point in the history
  • Loading branch information
PigeonsHouse committed Dec 10, 2023
1 parent 01648b5 commit 5eba15c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def __init__(
case "vid":
self.type = SourceType.VIDEO
self.exist_video = True
self.exist_audio = True
self.exist_audio = style.source_audio_system is not None
case "aud":
self.type = SourceType.AUDIO
self.exist_audio = True
Expand Down
7 changes: 3 additions & 4 deletions src/converter/content/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from content import SourceContent
from converter.schemas import Process
from converter.utils import get_background_process
from converter.utils import get_background_process, get_graphical_process
from style import GraphicUnit, TimeUnit


Expand All @@ -11,9 +11,8 @@ def create_image_process(
debug_mode: bool = False,
) -> Process:
# video_processの処理
video_process = ffmpeg.input(vsml_content.src_path, loop=1).video.filter(
"setsar", "1/1"
)
source = get_graphical_process(vsml_content.src_path, False, loop=1)
video_process = source["video"].filter("setsar", "1/1")

style = vsml_content.style
# videoのstyle対応
Expand Down
10 changes: 6 additions & 4 deletions src/converter/content/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from content import SourceContent
from converter.schemas import Process
from converter.utils import get_background_process
from converter.utils import get_background_process, get_graphical_process
from style import AudioSystem, GraphicUnit, TimeUnit
from utils import VSMLManager

Expand All @@ -14,9 +14,11 @@ def create_video_process(
debug_mode: bool = False,
) -> Process:
# sourceの取得
source = ffmpeg.input(vsml_content.src_path)
video_process = source.video
audio_process = source.audio
source = get_graphical_process(
vsml_content.src_path, vsml_content.exist_audio
)
video_process = source["video"]
audio_process = source["audio"]

style = vsml_content.style
# videoのstyle対応
Expand Down
5 changes: 4 additions & 1 deletion src/converter/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ def convert_video(

if debug_mode:
content_str = (
str(vsml_data.content).replace("'", '"').replace("True", "true")
str(vsml_data.content)
.replace("'", '"')
.replace("True", "true")
.replace("False", "false")
)
print(content_str)
content_str = json.dumps(
Expand Down
23 changes: 22 additions & 1 deletion src/converter/utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from typing import Optional
from typing import Any, Optional

import ffmpeg

from style import Color

origin_background_processes = {}
origin_graphic_processes: dict[str, dict[str, Any]] = {}


def get_background_process(
Expand Down Expand Up @@ -37,3 +38,23 @@ def get_background_process(
background_processes = origin_background_process.split()
origin_background_processes[key] = background_processes[1]
return background_processes[0]


def get_graphical_process(src_path: str, exist_audio: bool, **option):
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,
"audio": process.audio if exist_audio else None,
}
video_graphic_processes = origin_graphic_process["video"].split()
origin_graphic_processes[src_path] = {
"video": video_graphic_processes[1],
"audio": origin_graphic_process["audio"],
}
return {
"video": video_graphic_processes[0],
"audio": origin_graphic_process["audio"],
}

0 comments on commit 5eba15c

Please sign in to comment.