From 552ed166a8f6681d9140adb7cf734a50e521da2b Mon Sep 17 00:00:00 2001 From: Ankit raj <113342181+ankit-v2-3@users.noreply.github.com> Date: Tue, 29 Apr 2025 10:01:21 +0530 Subject: [PATCH 01/19] feat: add transcode --- videodb/__about__.py | 2 +- videodb/__init__.py | 8 ++++++++ videodb/_constants.py | 26 ++++++++++++++++++++++++++ videodb/client.py | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 1 deletion(-) diff --git a/videodb/__about__.py b/videodb/__about__.py index 972eedd..90f7f66 100644 --- a/videodb/__about__.py +++ b/videodb/__about__.py @@ -1,7 +1,7 @@ """ About information for videodb sdk""" -__version__ = "0.2.13" +__version__ = "0.2.14" __title__ = "videodb" __author__ = "videodb" __email__ = "contact@videodb.io" diff --git a/videodb/__init__.py b/videodb/__init__.py index 6f13816..d1d3215 100644 --- a/videodb/__init__.py +++ b/videodb/__init__.py @@ -16,6 +16,10 @@ SubtitleBorderStyle, SubtitleStyle, TextStyle, + TranscodeMode, + ResizeMode, + VideoConfig, + AudioConfig, ) from videodb.client import Connection from videodb.exceptions import ( @@ -43,6 +47,10 @@ "TextStyle", "SceneExtractionType", "Segmenter", + "TranscodeMode", + "ResizeMode", + "VideoConfig", + "AudioConfig", ] diff --git a/videodb/_constants.py b/videodb/_constants.py index b155752..b0eafbe 100644 --- a/videodb/_constants.py +++ b/videodb/_constants.py @@ -76,6 +76,7 @@ class ApiPath: web = "web" translate = "translate" dub = "dub" + transcode = "transcode" class Status: @@ -164,3 +165,28 @@ class TextStyle: tabsize: int = 4 x: Union[str, int] = "(main_w-text_w)/2" y: Union[str, int] = "(main_h-text_h)/2" + + +class TranscodeMode: + lightning = "lightning" + economy = "economy" + + +class ResizeMode: + crop = "crop" + fit = "fit" + pad = "pad" + + +@dataclass +class VideoConfig: + resolution: int = 720 + quality: int = 23 + framerate: int = None + aspect_ratio: str = None + resize_mode: str = ResizeMode.crop + + +@dataclass +class AudioConfig: + mute: bool = False diff --git a/videodb/client.py b/videodb/client.py index 7cbfbfd..54fe008 100644 --- a/videodb/client.py +++ b/videodb/client.py @@ -8,6 +8,9 @@ from videodb.__about__ import __version__ from videodb._constants import ( ApiPath, + TranscodeMode, + VideoConfig, + AudioConfig, ) from videodb.collection import Collection @@ -188,6 +191,41 @@ def youtube_search( ) return search_data.get("results") + def transcode( + self, + source: str, + callback_url: str, + mode: TranscodeMode = TranscodeMode.economy, + start_ts: int = None, + end_ts: int = None, + video_config: VideoConfig = VideoConfig(), + audio_config: AudioConfig = AudioConfig(), + ) -> None: + """Transcode the video + + :param str source: URL of the video to transcode, preferably a downloadable URL + :param str callback_url: URL to receive the callback + :param TranscodeMode mode: Mode of the transcoding + :param int start_ts: Start timestamp of the video to transcode (optional) + :param int end_ts: End timestamp of the video to transcode (optional) + :param VideoConfig video_config: Video configuration (optional) + :param AudioConfig audio_config: Audio configuration (optional) + :return: None + :rtype: None + """ + self.post( + path=f"{ApiPath.transcode}", + data={ + "source": source, + "callback_url": callback_url, + "mode": mode, + "start_ts": start_ts, + "end_ts": end_ts, + "video_config": video_config.__dict__, + "audio_config": audio_config.__dict__, + }, + ) + def upload( self, file_path: str = None, From 55269c97083323dcb1ceb4e787a1488f7bdfad94 Mon Sep 17 00:00:00 2001 From: Ankit raj <113342181+ankit-v2-3@users.noreply.github.com> Date: Tue, 6 May 2025 15:14:40 +0530 Subject: [PATCH 02/19] refactor: start and end --- videodb/client.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/videodb/client.py b/videodb/client.py index 54fe008..f0e5c26 100644 --- a/videodb/client.py +++ b/videodb/client.py @@ -196,8 +196,8 @@ def transcode( source: str, callback_url: str, mode: TranscodeMode = TranscodeMode.economy, - start_ts: int = None, - end_ts: int = None, + start: int = None, + end: int = None, video_config: VideoConfig = VideoConfig(), audio_config: AudioConfig = AudioConfig(), ) -> None: @@ -206,8 +206,8 @@ def transcode( :param str source: URL of the video to transcode, preferably a downloadable URL :param str callback_url: URL to receive the callback :param TranscodeMode mode: Mode of the transcoding - :param int start_ts: Start timestamp of the video to transcode (optional) - :param int end_ts: End timestamp of the video to transcode (optional) + :param int start: Start timestamp of the video to transcode (optional) + :param int end: End timestamp of the video to transcode (optional) :param VideoConfig video_config: Video configuration (optional) :param AudioConfig audio_config: Audio configuration (optional) :return: None @@ -219,8 +219,8 @@ def transcode( "source": source, "callback_url": callback_url, "mode": mode, - "start_ts": start_ts, - "end_ts": end_ts, + "start": start, + "end": end, "video_config": video_config.__dict__, "audio_config": audio_config.__dict__, }, From 808b8fdef764867c0cf9ab772d1269e908c2b833 Mon Sep 17 00:00:00 2001 From: Ankit raj <113342181+ankit-v2-3@users.noreply.github.com> Date: Tue, 10 Jun 2025 19:14:50 +0530 Subject: [PATCH 03/19] feat: add transcode details --- videodb/client.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/videodb/client.py b/videodb/client.py index f0e5c26..528bfdf 100644 --- a/videodb/client.py +++ b/videodb/client.py @@ -226,6 +226,15 @@ def transcode( }, ) + def get_transcode_details(self, job_id: str) -> dict: + """Get the details of a transcode job. + + :param str job_id: ID of the transcode job + :return: Details of the transcode job + :rtype: dict + """ + return self.get(path=f"{ApiPath.transcode}/{job_id}") + def upload( self, file_path: str = None, From 80f4541966b66199ace6811d5ed834577a7485eb Mon Sep 17 00:00:00 2001 From: Ankit raj <113342181+ankit-v2-3@users.noreply.github.com> Date: Tue, 10 Jun 2025 19:18:13 +0530 Subject: [PATCH 04/19] fix: constants --- videodb/_constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/videodb/_constants.py b/videodb/_constants.py index b0eafbe..a4415b2 100644 --- a/videodb/_constants.py +++ b/videodb/_constants.py @@ -180,7 +180,7 @@ class ResizeMode: @dataclass class VideoConfig: - resolution: int = 720 + resolution: int = None quality: int = 23 framerate: int = None aspect_ratio: str = None From 24711acbc9ab52ac7017e2439a6229d524a8f138 Mon Sep 17 00:00:00 2001 From: Ankit raj <113342181+ankit-v2-3@users.noreply.github.com> Date: Tue, 10 Jun 2025 19:26:12 +0530 Subject: [PATCH 05/19] feat: add job id --- videodb/client.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/videodb/client.py b/videodb/client.py index 528bfdf..896eacd 100644 --- a/videodb/client.py +++ b/videodb/client.py @@ -213,7 +213,7 @@ def transcode( :return: None :rtype: None """ - self.post( + job_data = self.post( path=f"{ApiPath.transcode}", data={ "source": source, @@ -225,6 +225,7 @@ def transcode( "audio_config": audio_config.__dict__, }, ) + return job_data.get("job_id") def get_transcode_details(self, job_id: str) -> dict: """Get the details of a transcode job. From 1993b82c4804233f02827295cef95df1c3678aff Mon Sep 17 00:00:00 2001 From: Ankit raj <113342181+ankit-v2-3@users.noreply.github.com> Date: Tue, 10 Jun 2025 19:29:28 +0530 Subject: [PATCH 06/19] build: update version --- videodb/__about__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/videodb/__about__.py b/videodb/__about__.py index 90f7f66..4059c8a 100644 --- a/videodb/__about__.py +++ b/videodb/__about__.py @@ -1,7 +1,7 @@ """ About information for videodb sdk""" -__version__ = "0.2.14" +__version__ = "0.2.15" __title__ = "videodb" __author__ = "videodb" __email__ = "contact@videodb.io" From fa73a1e939f6d710bc41bb5ebaf1cadb2b2970ba Mon Sep 17 00:00:00 2001 From: Ankit raj <113342181+ankit-v2-3@users.noreply.github.com> Date: Wed, 11 Jun 2025 14:53:17 +0530 Subject: [PATCH 07/19] fix: remove ts --- videodb/client.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/videodb/client.py b/videodb/client.py index 896eacd..a8818c2 100644 --- a/videodb/client.py +++ b/videodb/client.py @@ -196,8 +196,6 @@ def transcode( source: str, callback_url: str, mode: TranscodeMode = TranscodeMode.economy, - start: int = None, - end: int = None, video_config: VideoConfig = VideoConfig(), audio_config: AudioConfig = AudioConfig(), ) -> None: @@ -206,8 +204,6 @@ def transcode( :param str source: URL of the video to transcode, preferably a downloadable URL :param str callback_url: URL to receive the callback :param TranscodeMode mode: Mode of the transcoding - :param int start: Start timestamp of the video to transcode (optional) - :param int end: End timestamp of the video to transcode (optional) :param VideoConfig video_config: Video configuration (optional) :param AudioConfig audio_config: Audio configuration (optional) :return: None @@ -219,8 +215,6 @@ def transcode( "source": source, "callback_url": callback_url, "mode": mode, - "start": start, - "end": end, "video_config": video_config.__dict__, "audio_config": audio_config.__dict__, }, From 5aa14a6a2d701b306f42f7de85e3ae1d33a2a020 Mon Sep 17 00:00:00 2001 From: Ankit raj <113342181+ankit-v2-3@users.noreply.github.com> Date: Thu, 12 Jun 2025 17:45:00 +0530 Subject: [PATCH 08/19] fix: doc strings --- videodb/client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/videodb/client.py b/videodb/client.py index 5bd7375..25ae399 100644 --- a/videodb/client.py +++ b/videodb/client.py @@ -230,8 +230,8 @@ def transcode( :param TranscodeMode mode: Mode of the transcoding :param VideoConfig video_config: Video configuration (optional) :param AudioConfig audio_config: Audio configuration (optional) - :return: None - :rtype: None + :return: Transcode job ID + :rtype: str """ job_data = self.post( path=f"{ApiPath.transcode}", From 8e79b159c9fee8e51ffe15a0f97745a1a95727f9 Mon Sep 17 00:00:00 2001 From: Ankit raj <113342181+ankit-v2-3@users.noreply.github.com> Date: Mon, 23 Jun 2025 12:54:46 +0530 Subject: [PATCH 09/19] feat: add timelinev2 --- videodb/timeline_v2.py | 250 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 250 insertions(+) create mode 100644 videodb/timeline_v2.py diff --git a/videodb/timeline_v2.py b/videodb/timeline_v2.py new file mode 100644 index 0000000..2f4732c --- /dev/null +++ b/videodb/timeline_v2.py @@ -0,0 +1,250 @@ +from typing import List, Optional, Union +from enum import Enum + + +class AssetType(str, Enum): + video = "video" + image = "image" + + +class Fit(str, Enum): + crop = "crop" + cover = "cover" + contain = "contain" + none = "none" + + +class Position(str, Enum): + top = "top" + bottom = "bottom" + left = "left" + right = "right" + center = "center" + top_left = "top-left" + top_right = "top-right" + bottom_left = "bottom-left" + bottom_right = "bottom-right" + + +class Filter(str, Enum): + """A filter effect to apply to the Clip.""" + + blur = "blur" + boost = "boost" + contrast = "contrast" + darken = "darken" + greyscale = "greyscale" + lighten = "lighten" + muted = "muted" + negative = "negative" + + +class Offset: + def __init__(self, x: float = 0, y: float = 0): + self.x = x + self.y = y + + def to_json(self): + return { + "x": self.x, + "y": self.y, + } + + +class Crop: + def __init__(self, top: int = 0, right: int = 0, bottom: int = 0, left: int = 0): + self.top = top + self.right = right + self.bottom = bottom + self.left = left + + def to_json(self): + return { + "top": self.top, + "right": self.right, + "bottom": self.bottom, + "left": self.left, + } + + +class Transition: + def __init__(self, in_: str = None, out: str = None): + self.in_ = in_ + self.out = out + + def to_json(self): + return { + "in": self.in_, + "out": self.out, + } + + +class BaseAsset: + """The type of asset to display for the duration of the Clip.""" + + type: AssetType + + +class VideoAsset(BaseAsset): + """The VideoAsset is used to create video sequences from video files. The src must be a publicly accessible URL to a video resource""" + + type = AssetType.video + + def __init__( + self, + id: str, + trim: int = 0, + volume: float = 1, + crop: Optional[Crop] = None, + ): + if trim < 0: + raise ValueError("trim must be non-negative") + if not (0 <= volume <= 2): + raise ValueError("volume must be between 0 and 2") + + self.id = id + self.trim = trim + self.volume = volume + self.crop = crop if crop is not None else Crop() + + def to_json(self): + return { + "type": self.type, + "id": self.id, + "trim": self.trim, + "volume": self.volume, + "crop": self.crop.to_json(), + } + + +class ImageAsset(BaseAsset): + """The ImageAsset is used to create video from images to compose an image. The src must be a publicly accessible URL to an image resource such as a jpg or png file.""" + + type = AssetType.image + + def __init__(self, id: str, trim: int = 0, crop: Optional[Crop] = None): + if trim < 0: + raise ValueError("trim must be non-negative") + + self.id = id + self.trim = trim + self.crop = crop if crop is not None else Crop() + + def to_json(self): + return { + "type": self.type, + "id": self.id, + "trim": self.trim, + "crop": self.crop.to_json(), + } + + +AnyAsset = Union[VideoAsset, ImageAsset] + + +class Clip: + """A clip is a container for a specific type of asset, i.e. a title, image, video, audio or html. You use a Clip to define when an asset will display on the timeline, how long it will play for and transitions, filters and effects to apply to it.""" + + def __init__( + self, + asset: AnyAsset, + start: Union[float, int], + length: Union[float, int], + transition: Optional[Transition] = None, + effect: Optional[str] = None, + filter: Optional[Filter] = None, + scale: float = 1, + opacity: float = 1, + fit: Optional[Fit] = Fit.crop, + position: Position = Position.center, + offset: Optional[Offset] = None, + ): + if start < 0: + raise ValueError("start must be non-negative") + if length <= 0: + raise ValueError("length must be positive") + if not (0 <= scale <= 10): + raise ValueError("scale must be between 0 and 10") + if not (0 <= opacity <= 1): + raise ValueError("opacity must be between 0 and 1") + + self.asset = asset + self.start = start + self.length = length + self.transition = transition + self.effect = effect + self.filter = filter + self.scale = scale + self.opacity = opacity + self.fit = fit + self.position = position + self.offset = offset if offset is not None else Offset() + + def to_json(self): + json = { + "asset": self.asset.to_json(), + "start": self.start, + "length": self.length, + "effect": self.effect, + "scale": self.scale, + "opacity": self.opacity, + "fit": self.fit, + "position": self.position, + "offset": self.offset.to_json(), + } + + if self.transition: + json["transition"] = self.transition.to_json() + if self.filter: + json["filter"] = self.filter.value + + return json + + +class Track: + clips: List[Clip] + + def __init__(self, clips: List[Clip] = []): + self.clips = clips + + def add_clip(self, clip: Clip): + self.clips.append(clip) + + def to_json(self): + return { + "clips": [clip.to_json() for clip in self.clips], + } + + +class TimelineV2: + def __init__(self, connection): + self.connection = connection + self.background: str = "#000000" + self.resolution: str = "1280x720" + self.tracks: List[Track] = [] + self.stream_url = None + self.player_url = None + + def add_track(self, track: Track): + self.tracks.append(track) + + def add_clip(self, track_index: int, clip: Clip): + self.tracks[track_index].clips.append(clip) + + def to_json(self): + return { + "timeline": { + "background": self.background, + "resolution": self.resolution, + "tracks": [track.to_json() for track in self.tracks], + } + } + + def generate_stream(self): + stream_data = self.connection.post( + path="timeline_v2", + data=self.to_json(), + ) + self.stream_url = stream_data.get("stream_url") + self.player_url = stream_data.get("player_url") + return stream_data.get("stream_url", None) From a8fdf4ee943f4d977851e130189730a729a6459e Mon Sep 17 00:00:00 2001 From: Ankit raj <113342181+ankit-v2-3@users.noreply.github.com> Date: Mon, 23 Jun 2025 14:28:13 +0530 Subject: [PATCH 10/19] fix: fit --- videodb/timeline_v2.py | 1 - 1 file changed, 1 deletion(-) diff --git a/videodb/timeline_v2.py b/videodb/timeline_v2.py index 2f4732c..8e973d0 100644 --- a/videodb/timeline_v2.py +++ b/videodb/timeline_v2.py @@ -11,7 +11,6 @@ class Fit(str, Enum): crop = "crop" cover = "cover" contain = "contain" - none = "none" class Position(str, Enum): From 1e4a5f61259e3979853fbef4c605e03923a6e30f Mon Sep 17 00:00:00 2001 From: Ankit raj <113342181+ankit-v2-3@users.noreply.github.com> Date: Mon, 23 Jun 2025 15:24:41 +0530 Subject: [PATCH 11/19] build: update v --- videodb/__about__.py | 2 +- videodb/timeline_v2.py | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/videodb/__about__.py b/videodb/__about__.py index 3cc2806..fe85f3d 100644 --- a/videodb/__about__.py +++ b/videodb/__about__.py @@ -2,7 +2,7 @@ -__version__ = "0.2.15" +__version__ = "0.2.16" __title__ = "videodb" __author__ = "videodb" __email__ = "contact@videodb.io" diff --git a/videodb/timeline_v2.py b/videodb/timeline_v2.py index 8e973d0..c6b82ba 100644 --- a/videodb/timeline_v2.py +++ b/videodb/timeline_v2.py @@ -201,8 +201,6 @@ def to_json(self): class Track: - clips: List[Clip] - def __init__(self, clips: List[Clip] = []): self.clips = clips From 2b51bfc22c2a13009ef4aa11bd9d301f972d4e98 Mon Sep 17 00:00:00 2001 From: Ankit raj <113342181+ankit-v2-3@users.noreply.github.com> Date: Thu, 26 Jun 2025 10:12:58 +0530 Subject: [PATCH 12/19] fix: image asset --- videodb/timeline_v2.py | 1 - 1 file changed, 1 deletion(-) diff --git a/videodb/timeline_v2.py b/videodb/timeline_v2.py index c6b82ba..8c98e65 100644 --- a/videodb/timeline_v2.py +++ b/videodb/timeline_v2.py @@ -133,7 +133,6 @@ def to_json(self): return { "type": self.type, "id": self.id, - "trim": self.trim, "crop": self.crop.to_json(), } From 2940995c6b67985c538ea5123f0aefc7f07d0713 Mon Sep 17 00:00:00 2001 From: Ankit raj <113342181+ankit-v2-3@users.noreply.github.com> Date: Wed, 2 Jul 2025 18:30:39 +0530 Subject: [PATCH 13/19] feat: add audio asset --- videodb/__about__.py | 2 +- videodb/timeline_v2.py | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/videodb/__about__.py b/videodb/__about__.py index fe85f3d..1a52acf 100644 --- a/videodb/__about__.py +++ b/videodb/__about__.py @@ -2,7 +2,7 @@ -__version__ = "0.2.16" +__version__ = "0.2.17" __title__ = "videodb" __author__ = "videodb" __email__ = "contact@videodb.io" diff --git a/videodb/timeline_v2.py b/videodb/timeline_v2.py index 8c98e65..b323893 100644 --- a/videodb/timeline_v2.py +++ b/videodb/timeline_v2.py @@ -137,7 +137,26 @@ def to_json(self): } -AnyAsset = Union[VideoAsset, ImageAsset] +class AudioAsset(BaseAsset): + """The AudioAsset is used to create audio sequences from audio files. The src must be a publicly accessible URL to an audio resource""" + + type = AssetType.audio + + def __init__(self, id: str, trim: int = 0, volume: float = 1): + self.id = id + self.trim = trim + self.volume = volume + + def to_json(self): + return { + "type": self.type, + "id": self.id, + "trim": self.trim, + "volume": self.volume, + } + + +AnyAsset = Union[VideoAsset, ImageAsset, AudioAsset] class Clip: From 2672b729ab597b09986e73459b02d864e022b8dc Mon Sep 17 00:00:00 2001 From: Ankit raj <113342181+ankit-v2-3@users.noreply.github.com> Date: Wed, 2 Jul 2025 18:35:43 +0530 Subject: [PATCH 14/19] fix: asset enum --- videodb/timeline_v2.py | 1 + 1 file changed, 1 insertion(+) diff --git a/videodb/timeline_v2.py b/videodb/timeline_v2.py index b323893..5482cad 100644 --- a/videodb/timeline_v2.py +++ b/videodb/timeline_v2.py @@ -5,6 +5,7 @@ class AssetType(str, Enum): video = "video" image = "image" + audio = "audio" class Fit(str, Enum): From 3537e396d00e4210229883275cc5cb642e561fec Mon Sep 17 00:00:00 2001 From: Ankit raj <113342181+ankit-v2-3@users.noreply.github.com> Date: Tue, 8 Jul 2025 13:07:45 +0530 Subject: [PATCH 15/19] feat: add text asset --- videodb/timeline_v2.py | 223 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 222 insertions(+), 1 deletion(-) diff --git a/videodb/timeline_v2.py b/videodb/timeline_v2.py index 5482cad..f2e01c0 100644 --- a/videodb/timeline_v2.py +++ b/videodb/timeline_v2.py @@ -6,6 +6,7 @@ class AssetType(str, Enum): video = "video" image = "image" audio = "audio" + text = "text" class Fit(str, Enum): @@ -39,6 +40,36 @@ class Filter(str, Enum): negative = "negative" +class TextAlignment(str, Enum): + """Place the text in one of nine predefined positions of the background.""" + + top = "top" + top_right = "top_right" + right = "right" + bottom_right = "bottom_right" + bottom = "bottom" + bottom_left = "bottom_left" + left = "left" + top_left = "top_left" + center = "center" + + +class HorizontalAlignment(str, Enum): + """Horizontal text alignment options.""" + + left = "left" + center = "center" + right = "right" + + +class VerticalAlignment(str, Enum): + """Vertical text alignment options.""" + + top = "top" + center = "center" + bottom = "bottom" + + class Offset: def __init__(self, x: float = 0, y: float = 0): self.x = x @@ -157,7 +188,197 @@ def to_json(self): } -AnyAsset = Union[VideoAsset, ImageAsset, AudioAsset] +class Font: + """Font styling properties for text assets.""" + + def __init__( + self, + family: str = "Clear Sans", + size: int = 48, + color: str = "#FFFFFF", + opacity: float = 1.0, + weight: Optional[int] = None, + ): + if size < 1: + raise ValueError("size must be at least 1") + if not (0.0 <= opacity <= 1.0): + raise ValueError("opacity must be between 0.0 and 1.0") + if weight is not None and not (100 <= weight <= 900): + raise ValueError("weight must be between 100 and 900") + + self.family = family + self.size = size + self.color = color + self.opacity = opacity + self.weight = weight + + def to_json(self): + data = { + "family": self.family, + "size": self.size, + "color": self.color, + "opacity": self.opacity, + } + if self.weight is not None: + data["weight"] = self.weight + return data + + +class Border: + """Text border properties.""" + + def __init__(self, color: str = "#000000", width: float = 0.0): + if width < 0.0: + raise ValueError("width must be non-negative") + self.color = color + self.width = width + + def to_json(self): + return { + "color": self.color, + "width": self.width, + } + + +class Shadow: + """Text shadow properties.""" + + def __init__(self, color: str = "#000000", x: float = 0.0, y: float = 0.0): + if x < 0.0: + raise ValueError("x must be non-negative") + if y < 0.0: + raise ValueError("y must be non-negative") + self.color = color + self.x = x + self.y = y + + def to_json(self): + return { + "color": self.color, + "x": self.x, + "y": self.y, + } + + +class Background: + """Text background styling properties.""" + + def __init__( + self, + width: float = 0.0, + height: float = 0.0, + color: str = "#000000", + border_width: float = 0.0, + opacity: float = 1.0, + text_alignment: TextAlignment = TextAlignment.center, + ): + if width < 0.0: + raise ValueError("width must be non-negative") + if height < 0.0: + raise ValueError("height must be non-negative") + if border_width < 0.0: + raise ValueError("border_width must be non-negative") + if not (0.0 <= opacity <= 1.0): + raise ValueError("opacity must be between 0.0 and 1.0") + + self.width = width + self.height = height + self.color = color + self.border_width = border_width + self.opacity = opacity + self.text_alignment = text_alignment + + def to_json(self): + return { + "width": self.width, + "height": self.height, + "color": self.color, + "border_width": self.border_width, + "opacity": self.opacity, + "text_alignment": self.text_alignment.value, + } + + +class Alignment: + """Text alignment properties.""" + + def __init__( + self, + horizontal: HorizontalAlignment = HorizontalAlignment.center, + vertical: VerticalAlignment = VerticalAlignment.center, + ): + self.horizontal = horizontal + self.vertical = vertical + + def to_json(self): + return { + "horizontal": self.horizontal.value, + "vertical": self.vertical.value, + } + + +class TextAsset(BaseAsset): + """The TextAsset is used to create text sequences from text strings with full control over the text styling and positioning.""" + + type = AssetType.text + + def __init__( + self, + text: str, + font: Optional[Font] = None, + border: Optional[Border] = None, + shadow: Optional[Shadow] = None, + background: Optional[Background] = None, + alignment: Optional[Alignment] = None, + tabsize: int = 4, + line_spacing: float = 0, + width: Optional[int] = None, + height: Optional[int] = None, + ): + if tabsize < 1: + raise ValueError("tabsize must be at least 1") + if line_spacing < 0.0: + raise ValueError("line_spacing must be non-negative") + if width is not None and width < 1: + raise ValueError("width must be at least 1") + if height is not None and height < 1: + raise ValueError("height must be at least 1") + + self.text = text + self.font = font if font is not None else Font() + self.border = border + self.shadow = shadow + self.background = background + self.alignment = alignment if alignment is not None else Alignment() + self.tabsize = tabsize + self.line_spacing = line_spacing + self.width = width + self.height = height + + def to_json(self): + data = { + "type": self.type, + "text": self.text, + "font": self.font.to_json(), + "alignment": self.alignment.to_json(), + "tabsize": self.tabsize, + "line_spacing": self.line_spacing, + } + if self.border: + data["border"] = self.border.to_json() + if self.shadow: + data["shadow"] = self.shadow.to_json() + if self.background: + data["background"] = self.background.to_json() + if self.width is not None: + data["width"] = self.width + if self.height is not None: + data["height"] = self.height + + return data + + +AnyAsset = Union[VideoAsset, ImageAsset, AudioAsset, TextAsset] class Clip: From ac78d552712e66e9e361dc01ac27378c3aed3551 Mon Sep 17 00:00:00 2001 From: Ankit raj <113342181+ankit-v2-3@users.noreply.github.com> Date: Thu, 17 Jul 2025 11:53:45 +0530 Subject: [PATCH 16/19] fix: volume range --- videodb/timeline_v2.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/videodb/timeline_v2.py b/videodb/timeline_v2.py index f2e01c0..b74bc62 100644 --- a/videodb/timeline_v2.py +++ b/videodb/timeline_v2.py @@ -130,8 +130,8 @@ def __init__( ): if trim < 0: raise ValueError("trim must be non-negative") - if not (0 <= volume <= 2): - raise ValueError("volume must be between 0 and 2") + if not (0 <= volume <= 5): + raise ValueError("volume must be between 0 and 5") self.id = id self.trim = trim From fcf4796ed6cfd18ba96209bddeffcb7686f9edc2 Mon Sep 17 00:00:00 2001 From: Ankit raj <113342181+ankit-v2-3@users.noreply.github.com> Date: Tue, 5 Aug 2025 11:09:52 +0530 Subject: [PATCH 17/19] feat: add caption asset --- videodb/timeline_v2.py | 168 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 167 insertions(+), 1 deletion(-) diff --git a/videodb/timeline_v2.py b/videodb/timeline_v2.py index b74bc62..27c2903 100644 --- a/videodb/timeline_v2.py +++ b/videodb/timeline_v2.py @@ -7,6 +7,7 @@ class AssetType(str, Enum): image = "image" audio = "audio" text = "text" + caption = "caption" class Fit(str, Enum): @@ -62,6 +63,40 @@ class HorizontalAlignment(str, Enum): right = "right" +class CaptionBorderStyle(int, Enum): + """Border style properties for caption assets.""" + + no_border = 1 + opaque_box = 3 + outline = 4 + + +class CaptionAlignment(int, Enum): + """Caption alignment properties for caption assets.""" + + bottom_left = 1 + bottom_center = 2 + bottom_right = 3 + middle_left = 9 + middle_center = 10 + middle_right = 11 + top_left = 5 + top_center = 6 + top_right = 7 + + +class CaptionAnimation(str, Enum): + """Caption animation properties for caption assets.""" + + float_in_bottom = "float_in_bottom" + box_highlight = "box_highlight" + color_highlight = "color_highlight" + reveal = "reveal" + karioke = "karioke" + impact = "impact" + supersize = "supersize" + + class VerticalAlignment(str, Enum): """Vertical text alignment options.""" @@ -378,7 +413,138 @@ def to_json(self): return data -AnyAsset = Union[VideoAsset, ImageAsset, AudioAsset, TextAsset] +class FontStyling: + """Font styling properties for caption assets.""" + + def __init__( + self, + name: str = "Clear Sans", + size: int = 30, + bold: bool = False, + italic: bool = False, + underline: bool = False, + strikeout: bool = False, + scale_x: float = 1.0, + scale_y: float = 1.0, + spacing: float = 0.0, + angle: float = 0.0, + ): + self.name = name + self.size = size + self.bold = bold + self.italic = italic + self.underline = underline + self.strikeout = strikeout + self.scale_x = scale_x + self.scale_y = scale_y + self.spacing = spacing + self.angle = angle + + def to_json(self): + return { + "font_name": self.name, + "font_size": self.size, + "bold": self.bold, + "italic": self.italic, + "underline": self.underline, + "strikeout": self.strikeout, + "scale_x": self.scale_x, + "scale_y": self.scale_y, + "spacing": self.spacing, + "angle": self.angle, + } + + +class BorderAndShadow: + """Border and shadow properties for caption assets.""" + + def __init__( + self, + style: CaptionBorderStyle = CaptionBorderStyle.no_border, + outline: int = 1, + outline_color: str = "&H00000000", + shadow: int = 0, + ): + self.style = style + self.outline = outline + self.outline_color = outline_color + self.shadow = shadow + + def to_json(self): + return { + "style": self.style.value, + "outline": self.outline, + "outline_color": self.outline_color, + "shadow": self.shadow, + } + + +class Positioning: + """Positioning properties for caption assets.""" + + def __init__( + self, + alignment: CaptionAlignment = CaptionAlignment.bottom_center, + margin_l: int = 30, + margin_r: int = 30, + margin_v: int = 30, + ): + self.alignment = alignment + self.margin_l = margin_l + self.margin_r = margin_r + self.margin_v = margin_v + + def to_json(self): + return { + "alignment": self.alignment.value, + "margin_l": self.margin_l, + "margin_r": self.margin_r, + "margin_v": self.margin_v, + } + + +class CaptionAsset(BaseAsset): + """The CaptionAsset is used to create captions from text strings with full styling and ass support.""" + + type = AssetType.caption + + def __init__( + self, + src: str = "auto", + font: Optional[FontStyling] = None, + primary_color: str = "&H00FFFFFF", + secondary_color: str = "&H000000FF", + back_color: str = "&H00000000", + border: Optional[BorderAndShadow] = None, + position: Optional[Positioning] = None, + animation: Optional[CaptionAnimation] = None, + ): + self.src = src + self.font = font if font is not None else FontStyling() + self.primary_color = primary_color + self.secondary_color = secondary_color + self.back_color = back_color + self.border = border if border is not None else BorderAndShadow() + self.position = position if position is not None else Positioning() + self.animation = animation + + def to_json(self): + data = { + "type": self.type, + "src": self.src, + "font": self.font.to_json(), + "primary_color": self.primary_color, + "secondary_color": self.secondary_color, + "back_color": self.back_color, + "border": self.border.to_json(), + "position": self.position.to_json(), + } + if self.animation: + data["animation"] = self.animation.value + return data + + +AnyAsset = Union[VideoAsset, ImageAsset, AudioAsset, TextAsset, CaptionAsset] class Clip: From 9d5a6b0853485ca14270299cbf5cee9284747746 Mon Sep 17 00:00:00 2001 From: Ankit raj <113342181+ankit-v2-3@users.noreply.github.com> Date: Tue, 5 Aug 2025 12:41:09 +0530 Subject: [PATCH 18/19] fix: caption animation --- videodb/timeline_v2.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/videodb/timeline_v2.py b/videodb/timeline_v2.py index 27c2903..925d755 100644 --- a/videodb/timeline_v2.py +++ b/videodb/timeline_v2.py @@ -63,32 +63,32 @@ class HorizontalAlignment(str, Enum): right = "right" -class CaptionBorderStyle(int, Enum): +class CaptionBorderStyle(str, Enum): """Border style properties for caption assets.""" - no_border = 1 - opaque_box = 3 - outline = 4 + no_border = "no_border" + opaque_box = "opaque_box" + outline = "outline" -class CaptionAlignment(int, Enum): +class CaptionAlignment(str, Enum): """Caption alignment properties for caption assets.""" - bottom_left = 1 - bottom_center = 2 - bottom_right = 3 - middle_left = 9 - middle_center = 10 - middle_right = 11 - top_left = 5 - top_center = 6 - top_right = 7 + bottom_left = "bottom_left" + bottom_center = "bottom_center" + bottom_right = "bottom_right" + middle_left = "middle_left" + middle_center = "middle_center" + middle_right = "middle_right" + top_left = "top_left" + top_center = "top_center" + top_right = "top_right" class CaptionAnimation(str, Enum): """Caption animation properties for caption assets.""" - float_in_bottom = "float_in_bottom" + # float_in_bottom = "float_in_bottom" box_highlight = "box_highlight" color_highlight = "color_highlight" reveal = "reveal" @@ -424,8 +424,8 @@ def __init__( italic: bool = False, underline: bool = False, strikeout: bool = False, - scale_x: float = 1.0, - scale_y: float = 1.0, + scale_x: float = 100, + scale_y: float = 100, spacing: float = 0.0, angle: float = 0.0, ): From 92dc137f82cb1969b1c76fa31bf6142ab4291dcf Mon Sep 17 00:00:00 2001 From: Ankit raj <113342181+ankit-v2-3@users.noreply.github.com> Date: Tue, 5 Aug 2025 12:47:11 +0530 Subject: [PATCH 19/19] fix: border style --- videodb/timeline_v2.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/videodb/timeline_v2.py b/videodb/timeline_v2.py index 925d755..efd560d 100644 --- a/videodb/timeline_v2.py +++ b/videodb/timeline_v2.py @@ -66,8 +66,7 @@ class HorizontalAlignment(str, Enum): class CaptionBorderStyle(str, Enum): """Border style properties for caption assets.""" - no_border = "no_border" - opaque_box = "opaque_box" + outline_and_shadow = "outline_and_shadow" outline = "outline" @@ -460,7 +459,7 @@ class BorderAndShadow: def __init__( self, - style: CaptionBorderStyle = CaptionBorderStyle.no_border, + style: CaptionBorderStyle = CaptionBorderStyle.outline_and_shadow, outline: int = 1, outline_color: str = "&H00000000", shadow: int = 0,