veditor.elements.base module¶
- class veditor.elements.base.BaseElement(pos_frames: Tuple[int, Optional[int]] = (0, None))[source]¶
Bases:
abc.ABC
- ELEMENT_IDX: int = 0¶
- property element_name: str¶
- property bottom: int¶
- property right: int¶
- property locations: Tuple[int, int, int, int]¶
- property trbl: Tuple[int, int, int, int]¶
- 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 veditor.chaptors import MarqueeEditor >>> editor = MarqueeEditor >>> editor.set_attribute(name="hoge", value=1) >>> hasattr(editor, "hoge") True >>> editor.hoge 1
- abstract edit(frame: numpy.ndarray[Any, numpy.dtype[numpy.uint8]], pos: int, **kwargs) → numpy.ndarray[Any, numpy.dtype[numpy.uint8]][source]¶
Edit a
pos
-th frame.- Parameters
frame (npt.NDArray[np.uint8]) – The current frame (BGR image) (in the video)
pos (int) – The current position (in the video)
- Returns
An editied frame.
- Return type
npt.NDArray[np.uint8]
- overlay_audio(base_media_path: str, frame_rate: float) → str[source]¶
Overlay audio if this
element
has its own audio.- Parameters
base_media_path (str) – The path to media file (contains audio) to be overlayed.
frame_rate (float) – The frame rate for the media at
base_media_path
.
- Returns
The path to created audio file.
- Return type
str
- check_work_in_video(video_path: str, pos: int, 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 atvideo_path
of this editor.- Parameters
video_path (str) – The path to the input video file.
pos (int) – The position in the video at
vide_path
as_pil (bool, optional) – Whether to return object as
Image.Image
ornpt.NDArray[npt.uint8]
. Defaults toTrue
.
- Returns
An edited result for the
pos
-th frame.- Return type
Union[npt.NDArray[np.uint8], Image.Image]
- check_works_in_video(video_path: str, audio_path: Optional[str] = None, out_path: Optional[str] = None, codec: str = 'H264', H: Optional[int] = None, W: Optional[int] = None, fps: Optional[float] = None, open: bool = True, **kwargs) → str[source]¶
Check the editing results of this editor for a video at
video_path
.- Parameters
video_path (str) – Path to the input video file.
audio_path (str, optional) – Path to the audio file. Defaults to
None
. (Same asvideo_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"
.H (Optional[int], optional) – Height of the output video. Defaults to
None
.W (Optional[int], optional) – Width of the output video. Defaults to
None
.fps (Optional[float], optional) – Frame rate of the output video. Defaults to
None
.open (bool, optional) – Whether to open output file or not. Defaults to
True
.
- Returns
The path to the created video.
- Return type
str
- class veditor.elements.base.FixedElement(pos_frames: Tuple[int, Optional[int]] = (0, None), margin: Union[int, List[int]] = 0, width: Optional[int] = None, height: Optional[int] = None, top: Optional[Union[veditor.elements.base.BaseElement, int]] = None, right: Optional[Union[veditor.elements.base.BaseElement, int]] = None, left: Optional[Union[veditor.elements.base.BaseElement, int]] = None, bottom: Optional[Union[veditor.elements.base.BaseElement, int]] = None, **kwargs)[source]¶
Bases:
veditor.elements.base.BaseElement
- calc_element_size(width: Optional[int] = None, height: Optional[int] = None, **kwargs) → Tuple[int, int][source]¶
Basic method for calculating the element size.
- Parameters
width (Optional[int], optional) – Element width. Defaults to
None
.height (Optional[int], optional) – Element height. Defaults to
None
.
- Returns
Tu
- Return type
Tuple[int, int]
- set_size(width: Optional[int] = None, height: Optional[int] = None, **kwargs) → None[source]¶
Set size attributes (
width
andheight
).- Parameters
width (int) – [description].
height (int) – [description].
- set_margin(margin: Optional[Union[int, List[int]]] = None, margin_default: int = 0) → None[source]¶
Set an attribute for element margin.
- Parameters
margin (Optional[Union[int, List[int]]], optional) – Margin. Defaults to
None
.margin_default (int, optional) – Default value for margin. Defaults to
0
.
- set_locations(top: Optional[Union[veditor.elements.base.BaseElement, int]] = None, right: Optional[Union[veditor.elements.base.BaseElement, int]] = None, left: Optional[Union[veditor.elements.base.BaseElement, int]] = None, bottom: Optional[Union[veditor.elements.base.BaseElement, int]] = None) → None[source]¶
Automatically calculate and find the optimal locations for both
left
andtop
- Parameters
top (Optional[Union[BaseElement, int]], optional) – Reference element or absolute value at the top. Defaults to
None
.right (Optional[Union[BaseElement, int]], optional) – Reference element or absolute value at the right. Defaults to
None
.left (Optional[Union[BaseElement, int]], optional) – Reference element or absolute value at the left. Defaults to
None
.bottom (Optional[Union[BaseElement, int]], optional) – Reference element or absolute value at the bottom. Defaults to
None
.
- set_location(lb: Optional[Union[veditor.elements.base.BaseElement, int]] = None, ub: Optional[Union[veditor.elements.base.BaseElement, int]] = None, direction: str = 'vertical', ratio: Tuple[numbers.Number, numbers.Number] = (1, 1)) → None[source]¶
Automatically calculate and find the optimal location (
left
ortop
)- Parameters
lb (Optional[Union[BaseElement, int]], optional) – Lower bound of location. Defaults to
None
.ub (Optional[Union[BaseElement, int]], optional) – Upper bound of location. Defaults to
None
.direction (str, optional) – Direction of
lb
andub
line up. Please choose from"vertical"
or"horizontal"
. Defaults to"vertical"
.ratio (Tuple[Number,Number], optional) – If
lb
andub
are both instances ofBaseElement
, at what ratio do you split between the 2 elements? Defaults to(1, 1)
.
- edit(frame: numpy.ndarray[Any, numpy.dtype[numpy.uint8]], pos: int, **kwargs) → numpy.ndarray[Any, numpy.dtype[numpy.uint8]][source]¶
Return
frame
as it is.- Parameters
frame (npt.NDArray[np.uint8]) – The current frame (BGR image) (in the video)
pos (int) – The current position (in the video)
- Returns
An editied frame.
- Return type
npt.NDArray[np.uint8]
- calc_dsize(dsize: Optional[Tuple[int, int]] = None, width: Optional[int] = None, height: Optional[int] = None) → Tuple[int, int][source]¶
Resize the both
image_pil
andimage_arr
attributes.If only
width
orheight
is given, resize while preserving the aspect ratio.- Parameters
dsize (Optional[Tuple[int,int]], optional) – Desired image size. Defaults to
None
.width (Optional[int], optional) – Desired image width. Defaults to
None
.height (Optional[int], optional) – Desired image height. Defaults to
None
.
- Returns
Calculated desired size. (
width
,height
)- Return type
Tuple[int, int]
- resize(dsize: Optional[Tuple[int, int]] = None, width: Optional[int] = None, height: Optional[int] = None)[source]¶
Resize the element size.
- Parameters
dsize (Optional[Tuple[int, int]], optional) – Desired size. Defaults to
None
.width (Optional[int], optional) – Desired width. Defaults to
None
.height (Optional[int], optional) – Desired height. Defaults to
None
.
- check_work(video_path: str, pos: int, 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 atvideo_path
of this editor.- Parameters
video_path (str) – The path to the input video file.
pos (int) – The position in the video at
vide_path
as_pil (bool, optional) – Whether to return object as
Image.Image
ornpt.NDArray[npt.uint8]
. Defaults toTrue
.
- Returns
An edited result for the
pos
-th frame.- Return type
Union[npt.NDArray[np.uint8], Image.Image]