Skip to content

Commit 5416008

Browse files
authored
Merge pull request #44 from video-db/ankit/add-transcode
Ankit/add transcode
2 parents 48ee29d + 5aa14a6 commit 5416008

File tree

4 files changed

+78
-1
lines changed

4 files changed

+78
-1
lines changed

videodb/__about__.py

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

33

4-
__version__ = "0.2.14"
4+
5+
__version__ = "0.2.15"
56
__title__ = "videodb"
67
__author__ = "videodb"
78
__email__ = "[email protected]"

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
@@ -80,6 +80,7 @@ class ApiPath:
8080
web = "web"
8181
translate = "translate"
8282
dub = "dub"
83+
transcode = "transcode"
8384

8485

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

videodb/client.py

Lines changed: 42 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
@@ -212,6 +215,45 @@ def youtube_search(
212215
)
213216
return search_data.get("results")
214217

218+
def transcode(
219+
self,
220+
source: str,
221+
callback_url: str,
222+
mode: TranscodeMode = TranscodeMode.economy,
223+
video_config: VideoConfig = VideoConfig(),
224+
audio_config: AudioConfig = AudioConfig(),
225+
) -> None:
226+
"""Transcode the video
227+
228+
:param str source: URL of the video to transcode, preferably a downloadable URL
229+
:param str callback_url: URL to receive the callback
230+
:param TranscodeMode mode: Mode of the transcoding
231+
:param VideoConfig video_config: Video configuration (optional)
232+
:param AudioConfig audio_config: Audio configuration (optional)
233+
:return: Transcode job ID
234+
:rtype: str
235+
"""
236+
job_data = self.post(
237+
path=f"{ApiPath.transcode}",
238+
data={
239+
"source": source,
240+
"callback_url": callback_url,
241+
"mode": mode,
242+
"video_config": video_config.__dict__,
243+
"audio_config": audio_config.__dict__,
244+
},
245+
)
246+
return job_data.get("job_id")
247+
248+
def get_transcode_details(self, job_id: str) -> dict:
249+
"""Get the details of a transcode job.
250+
251+
:param str job_id: ID of the transcode job
252+
:return: Details of the transcode job
253+
:rtype: dict
254+
"""
255+
return self.get(path=f"{ApiPath.transcode}/{job_id}")
256+
215257
def upload(
216258
self,
217259
file_path: str = None,

0 commit comments

Comments
 (0)