MCPcopy Create free account
hub / github.com/MotrixLab/AiOS / pad_for_libx264

Function pad_for_libx264

detrsmpl/utils/ffmpeg_utils.py:1331–1376  ·  view source on GitHub ↗

Pad zeros if width or height of image_array is not divisible by 2. Otherwise you will get. \"[libx264 @ 0x1b1d560] width not divisible by 2 \" Args: image_array (np.ndarray): Image or images load by cv2.imread(). Possible shapes: 1. [height,

(image_array)

Source from the content-addressed store, hash-verified

1329
1330
1331def pad_for_libx264(image_array):
1332 """Pad zeros if width or height of image_array is not divisible by 2.
1333 Otherwise you will get.
1334
1335 \"[libx264 @ 0x1b1d560] width not divisible by 2 \"
1336
1337 Args:
1338 image_array (np.ndarray):
1339 Image or images load by cv2.imread().
1340 Possible shapes:
1341 1. [height, width]
1342 2. [height, width, channels]
1343 3. [images, height, width]
1344 4. [images, height, width, channels]
1345
1346 Returns:
1347 np.ndarray:
1348 A image with both edges divisible by 2.
1349 """
1350 if image_array.ndim == 2 or \
1351 (image_array.ndim == 3 and image_array.shape[2] == 3):
1352 hei_index = 0
1353 wid_index = 1
1354 elif image_array.ndim == 4 or \
1355 (image_array.ndim == 3 and image_array.shape[2] != 3):
1356 hei_index = 1
1357 wid_index = 2
1358 else:
1359 return image_array
1360 hei_pad = image_array.shape[hei_index] % 2
1361 wid_pad = image_array.shape[wid_index] % 2
1362 if hei_pad + wid_pad > 0:
1363 pad_width = []
1364 for dim_index in range(image_array.ndim):
1365 if dim_index == hei_index:
1366 pad_width.append((0, hei_pad))
1367 elif dim_index == wid_index:
1368 pad_width.append((0, wid_pad))
1369 else:
1370 pad_width.append((0, 0))
1371 values = 0
1372 image_array = \
1373 np.pad(image_array,
1374 pad_width,
1375 mode='constant', constant_values=values)
1376 return image_array

Callers 1

array_to_videoFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected