7. Additional Tools¶
Latest update : 13.6.2021
Extracting frames (FFMPEG)¶
In a video edior for post-processing, you might want to have the first frame as an image. This can be achieved with the following script, which will batch-process all videos in the Downloads folder and extract all first frames to the folder “Downloads/processed”
[1]:
from pathlib import Path
import os
suffix = ".mp4"
input_path= Path.home() / "Downloads/"
file_paths= [subp for subp in input_path.rglob('*') if suffix == subp.suffix]
if len(file_paths) == 0:
raise ValueError("No videos in folder")
file_paths.sort()
print(file_paths)
output_path = Path.home() / "Downloads/processed"
output_path.mkdir(parents=True, exist_ok=True)
print(output_path)
for file_p in file_paths:
input = str(file_p)
output = str( output_path / file_p.name)
output = output[:-4] # delete the ending
print(output)
command = f"ffmpeg -i {input} -vframes 1 {output}.png"
os.system(command)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/tmp/ipykernel_2662/4206570128.py in <module>
5 file_paths= [subp for subp in input_path.rglob('*') if suffix == subp.suffix]
6 if len(file_paths) == 0:
----> 7 raise ValueError("No videos in folder")
8 file_paths.sort()
9 print(file_paths)
ValueError: No videos in folder