wed.chaptors.base_editor module

class wed.chaptors.base_editor.BaseVideoHandler[source]

Bases: abc.ABC

static get_frame(pos: int, video_path: str = '/Users/iwasakishuto/Github/portfolio/Wed-Downtown-OP/data/materials/opening-template.mp4', as_pil: bool = False)Union[numpy.ndarray[Any, numpy.dtype[numpy.uint8]], PIL.Image.Image][source]

Get the pos-th frame in the video at video_path.

Parameters
  • pos (int) – The position of the frame to get.

  • video_path (str, optional) – Path to the video. Defaults to OPENING_TEMPLATE_PATH.

  • as_pil (bool, optional) – Whether to return in type Image.Image. Defaults to False.

Returns

pos-th frame in the video at video_path.

Return type

Union[npt.NDArray[np.uint8], Image.Image]

>>> import matplotlib.pyplot as plt
>>> from wed.chaptors import BaseVideoHandler
>>> from wed.utils import cv2plot
>>> fig = plt.figure(figsize=(18,8))
>>> for i,pos in enumerate([129,240,300,361,492], start=1):
...     ax = fig.add_subplot(2, 3, i)
...     frame = BaseVideoHandler.get_frame(pos=pos)
...     ax = cv2plot(frame=frame,ax=ax, isBGR=True)
...     ax.set_title(f"Frame No. {pos}")
>>> fig.tight_layout()
>>> fig.show()
_images/wed-chaptors-base_editor-1.png
static show_frames(start: int = 0, end: Optional[int] = None, step: int = 1, ncols: int = 6, figsize: Tuple[int, int] = (4, 3), fig: Optional[matplotlib.figure.Figure] = None)matplotlib.figure.Figure[source]

Cut out frames from the video and plot them.

Parameters
  • start (int, optional) – Draw subsequent frames from start. Defaults to 0.

  • end (Optional[int], optional) – Draw up to end-th frame. If not specified, draw to the end. Defaults to None.

  • ncols (int, optional) – Number of images lined up side by side (number of columns). Defaults to 6.

  • figsize (Tuple[int, int], optional) – Size of one image. Defaults to (4,3).

  • fig (Optional[Figure], optional) – Figure instance you want to draw in. Defaults to None.

Returns

Figure where frames from start to end are drawn.

Return type

Figure

>>> from wed.chaptors import BaseVideoHandler
>>> fig = BaseVideoHandler.show_frames(step=30, ncols=4)
>>> fig.show()
_images/wed-chaptors-base_editor-2.png
class wed.chaptors.base_editor.BaseWedOPEditor(positions: Tuple[int, int], image_paths: Dict[str, str] = {}, texts: Dict[str, str] = {})[source]

Bases: wed.chaptors.base_editor.BaseVideoHandler

Abstract Editor Class for Wednesday’s Downtown OP.

Parameters
  • positions (Tuple[int, int]) – Positions in videos assigned to this editor. (start_pos, end_pos)

  • image_paths (Dict[str,str], optional) – [description]. Defaults to {}.

  • texts (dict[str,str], optional) – [description]. Defaults to {}.

EDITOR_IDX

Number to prevent the same editor from using the same logger.

Type

int

logger

Editor assigned to this editor. An instance of logging.Logger.

Type

logging.Logger

start_pos, end_pos

Positions in videos assigned to this editor.

Type

int

duration

Duration assigned to this editor. Same as end_pos - start_pos + 1.

Type

int

EDITOR_IDX: int = 0
TOTAL_TEXT_LENGTH: int = 30
FRAME_SIZE: Tuple[int, int] = (640, 360)
FRAME_WIDTH = 640
FRAME_HEIGHT = 360
FPS: float = 30.0
property editor_name

Same as self.__class__.__name__.

set_attribute(name: str, value: str, msg: Optional[str] = None)None[source]

Set attribute to this class with logs using setattr.

Parameters
  • name (str) – An attribute name.

  • value (str) – An attribute value.

  • msg (str, optional) – Additional log message. Defaults to "".

Examples

>>> from wed.chaptors import MarqueeEditor
>>> editor = MarqueeEditor
>>> editor.set_attribute(name="hoge", value=1)
>>> hasattr(editor, "hoge")
True
>>> editor.hoge
1
set_text_attributes(**texts)None[source]

Set attributes for text.

Examples

>>> from wed.chaptors import MarqueeEditor
>>> editor = MarqueeEditor()
>>> editor.set_text_attributes(hoge_text="HOGE")
>>> hasattr(editor, "hoge_text") and hasattr(editor, "hoge_texts")
True
set_image_attributes(**image_paths)None[source]

