Exposed number of actual frames to extract with ffmpeg for more transparency (#1683)

* Exposed number of actual frames to extract for more transparency

* Fixed off-by-one error in calculation of frames to extract.

* Added math import

* Switched print statements to CONSOLE.print

---------

Co-authored-by: jackson-waschura <jwaschur@calpoly.edu>
This commit is contained in:
Jackson Waschuraandjackson-waschura authored and GitHub committed 2023-04-01 16:29:33 -07:00
1 parent e104a3029e
commit 4564ade1fe
1 file changed
+3 -1
@@ -14,6 +14,7 @@
"""Helper utils for processing data into the nerfstudio format.""" """Helper utils for processing data into the nerfstudio format."""
import math
import os import os
import shutil import shutil
import sys import sys
@@ -141,7 +142,7 @@ def convert_video_to_images(
if num_frames == 0: if num_frames == 0:
CONSOLE.print(f"[bold red]Error: Video has no frames: {video_path}") CONSOLE.print(f"[bold red]Error: Video has no frames: {video_path}")
sys.exit(1) sys.exit(1)
print("Number of frames in video:", num_frames) CONSOLE.print("Number of frames in video:", num_frames)
out_filename = image_dir / "frame_%05d.png" out_filename = image_dir / "frame_%05d.png"
ffmpeg_cmd = f'ffmpeg -i "{video_path}"' ffmpeg_cmd = f'ffmpeg -i "{video_path}"'
@@ -157,6 +158,7 @@ def convert_video_to_images(
spacing = num_frames // num_frames_target spacing = num_frames // num_frames_target
if spacing > 1: if spacing > 1:
ffmpeg_cmd += f" -vf thumbnail={spacing},setpts=N/TB{crop_cmd} -r 1" ffmpeg_cmd += f" -vf thumbnail={spacing},setpts=N/TB{crop_cmd} -r 1"
CONSOLE.print("Number of frames to extract:", math.ceil(num_frames / spacing))
else: else:
CONSOLE.print("[bold red]Can't satisfy requested number of frames. Extracting all frames.") CONSOLE.print("[bold red]Can't satisfy requested number of frames. Extracting all frames.")
ffmpeg_cmd += " -pix_fmt bgr8" ffmpeg_cmd += " -pix_fmt bgr8"