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

Function temporal_concat_video

detrsmpl/utils/ffmpeg_utils.py:1195–1259  ·  view source on GitHub ↗

Concat no matter videos or gifs into a temporal sequence, and save as a new video or gif file. Args: input_path_list (List[str]): list of input video paths. output_path (str): output video file path. resolution (Optional[Union[Tuple[int, int], Tuple[float, float]]]

(input_path_list: List[str],
                          output_path: str,
                          resolution: Union[Tuple[int, int],
                                            Tuple[float, float]] = (512, 512),
                          remove_raw_files: bool = False,
                          disable_log: bool = False)

Source from the content-addressed store, hash-verified

1193
1194
1195def temporal_concat_video(input_path_list: List[str],
1196 output_path: str,
1197 resolution: Union[Tuple[int, int],
1198 Tuple[float, float]] = (512, 512),
1199 remove_raw_files: bool = False,
1200 disable_log: bool = False) -> None:
1201 """Concat no matter videos or gifs into a temporal sequence, and save as a
1202 new video or gif file.
1203
1204 Args:
1205 input_path_list (List[str]): list of input video paths.
1206 output_path (str): output video file path.
1207 resolution (Optional[Union[Tuple[int, int], Tuple[float, float]]]
1208 , optional): (height, width) of output].
1209 Defaults to (512,512).
1210 remove_raw_files (bool, optional): whether remove the input videos.
1211 Defaults to False.
1212 disable_log (bool, optional): whether close the ffmepg command info.
1213 Defaults to False.
1214 Raises:
1215 FileNotFoundError: check the input path.
1216 FileNotFoundError: check the output path.
1217
1218 Returns:
1219 None.
1220 """
1221 for path in input_path_list:
1222 check_input_path(
1223 path,
1224 allowed_suffix=['.gif', '.mp4'],
1225 tag='input video',
1226 path_type='file')
1227 prepare_output_path(
1228 output_path,
1229 allowed_suffix=['.gif', '.mp4'],
1230 tag='output video',
1231 path_type='file',
1232 overwrite=True)
1233
1234 height, width = resolution
1235 command = ['ffmpeg']
1236 concat_command = []
1237 scale_command = []
1238 for index, vid_file in enumerate(input_path_list):
1239 command.append('-i')
1240 command.append(vid_file)
1241 scale_command.append(
1242 '[%d:v]scale=%d:%d:force_original_aspect_ratio=0[v%d];' %
1243 (index, width, height, index))
1244 concat_command.append('[v%d]' % index)
1245 concat_command = ''.join(concat_command)
1246 scale_command = ''.join(scale_command)
1247 command += [
1248 '-filter_complex',
1249 '%s%sconcat=n=%d:v=1:a=0[v]' %
1250 (scale_command, concat_command, len(input_path_list)), '-loglevel',
1251 'error', '-map', '[v]', '-c:v', 'libx264', '-y', output_path
1252 ]

Callers

nothing calls this directly

Calls 3

check_input_pathFunction · 0.90
prepare_output_pathFunction · 0.90
printFunction · 0.50

Tested by

no test coverage detected