Set attributes for images.

Raises

FileNotFoundError – When file is not found.

Examples

>>> from wed.utils import ROTATING_SQUARE_IMAGE_PATH
>>> from wed.chaptors import RotatingRectangleEditor
>>> editor = RotatingRectangleEditor()
>>> editor.set_image_attributes(hoge_image=ROTATING_SQUARE_IMAGE_PATH)
>>> hasattr(editor, "hoge_image_arr") and hasattr(editor, "hoge_image_pil")
True
set_fontcyrcler_attributes(prefix, cycler: wed.utils.generic_utils.Cycler, ttfontname, **kwargs)None[source]

[summary]

Parameters
  • prefix ([type]) – [description].

  • cycler (Cycler) – [description].

  • ttfontname ([type]) – [description].

abstract edit(frame: numpy.ndarray[Any, numpy.dtype[numpy.uint8]], pos: int)numpy.ndarray[Any, numpy.dtype[numpy.uint8]][source]

Edit the image if it is an assigned chapter (pos)

Parameters
  • frame (npt.NDArray[np.uint8]) – Current frame in the video.

  • pos (int) – Current position in the video.

Returns

Edited frame.

Return type

npt.NDArray[np.uint8]

audio_for_overlay_create()Tuple[bool, str][source]
overlayed_audio_create(video_path)str[source]
check_works(video_path: str = '/Users/iwasakishuto/Github/portfolio/Wed-Downtown-OP/data/materials/opening-template.mp4', audio_path: Optional[str] = None, out_path: Optional[str] = None, codec: str = 'H264', open: bool = True, **kwargs)str[source]

Check the editing results of this editor.

Parameters
  • video_path (str, optional) – Path to the input video. Defaults to OPENING_TEMPLATE_PATH.

  • audio_path (str, optional) – Path to the audio file. Defaults to None. (Same as video_path.)

  • out_path (Optional[str], optional) – Path to the created video. Defaults to None.

  • codec (str, optional) – Video codec for the created video. Defaults to "H264".

  • open (bool, optional) – Whether to open output file or not. Defaults to True.

Returns

Path to the created video.

Return type

str

Examples

>>> from wed.chaptors import MarqueeEditor
>>> editor = MarqueeEditor(upper_text="IWASAKI SHUTO", lower_text="INFTY")
>>> out_path = editor.check_works()
check_work(pos: int, video_path: str = '/Users/iwasakishuto/Github/portfolio/Wed-Downtown-OP/data/materials/opening-template.mp4', as_pil: bool = True)Union[numpy.ndarray[Any, numpy.dtype[numpy.uint8]], PIL.Image.Image][source]

Check the editing result for pos frame in video at video_path of this editor.

Parameters
  • pos (int) – The position in the video.

  • video_path (str, optional) – Path to the video file. Defaults to OPENING_TEMPLATE_PATH.

  • as_pil (bool, optional) – Whether to return object as Image.Image or npt.NDArray[npt.uint8]. Defaults to True.

Returns

Edutubg resykt fir the pos-th frame.

Return type

Union[npt.NDArray[np.uint8], Image.Image]

Examples

>>> import matplotlib.pyplot as plt
>>> from wed.utils import cv2plot
>>> from wed.chaptors import MarqueeEditor
>>> editor = MarqueeEditor(upper_text="IWASAKI SHUTO", lower_text="INFTY")
>>> frame = editor.check_work(pos=125, as_pil=False)
>>> fig, ax = plt.subplots()
>>> ax = cv2plot(frame, ax=ax)
>>> fig.show()
show_frames_in_charge(step: int = 1, ncols: int = 6, video_path: str = '/Users/iwasakishuto/Github/portfolio/Wed-Downtown-OP/data/materials/opening-template.mp4', figsize: Tuple[int, int] = (4, 3), fig: Optional[matplotlib.figure.Figure] = None)matplotlib.figure.Figure[source]

Cut out frames from the video and plot them.

Parameters
  • ncols (int, optional) – Number of images lined up side by side (number of columns). Defaults to 6.

  • video_path (str, optional) – Path to video. Defaults to OPENING_TEMPLATE_PATH.

  • figsize (Tuple[int, int], optional) – Size of one image. Defaults to (4,3).

  • fig (Optional[Figure], optional) – Figure instance you want to draw in. Defaults to None.

Returns

Figure where frames from start to end are drawn.

Return type

Figure

>>> from wed.chaptors import BaseVideoHandler
>>> fig = BaseVideoHandler.show_frames(step=30, ncols=4)
>>> fig.show()
_images/wed-chaptors-base_editor-3.png