in preprocess.py [0:0]
def video_preprocessing(args):
video_path = args.input
output_folder = args.output
ffmpeg_path = args.ffmpeg_path
# extract frames
images_folder = os.path.join(output_folder, "images/")
create_folder(images_folder)
from subprocess import run, check_output, STDOUT, DEVNULL
command = ""
# command += "-i " + video_path + " -f image2 -qscale:v 1 -qmin 1 " + images_folder + "image%05d.jpg" # highest quality and all images.
command += (
"-i "
+ video_path
+ " -f image2 -qscale:v 2 -vf fps="
+ str(args.fps)
+ " "
+ images_folder
+ "image%05d.png"
)
# command += "-i " + video_path + ' -f image2 -qscale:v 2 -vf "fps=' + str(args.fps) + ', crop=in_w:3/4*in_h:0:in_h/4" ' + images_folder + "image%05d.png" # crop
print(command, flush=True)
try:
ffmpeg_output = check_output([ffmpeg_path] + command.split(" "), stderr=STDOUT)
except:
run(ffmpeg_path + " " + command)
# take care of failed frames
failed_frames_folder = os.path.join(output_folder, "images_failed/")
if os.path.exists(failed_frames_folder):
failed_frame_names = os.listdir(failed_frames_folder)
print(
"detected failed frames, will delete: " + str(failed_frame_names),
flush=True,
)
[
os.remove(os.path.join(images_folder, failed_frame))
for failed_frame in failed_frame_names
]
# create videos using ffmpeg
print("creating full-resolution RGB video...", flush=True)
command = ""
command += (
"-framerate " + str(args.fps) + " -i " + images_folder + "image%05d.png -y "
) # -y overwrites existing files automatically
command += os.path.join(output_folder, "rgb_scene_fullres.mp4")
try:
ffmpeg_output = check_output([ffmpeg_path] + command.split(" "), stderr=STDOUT)
except:
run(ffmpeg_path + " " + command)