diff --git a/run.sh b/run.sh index 54d3f9a..06bbd08 100644 --- a/run.sh +++ b/run.sh @@ -128,6 +128,7 @@ for COLMAP_MATCHER in sequential exhaustive; do mkdir $SCENE_PATH/colmap_$COLMAP_MATCHER fi ( + CONFIG_NGP_PATH=$(realpath $CONFIG_NGP_PATH) cd $SCENE_PATH && python $CONFIG_NGP_PATH/scripts/colmap2nerf.py \ --run_colmap \ diff --git a/scripts/extract_all_frames.py b/scripts/extract_all_frames.py new file mode 100644 index 0000000..7a34ab9 --- /dev/null +++ b/scripts/extract_all_frames.py @@ -0,0 +1,58 @@ +import subprocess +import os +import sys + + +def extract_frames(video_path, downsample_factor=2): + # Ensure the ffmpeg is installed + if subprocess.call(["which", "ffmpeg"]) != 0: + print("ffmpeg is not installed. Please install ffmpeg to use this script.") + sys.exit(1) + + # Check if the video file exists + if not os.path.exists(video_path): + print(f"The video file {video_path} does not exist.") + sys.exit(1) + + # Define the output folder based on the video file's path + base_path = os.path.dirname(video_path) + output_folder = os.path.join(base_path, "images") + + # Create the output folder if it doesn't exist + if not os.path.exists(output_folder): + os.makedirs(output_folder) + + # Construct the ffmpeg command + output_pattern = os.path.join(output_folder, f"%06d.jpg") + ffmpeg_cmd = [ + "ffmpeg", + "-i", + video_path, + "-vf", + f"scale=iw/{downsample_factor}:ih/{downsample_factor}", + "-qscale:v", + "1", # Set the quality scale for video streams to the highest quality + "-start_number", + "0", # Start numbering from 000000 + output_pattern, + ] + + # Execute the ffmpeg command + try: + subprocess.run(ffmpeg_cmd, check=True) + print(f"Frames extracted successfully into {output_folder}") + except subprocess.CalledProcessError as e: + print(f"An error occurred during frame extraction: {e}") + sys.exit(1) + + +if __name__ == "__main__": + if len(sys.argv) < 2 or len(sys.argv) > 3: + print( + "Usage: python extract_all_frames.py [OPTIONAL: downsample_factor]" + ) + sys.exit(1) + + video_path = sys.argv[1] + downsample_factor = sys.argv[2] if len(sys.argv) == 3 else 2 + extract_frames(video_path, downsample_factor)