Skip to content

Commit b19eabb

Browse files
Merge pull request #184 from fastlabel/feature/codec-restriction-h264
SDKで動画のタスク登録するときに、動画のコーデックがH.264のものではない場合はエラーを返す
2 parents 5e4ae0b + 02ab51e commit b19eabb

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,8 @@ task_id = client.create_video_task(
767767
##### Limitation
768768

769769
- You can upload up to a size of 250 MB.
770+
- You can upload only videos with H.264 encoding.
771+
- You can upload only MP4 file format.
770772

771773
#### Find Task
772774

fastlabel/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,6 +1252,10 @@ def create_video_task(
12521252
raise FastLabelInvalidException(
12531253
"Supported video size is under 250 MB.", 422
12541254
)
1255+
if not utils.is_video_supported_codec(file_path):
1256+
raise FastLabelInvalidException(
1257+
"Supported video encoding for registration through the SDK is only H.264.", 422
1258+
)
12551259

12561260
file = utils.base64_encode(file_path)
12571261
payload = {"project": project, "name": name, "file": file}
@@ -1316,6 +1320,10 @@ def create_video_classification_task(
13161320
raise FastLabelInvalidException(
13171321
"Supported video size is under 250 MB.", 422
13181322
)
1323+
if not utils.is_video_supported_codec(file_path):
1324+
raise FastLabelInvalidException(
1325+
"Supported video encoding for registration through the SDK is only H.264.", 422
1326+
)
13191327

13201328
file = utils.base64_encode(file_path)
13211329
payload = {"project": project, "name": name, "file": file}

fastlabel/const.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@
222222
# API can accept under 250 MB
223223
SUPPORTED_OBJECT_SIZE = 250 * math.pow(1024, 2)
224224

225+
# Only 'avc1' and 'H264' are supported for video task creation.
226+
SUPPORTED_FOURCC = ["avc1"]
227+
225228

226229
SUPPORTED_INFERENCE_IMAGE_SIZE = 6 * math.pow(1024, 2)
227230

fastlabel/utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import geojson
77
import numpy as np
8+
import cv2
89

910
from fastlabel import const
1011

@@ -18,6 +19,10 @@ def is_image_supported_ext(file_path: str) -> bool:
1819
return file_path.lower().endswith((".png", ".jpg", ".jpeg"))
1920

2021

22+
def is_video_supported_codec(file_path: str) -> bool:
23+
return get_video_fourcc(file_path) in const.SUPPORTED_FOURCC
24+
25+
2126
def is_video_supported_ext(file_path: str) -> bool:
2227
return file_path.lower().endswith(".mp4")
2328

@@ -164,3 +169,11 @@ def is_clockwise(points: list) -> bool:
164169
def get_json_length(value) -> int:
165170
json_str = json.dumps(value)
166171
return len(json_str)
172+
173+
174+
def get_video_fourcc(video_path: str) -> str:
175+
cap = cv2.VideoCapture(video_path)
176+
fourcc_code = int(cap.get(cv2.CAP_PROP_FOURCC))
177+
fourcc_str = "".join([chr((fourcc_code >> 8 * i) & 0xFF) for i in range(4)])
178+
cap.release()
179+
return fourcc_str

0 commit comments

Comments
 (0)