mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 08:24:53 +01:00
override '_drawtext' in ffmpeg burnins
This commit is contained in:
parent
2f55d79253
commit
d23269b654
1 changed files with 35 additions and 0 deletions
|
|
@ -7,6 +7,8 @@ import tempfile
|
||||||
from string import Formatter
|
from string import Formatter
|
||||||
|
|
||||||
import opentimelineio_contrib.adapters.ffmpeg_burnins as ffmpeg_burnins
|
import opentimelineio_contrib.adapters.ffmpeg_burnins as ffmpeg_burnins
|
||||||
|
from PIL import ImageFont
|
||||||
|
|
||||||
from ayon_core.lib import (
|
from ayon_core.lib import (
|
||||||
get_ffmpeg_tool_args,
|
get_ffmpeg_tool_args,
|
||||||
get_ffmpeg_codec_args,
|
get_ffmpeg_codec_args,
|
||||||
|
|
@ -36,6 +38,39 @@ TIMECODE_KEY = "{timecode}"
|
||||||
SOURCE_TIMECODE_KEY = "{source_timecode}"
|
SOURCE_TIMECODE_KEY = "{source_timecode}"
|
||||||
|
|
||||||
|
|
||||||
|
def _drawtext(align, resolution, text, options):
|
||||||
|
"""
|
||||||
|
:rtype: {'x': int, 'y': int}
|
||||||
|
"""
|
||||||
|
x_pos = "0"
|
||||||
|
if align in (ffmpeg_burnins.TOP_CENTERED, ffmpeg_burnins.BOTTOM_CENTERED):
|
||||||
|
x_pos = "w/2-tw/2"
|
||||||
|
|
||||||
|
elif align in (ffmpeg_burnins.TOP_RIGHT, ffmpeg_burnins.BOTTOM_RIGHT):
|
||||||
|
ifont = ImageFont.truetype(options["font"], options["font_size"])
|
||||||
|
if hasattr(ifont, "getbox"):
|
||||||
|
left, top, right, bottom = ifont.getbbox(text)
|
||||||
|
box_size = right - left, bottom - top
|
||||||
|
else:
|
||||||
|
box_size = ifont.getsize(text)
|
||||||
|
x_pos = resolution[0] - (box_size[0] + options["x_offset"])
|
||||||
|
elif align in (ffmpeg_burnins.TOP_LEFT, ffmpeg_burnins.BOTTOM_LEFT):
|
||||||
|
x_pos = options["x_offset"]
|
||||||
|
|
||||||
|
if align in (
|
||||||
|
ffmpeg_burnins.TOP_CENTERED,
|
||||||
|
ffmpeg_burnins.TOP_RIGHT,
|
||||||
|
ffmpeg_burnins.TOP_LEFT
|
||||||
|
):
|
||||||
|
y_pos = "%d" % options["y_offset"]
|
||||||
|
else:
|
||||||
|
y_pos = "h-text_h-%d" % (options["y_offset"])
|
||||||
|
return {"x": x_pos, "y": y_pos}
|
||||||
|
|
||||||
|
|
||||||
|
ffmpeg_burnins._drawtext = _drawtext
|
||||||
|
|
||||||
|
|
||||||
def _get_ffprobe_data(source):
|
def _get_ffprobe_data(source):
|
||||||
"""Reimplemented from otio burnins to be able use full path to ffprobe
|
"""Reimplemented from otio burnins to be able use full path to ffprobe
|
||||||
:param str source: source media file
|
:param str source: source media file
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue