8000 feat: add transcode · video-db/videodb-python@552ed16 · GitHub
[go: up one dir, main page]

Skip to content

Commit 552ed16

Browse files
committed
feat: add transcode
1 parent d185e9a commit 552ed16

File tree

4 files changed

+73
-1
lines changed

4 files changed

+73
-1
lines changed

videodb/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
""" About information for videodb sdk"""
22

33

4-
__version__ = "0.2.13"
4+
__version__ = "0.2.14"
55
__title__ = "videodb"
66
__author__ = "videodb"
77
__email__ = "contact@videodb.io"

videodb/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
SubtitleBorderStyle,
1717
SubtitleStyle,
1818
TextStyle,
19+
TranscodeMode,
20+
ResizeMode,
21+
VideoConfig,
22+
AudioConfig,
1923
)
2024
from videodb.client import Connection
2125
from videodb.exceptions import (
@@ -43,6 +47,10 @@
4347
"TextStyle",
4448
"SceneExtractionType",
4549
"Segmenter",
50+
"TranscodeMode",
51+
"ResizeMode",
52+
"VideoConfig",
53+
"AudioConfig",
4654
]
4755

4856

videodb/_constants.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class ApiPath:
7676
web = "web"
7777
translate = "translate"
7878
dub = "dub"
79+
transcode = "transcode"
7980

8081

8182
class Status:
@@ -164,3 +165,28 @@ class TextStyle:
164165
tabsize: int = 4
165166
x: Union[str, int] = "(main_w-text_w)/2"
166167
y: Union[str, int] = "(main_h-text_h)/2"
168+
169+
170+
class TranscodeMode:
171+
lightning = "lightning"
172+
economy = "economy"
173+
174+
175+
class ResizeMode:
176+
crop = "crop"
177+
fit = "fit"
178+
pad = "pad"
179+
180+
181+
@dataclass
182+
class VideoConfig:
183+
resolution: int = 720
184+
quality: int = 23
185+
framerate: int = None
186+
aspect_ratio: str = None
187+
resize_mode: str = ResizeMode.crop
188+
189+
190+
@dataclass
191+
class AudioConfig:
192+
mute: bool = False

videodb/client.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
from videodb.__about__ import __version__
99
from videodb._constants import (
1010
ApiPath,
11+
TranscodeMode,
12+
VideoConfig,
13+
AudioConfig,
1114
)
1215

1316
from videodb.collection import Collection
@@ -188,6 +191,41 @@ def youtube_search(
188191
)
189192
return search_data.get("results")
190193

194+
def transcode(
195+
self,
196+
source: str,
197+
callback_url: str,
198+
mode: TranscodeMode = TranscodeMode.economy,
199+
start_ts: int = None,
200+
end_ts: int = None,
201+
video_config: VideoConfig = VideoConfig(),
202+
audio_config: AudioConfig = AudioConfig(),
203+
) -> None:
204+
"""Transcode the video
205+
206+
:param str source: URL of the video to transcode, preferably a downloadable URL
207+
:param str callback_url: URL to receive the callback
208+
:param TranscodeMode mode: Mode of the transcoding
209+
:param int start_ts: Start timestamp of the video to transcode (optional)
210+
:param int end_ts: End timestamp of the video to transcode (optional)
211+
:param VideoConfig video_config: Video configuration (optional)
212+
:param AudioConfig audio_config: Audio configuration (optional)
213+
:return: None
214+
:rtype: None
215+
"""
216+
self.post(
217+
path=f"{ApiPath.transcode}",
218+
data={
219+
"source": source,
220+
"callback_url": callback_url,
221+
"mode": mode,
222+
"start_ts": start_ts,
223+
"end_ts": end_ts,
224+
"video_config": video_config.__dict__,
225+
"audio_config": audio_config.__dict__,
226+
},
227+
)
228+
191229
def upload(
192230
self,
193231
file_path: str = None,

0 commit comments

Comments
 (0)
0