From 9252a46273a6970d255e7cca9fc01bd90a0ae11d Mon Sep 17 00:00:00 2001 From: Matthew Tancik Date: Thu, 6 Oct 2022 09:41:36 -0700 Subject: [PATCH] Check ffmpeg before rendering video (#715) * check ffmpeg before rendering video * Fix imports --- nerfstudio/utils/install_checks.py | 41 ++++++++++++++++++++++++++++++ scripts/process_data.py | 25 +++--------------- scripts/render.py | 3 +++ 3 files changed, 47 insertions(+), 22 deletions(-) create mode 100644 nerfstudio/utils/install_checks.py diff --git a/nerfstudio/utils/install_checks.py b/nerfstudio/utils/install_checks.py new file mode 100644 index 000000000..0372130a8 --- /dev/null +++ b/nerfstudio/utils/install_checks.py @@ -0,0 +1,41 @@ +# Copyright 2022 The Nerfstudio Team. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Helpers for checking if programs are installed""" + +import shutil +import sys + +from rich.console import Console + +console = Console(width=120) + + +def check_ffmpeg_installed(): + """Checks if ffmpeg is installed.""" + ffmpeg_path = shutil.which("ffmpeg") + if ffmpeg_path is None: + console.print("[bold red]Could not find ffmpeg. Please install ffmpeg.") + print("See https://ffmpeg.org/download.html for installation instructions.") + print("ffmpeg is only necessary if using videos as input.") + sys.exit(1) + + +def check_colmap_installed(): + """Checks if colmap is installed.""" + colmap_path = shutil.which("colmap") + if colmap_path is None: + console.print("[bold red]Could not find COLMAP. Please install COLMAP.") + print("See https://colmap.github.io/install.html for installation instructions.") + sys.exit(1) diff --git a/scripts/process_data.py b/scripts/process_data.py index 2726b5bb5..9ebb8e43a 100755 --- a/scripts/process_data.py +++ b/scripts/process_data.py @@ -16,7 +16,7 @@ import tyro from rich.console import Console from rich.progress import track -from nerfstudio.utils import colmap_utils +from nerfstudio.utils import colmap_utils, install_checks CONSOLE = Console(width=120) @@ -34,25 +34,6 @@ CAMERA_MODELS = { } -def check_ffmpeg_installed(): - """Checks if ffmpeg is installed.""" - ffmpeg_path = shutil.which("ffmpeg") - if ffmpeg_path is None: - CONSOLE.print("[bold red]Could not find ffmpeg. Please install ffmpeg.") - print("See https://ffmpeg.org/download.html for installation instructions.") - print("ffmpeg is only necissary if using videos as input.") - sys.exit(1) - - -def check_colmap_installed(): - """Checks if colmap is installed.""" - colmap_path = shutil.which("colmap") - if colmap_path is None: - CONSOLE.print("[bold red]Could not find COLMAP. Please install COLMAP.") - print("See https://colmap.github.io/install.html for installation instructions.") - sys.exit(1) - - def get_colmap_version(default_version=3.8) -> float: """Returns the version of COLMAP. This code assumes that colmap returns a version string of the form @@ -408,8 +389,8 @@ def main( verbose: If True, print extra logging. """ - check_ffmpeg_installed() - check_colmap_installed() + install_checks.check_ffmpeg_installed() + install_checks.check_colmap_installed() output_dir.mkdir(parents=True, exist_ok=True) image_dir = output_dir / "images" diff --git a/scripts/render.py b/scripts/render.py index 24ae21edc..7db0ea87d 100644 --- a/scripts/render.py +++ b/scripts/render.py @@ -28,6 +28,7 @@ from nerfstudio.cameras.camera_paths import get_path_from_json, get_spiral_path from nerfstudio.cameras.cameras import Cameras from nerfstudio.configs.base_config import Config # pylint: disable=unused-import from nerfstudio.pipelines.base_pipeline import Pipeline +from nerfstudio.utils import install_checks from nerfstudio.utils.eval_utils import eval_setup from nerfstudio.utils.rich_utils import ItersPerSecColumn @@ -116,6 +117,8 @@ class RenderTrajectory: eval_num_rays_per_chunk=self.eval_num_rays_per_chunk, ) + install_checks.check_ffmpeg_installed() + seconds = self.seconds # TODO(ethan): use camera information from parsing args