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

Commit

Permalink
update: 字幕作成処理の関数切り出し
Browse files Browse the repository at this point in the history
  • Loading branch information
PigeonsHouse committed Dec 29, 2023
1 parent 460161e commit 745be4a
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 38 deletions.
50 changes: 12 additions & 38 deletions src/converter/content.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from typing import Any, Optional

import ffmpeg

from content import SourceContent
from style import Style, TimeUnit
from utils import SourceType
Expand All @@ -10,8 +8,8 @@
audio_system_filter,
audio_volume_filter,
get_background_color_code,
get_background_process,
get_source_process,
get_text_process,
object_length_filter,
set_background_filter,
time_space_end_filter,
Expand Down Expand Up @@ -41,42 +39,18 @@ def get_process_by_source(
width_with_padding,
height_with_padding,
) = style.get_size_with_padding()
transparent_process = get_background_process(
"{}x{}".format(
width_with_padding.get_pixel(),
height_with_padding.get_pixel(),
),
video_process = get_text_process(
src_path,
width_with_padding,
height_with_padding,
style.padding_left,
style.padding_top,
style.background_color,
)
option: dict = {
"x": style.padding_left.get_pixel(),
"y": style.padding_top.get_pixel(),
}
if style.font_family is not None:
option |= {
"font": style.font_family,
}
if style.font_size is not None:
option |= {
"fontsize": style.font_size.get_pixel(),
}
if style.font_color is not None:
option |= {
"fontcolor": style.font_color.value,
}
if style.font_border_color is not None:
option |= {
"bordercolor": style.font_border_color.value,
}
if style.font_border_width is not None:
option |= {
"borderw": style.font_border_width,
}

video_process = ffmpeg.drawtext(
transparent_process,
text=src_path,
**option,
style.font_family,
style.font_size,
style.font_color,
style.font_border_color,
style.font_border_width,
)
case _:
raise Exception()
Expand Down
52 changes: 52 additions & 0 deletions src/converter/ffmpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,58 @@ def audio_merge_filter(
)


def get_text_process(
sentence: str,
width: GraphicValue,
height: GraphicValue,
padding_left: GraphicValue,
padding_top: GraphicValue,
background_color: Optional[Color],
font_family: Optional[str],
font_size: Optional[GraphicValue],
font_color: Optional[Color],
font_border_color: Optional[Color],
font_border_width: Optional[int],
) -> Any:
option: dict = {
"x": padding_left.get_pixel(),
"y": padding_top.get_pixel(),
}
transparent_process = get_background_process(
"{}x{}".format(
width.get_pixel(),
height.get_pixel(),
),
background_color,
)
if font_family is not None:
option |= {
"font": font_family,
}
if font_size is not None:
option |= {
"fontsize": font_size.get_pixel(),
}
if font_color is not None:
option |= {
"fontcolor": font_color.value,
}
if font_border_color is not None:
option |= {
"bordercolor": font_border_color.value,
}
if font_border_width is not None:
option |= {
"borderw": font_border_width,
}

return ffmpeg.drawtext(
transparent_process,
text=sentence,
**option,
)


def adjust_parallel_audio(
object_length: TimeValue,
audio_process: Any,
Expand Down

0 comments on commit 745be4a

Please sign in to comment.