How to Extract frames and set frames per seconds with .sh file

Viewed 37

I am trying to extract features from videos using a shell script file while extracting features from videos I don't know how to set frames per second.

#!/bin/bash
frames_folder_path=./data
videos_folder_path=./videos
ext=mp4

mkdir "${frames_folder_path}"

for video_file_path in "${videos_folder_path}"/*."${ext}"; do
    slash_and_video_file_name="${video_file_path:${#videos_folder_path}}"
    slash_and_video_file_name_without_extension="${slash_and_video_file_name%.${ext}}"
    video_frames_folder_path="${frames_folder_path}${slash_and_video_file_name_without_extension}";
    mkdir "${video_frames_folder_path}"
    ffmpeg -i "${video_file_path}" "${video_frames_folder_path}/%d.jpg"
done

I tried this code to extract the feature. I just want to extract 2 frames per second but It removes 30 frames per second with default frames rate.

How to resolve this issue with shell script file.

1 Answers

Add -r 2 between file path and output path, here 2 is frames per second( FPS )

ffmpeg -i "${video_file_path}" "${video_frames_folder_path}/%d.jpg"

use this

ffmpeg -i "${video_file_path}" -r 2 "${video_frames_folder_path}/%d.jpg"

#!/bin/bash
    frames_folder_path=./data
    videos_folder_path=./vid
    ext=mp4
    
    mkdir "${frames_folder_path}"
    
    for video_file_path in "${videos_folder_path}"/*."${ext}"; do
        slash_and_video_file_name="${video_file_path:${#videos_folder_path}}"
        slash_and_video_file_name_without_extension="${slash_and_video_file_name%.${ext}}"
        video_frames_folder_path="${frames_folder_path}${slash_and_video_file_name_without_extension}";
        mkdir "${video_frames_folder_path}"
        ffmpeg -i  "${video_file_path}" -r 2 "${video_frames_folder_path}/%d.jpg" 
    done
Related