Skip to content

Commit d749374

Browse files
feat(LAB-3512): remove video processing parameters checks for SDK (#1872)
Co-authored-by: paulruelle <[email protected]>
1 parent 4f092d9 commit d749374

File tree

1 file changed

+2
-84
lines changed

1 file changed

+2
-84
lines changed

src/kili/services/asset_import/video.py

Lines changed: 2 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from concurrent.futures import ThreadPoolExecutor
55
from enum import Enum
66
from itertools import repeat
7-
from json import JSONDecodeError
87
from typing import List, Optional
98

109
from kili.core.helpers import get_mime_type, is_url
@@ -168,101 +167,20 @@ def get_data_type(self, assets):
168167
return VideoDataType.HOSTED_FILE
169168
return VideoDataType.LOCAL_FILE
170169

171-
@staticmethod
172-
def are_native_videos(assets) -> bool:
173-
"""Determine if assets should be imported asynchronously and cut into frames."""
174-
should_use_native_video_array = []
175-
for asset in assets:
176-
# json_metadata stringification is done later on the call
177-
json_metadata_ = asset.get("json_metadata")
178-
if not json_metadata_:
179-
return False
180-
181-
processing_parameters = json_metadata_.get("processingParameters")
182-
if not processing_parameters:
183-
return False
184-
185-
should_use_native_video_array.append(
186-
processing_parameters.get("shouldUseNativeVideo", True)
187-
)
188-
if all(should_use_native_video_array):
189-
return True
190-
if all(not b for b in should_use_native_video_array):
191-
return False
192-
raise ImportValidationError(
193-
"""
194-
Cannot upload videos to split into frames
195-
and video to keep as native in the same time.
196-
Please separate the assets into 2 calls
197-
"""
198-
)
199-
200-
@staticmethod
201-
def has_complete_processing_parameters(asset) -> bool:
202-
"""Determine if assets should be imported asynchronously and cut into frames."""
203-
try:
204-
# json_metadata stringification is done later on the call
205-
json_metadata = asset.get("json_metadata")
206-
if not json_metadata:
207-
return False
208-
209-
processing_parameters = json_metadata.get("processingParameters")
210-
211-
if not processing_parameters:
212-
return False
213-
214-
required_keys = [
215-
"codec",
216-
"delayDueToMinPts",
217-
"framesPlayedPerSecond",
218-
"numberOfFrames",
219-
"startTime",
220-
]
221-
required_types = [str, (int, float), (int, float), (int, float), (int, float)]
222-
223-
for key, required_type in zip(required_keys, required_types):
224-
value = processing_parameters.get(key)
225-
if value is None or not isinstance(value, required_type):
226-
return False
227-
228-
if not float(processing_parameters.get("numberOfFrames")).is_integer():
229-
return False
230-
231-
return True
232-
except JSONDecodeError:
233-
return False
234-
235-
def videos_have_complete_processing_parameters(self, assets) -> bool:
236-
"""Determine if assets should be imported asynchronously and cut into frames."""
237-
for asset in assets:
238-
if not self.has_complete_processing_parameters(asset):
239-
return False
240-
return True
241-
242170
def import_assets(self, assets: List[AssetLike], input_type: InputType):
243171
"""Import video assets into Kili."""
244172
self._check_upload_is_allowed(assets)
245173
data_type = self.get_data_type(assets)
246174
assets = self.filter_duplicate_external_ids(assets)
247175
if data_type == VideoDataType.LOCAL_FILE:
248176
assets = self.filter_local_assets(assets, self.raise_error)
249-
are_native_videos = self.are_native_videos(assets)
250-
videos_have_complete_processing_parameters = (
251-
self.videos_have_complete_processing_parameters(assets)
252-
)
253-
is_synchronous = are_native_videos and videos_have_complete_processing_parameters
254-
batch_params = BatchParams(is_hosted=False, is_asynchronous=not is_synchronous)
177+
batch_params = BatchParams(is_hosted=False, is_asynchronous=True)
255178
batch_importer = VideoContentBatchImporter(
256179
self.kili, self.project_params, batch_params, self.pbar
257180
)
258181
batch_size = IMPORT_BATCH_SIZE
259182
elif data_type == VideoDataType.HOSTED_FILE:
260-
are_native_videos = self.are_native_videos(assets)
261-
videos_have_complete_processing_parameters = (
262-
self.videos_have_complete_processing_parameters(assets)
263-
)
264-
is_synchronous = are_native_videos and videos_have_complete_processing_parameters
265-
batch_params = BatchParams(is_hosted=True, is_asynchronous=not is_synchronous)
183+
batch_params = BatchParams(is_hosted=True, is_asynchronous=True)
266184
batch_importer = VideoContentBatchImporter(
267185
self.kili, self.project_params, batch_params, self.pbar
268186
)

0 commit comments

Comments
 (0)