From 8b320cf0992a7b41a573aa4d008f024d11f7b0c4 Mon Sep 17 00:00:00 2001 From: Viner Abubakirov Date: Wed, 1 Apr 2026 18:43:01 +0500 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BC=D0=B5=D1=89=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B8=D0=B7=D0=BE=D0=B1=D1=80=D0=B0=D0=B6?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=B8=20=D1=81=D0=B1=D0=BE=D1=80?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=B2=D0=B8=D0=B4=D0=B5=D0=BE=20=D1=81=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=BC=D0=BE=D1=89=D1=8C=D1=8E=20ffmpeg;=20=D1=83=D0=BB?= =?UTF-8?q?=D1=83=D1=87=D1=88=D0=B5=D0=BD=D0=BE=20=D0=BB=D0=BE=D0=B3=D0=B8?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 55209ad..47a7a65 100644 --- a/main.py +++ b/main.py @@ -169,7 +169,7 @@ def main(): prev_frame_path = None frame_count = 0 for frame_paths in video_frames_to_disk_generator(video_path, output_dir): - logging.info(f"Processing frames: {frame_paths}") + logging.info(f"Processing frames: {len(frame_paths)}") if prev_frame_path is not None: img1 = prev_frame_path[-1] @@ -193,12 +193,47 @@ def main(): def builder(): frames_dir = "output/frames" interpolated_dir = "output/interpolated" - list_path = "file_list.txt" + moved_dir = "output/moved" video_path = "source/video.mp4" output_video = "output/interpolated_video.mp4" - build_file_list('output/moved_frames', list_path) - merge_with_ffmpeg(video_path, list_path, output_video) + move_images(frames_dir, interpolated_dir, moved_dir) + cap = cv2.VideoCapture(video_path) + + if not cap.isOpened(): + raise ValueError("Cannot open original video") + + fps = cap.get(cv2.CAP_PROP_FPS) + cmd = [ + "ffmpeg", + "-y", + "-framerate", str(fps * 2), + "-i", f"{moved_dir}/img_%08d.png", + "-i", video_path, + "-c:v", "libx264", + "-c:a", "copy", + "-shortest", + output_video, + ] + logging.info("Running ffmpeg command to build final video: " + " ".join(cmd)) + subprocess.run(cmd, check=True) + + +def cleanup(): + import os + import shutil + frames_dir = "output/frames" + interpolated_dir = "output/interpolated" + moved_dir = "output/moved" + os.makedirs(frames_dir, exist_ok=True) + os.makedirs(interpolated_dir, exist_ok=True) + os.makedirs(moved_dir, exist_ok=True) + shutil.rmtree(frames_dir) + shutil.rmtree(interpolated_dir) + shutil.rmtree(moved_dir) if __name__ == "__main__": + cleanup() main() + builder() + cleanup()