"scripts/vscode:/vscode.git/clone" did not exist on "c480a3f6ea1be75d683551cdc7491aef2cf312e5"
Commit 343c2cea authored by gaclove's avatar gaclove
Browse files

Enhance array_to_video function with detailed docstring and output pixel format option

parent 397ce244
...@@ -137,7 +137,27 @@ def array_to_video( ...@@ -137,7 +137,27 @@ def array_to_video(
resolution: Optional[Union[Tuple[int, int], Tuple[float, float]]] = None, resolution: Optional[Union[Tuple[int, int], Tuple[float, float]]] = None,
disable_log: bool = False, disable_log: bool = False,
lossless: bool = True, lossless: bool = True,
output_pix_fmt: str = "yuv420p",
) -> None: ) -> None:
"""Convert an array to a video directly, gif not supported.
Args:
image_array (np.ndarray): shape should be (f * h * w * 3).
output_path (str): output video file path.
fps (Union[int, float, optional): fps. Defaults to 30.
resolution (Optional[Union[Tuple[int, int], Tuple[float, float]]],
optional): (height, width) of the output video.
Defaults to None.
disable_log (bool, optional): whether close the ffmepg command info.
Defaults to False.
output_pix_fmt (str): output pix_fmt in ffmpeg command.
Raises:
FileNotFoundError: check output path.
TypeError: check input array.
Returns:
None.
"""
if not isinstance(image_array, np.ndarray): if not isinstance(image_array, np.ndarray):
raise TypeError("Input should be np.ndarray.") raise TypeError("Input should be np.ndarray.")
assert image_array.ndim == 4 assert image_array.ndim == 4
...@@ -175,6 +195,7 @@ def array_to_video( ...@@ -175,6 +195,7 @@ def array_to_video(
output_path, output_path,
] ]
else: else:
output_pix_fmt = output_pix_fmt or "yuv420p"
command = [ command = [
"/usr/bin/ffmpeg", "/usr/bin/ffmpeg",
"-y", # (optional) overwrite output file if it exists "-y", # (optional) overwrite output file if it exists
...@@ -194,6 +215,8 @@ def array_to_video( ...@@ -194,6 +215,8 @@ def array_to_video(
"-", # The input comes from a pipe "-", # The input comes from a pipe
"-vcodec", "-vcodec",
"libx264", "libx264",
"-pix_fmt",
f"{output_pix_fmt}",
"-an", # Tells FFMPEG not to expect any audio "-an", # Tells FFMPEG not to expect any audio
output_path, output_path,
] ]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment