Skip to content

Commit

Permalink
double-quote filenames in process-data commands so that on Windows, p…
Browse files Browse the repository at this point in the history
…aths with spaces don't fail (nerfstudio-project#1347)

* double-quote filenames in commands so that on Windows, paths with spaces don't fail

* reformatting by black
  • Loading branch information
machenmusik authored Feb 4, 2023
1 parent ab355e4 commit f7ee1a2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions nerfstudio/process_data/process_data_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ def get_num_frames_in_video(video: Path) -> int:
Returns:
The number of frames in a video.
"""
cmd = f"ffprobe -v error -select_streams v:0 -count_packets \
-show_entries stream=nb_read_packets -of csv=p=0 {video}"
cmd = f'ffprobe -v error -select_streams v:0 -count_packets \
-show_entries stream=nb_read_packets -of csv=p=0 "{video}"'
output = run_command(cmd)
assert output is not None
output = output.strip(" ,\t\n\r")
Expand Down Expand Up @@ -114,7 +114,7 @@ def convert_video_to_images(
print("Number of frames in video:", num_frames)

out_filename = image_dir / "frame_%05d.png"
ffmpeg_cmd = f"ffmpeg -i {video_path}"
ffmpeg_cmd = f'ffmpeg -i "{video_path}"'
spacing = num_frames // num_frames_target

if spacing > 1:
Expand Down Expand Up @@ -168,7 +168,7 @@ def copy_images_list(
file_type = image_paths[0].suffix
filename = f"frame_%05d{file_type}"
crop = f"crop=iw-{crop_border_pixels*2}:ih-{crop_border_pixels*2}"
ffmpeg_cmd = f"ffmpeg -y -noautorotate -i {image_dir / filename} -q:v 2 -vf {crop} {image_dir / filename}"
ffmpeg_cmd = f'ffmpeg -y -noautorotate -i "{image_dir / filename}" -q:v 2 -vf {crop} "{image_dir / filename}"'
run_command(ffmpeg_cmd, verbose=verbose)

num_frames = len(image_paths)
Expand Down Expand Up @@ -210,9 +210,9 @@ def copy_and_upscale_polycam_depth_maps_list(
for idx, depth_map in enumerate(polycam_depth_image_filenames):
destination = depth_dir / f"frame_{idx + 1:05d}{depth_map.suffix}"
ffmpeg_cmd = [
f"ffmpeg -y -i {depth_map} ",
f'ffmpeg -y -i "{depth_map}" ',
f"-q:v 2 -vf scale=iw*{upscale_factor}:ih*{upscale_factor}:flags=neighbor ",
f"{destination}",
f'"{destination}"',
]
ffmpeg_cmd = " ".join(ffmpeg_cmd)
run_command(ffmpeg_cmd, verbose=verbose)
Expand All @@ -222,7 +222,7 @@ def copy_and_upscale_polycam_depth_maps_list(
file_type = depth_dir.glob("frame_*").__next__().suffix
filename = f"frame_%05d{file_type}"
crop = f"crop=iw-{crop_border_pixels * 2}:ih-{crop_border_pixels * 2}"
ffmpeg_cmd = f"ffmpeg -y -i {depth_dir / filename} -q:v 2 -vf {crop} {depth_dir / filename}"
ffmpeg_cmd = f'ffmpeg -y -i "{depth_dir / filename}" -q:v 2 -vf {crop} "{depth_dir / filename}"'
run_command(ffmpeg_cmd, verbose=verbose)

CONSOLE.log("[bold green]:tada: Done upscaling depth maps.")
Expand Down Expand Up @@ -282,9 +282,9 @@ def downscale_images(image_dir: Path, num_downscales: int, folder_name: str = "i
for f in files:
filename = f.name
ffmpeg_cmd = [
f"ffmpeg -y -noautorotate -i {image_dir / filename} ",
f'ffmpeg -y -noautorotate -i "{image_dir / filename}" ',
f"-q:v 2 -vf scale=iw/{downscale_factor}:ih/{downscale_factor} ",
f"{downscale_dir / filename}",
f'"{downscale_dir / filename}"',
]
ffmpeg_cmd = " ".join(ffmpeg_cmd)
run_command(ffmpeg_cmd, verbose=verbose)
Expand Down
2 changes: 1 addition & 1 deletion scripts/process_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def main(self) -> None:
if not filename_back.exists():
raise FileNotFoundError(f"Could not find {filename_back}")

ffprobe_cmd = f"ffprobe -v quiet -print_format json -show_streams -select_streams v:0 {filename_back}"
ffprobe_cmd = f'ffprobe -v quiet -print_format json -show_streams -select_streams v:0 "{filename_back}"'

ffprobe_output = process_data_utils.run_command(ffprobe_cmd)

Expand Down

0 comments on commit f7ee1a2

Please sign in to comment.