output: need video_name
(inputs, frame_rate, output, format="png")
| 11 | VIDEO_TYPE_LIST = {'.avi','.mp4','.gif','.AVI','.MP4','.GIF'} |
| 12 | |
| 13 | def encodeffmpeg(inputs, frame_rate, output, format="png"): |
| 14 | """output: need video_name""" |
| 15 | assert ( |
| 16 | os.path.splitext(output)[-1] in VIDEO_TYPE_LIST |
| 17 | ), "output is the format of video, e.g., mp4" |
| 18 | assert os.path.isdir(inputs), "input dir is NOT file format" |
| 19 | |
| 20 | inputs = inputs[:-1] if inputs[-1] == "/" else inputs |
| 21 | |
| 22 | output = os.path.abspath(output) |
| 23 | |
| 24 | cmd = ( |
| 25 | f"ffmpeg -r {frame_rate} -pattern_type glob -i '{inputs}/*.{format}' " |
| 26 | + f'-vcodec libx264 -crf 10 -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" ' |
| 27 | + f"-pix_fmt yuv420p {output} > /dev/null 2>&1" |
| 28 | ) |
| 29 | |
| 30 | print(cmd) |
| 31 | |
| 32 | output_dir = os.path.dirname(output) |
| 33 | if os.path.exists(output): |
| 34 | os.remove(output) |
| 35 | os.makedirs(output_dir, exist_ok=True) |
| 36 | |
| 37 | print("encoding imgs to video.....") |
| 38 | os.system(cmd) |
| 39 | print("video done!") |
| 40 | |
| 41 | def images_to_video(images, output_path, fps, gradio_codec: bool, verbose=False, bitrate="10M"): |
| 42 | os.makedirs(os.path.dirname(output_path), exist_ok=True) |