← All articles
Published June 26, 2024by MassBrainImpact
How I managed to get frames for my Gura, Alpha Lexa, and Leiko Pony LoRAs (Video To Frames)
160 views0 reactions0 comments on CivitAI2 collected
codedata prepdata preparation

So, as promised, here's the code I used to take a video (an MP4 preferably) and convert them into frames:
# Specify the path to your video file and destination folder (replace with yours)
video_path = '/content/gdrive/MyDrive/[insert folder here]/[insert one word filename here].mp4'
destination_folder = '/content/gdrive/MyDrive/[insert folder here]/[insert resulting folder here]'
# Create the destination folder if it doesn't exist
!mkdir -p {destination_folder}
# Frame extraction using ffmpeg (assuming ffmpeg is available)
!ffmpeg -i {video_path} -vf "select='not(mod(n\,10))'" -vsync vfr {destination_folder}/sharkd%03d.png
print(f"Extracted frames and saved to {destination_folder}")It's programed to extract every ten frames, since every single frame or every few frames would be overkill, but feel free to tweak it however you wish. This can also be perfect for screencapping if you have a few episodes lying around.