-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_dataset.sh
More file actions
71 lines (64 loc) · 1.93 KB
/
Copy pathmake_dataset.sh
File metadata and controls
71 lines (64 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
function printUsageAndExit {
echo "Usage: bash $0 input_video_folder [output_image_folder num_frames_per_video]"
exit -1
}
# Ensure ffmpeg is installed
if ! command -v ffmpeg &> /dev/null
then
echo "ffmpeg not found. Please install ffmpeg to use this script."
exit -1
fi
echo "cabird num args: $#"
if [ $# -lt 1 ]; then
printUsageAndExit
fi
ffmpeg_path=$(dirname `which ffmpeg`)
# Video counter
video_counter=0
if [ $# -gt 0 ]; then
video_path=$1
if [ ! -d $video_path ]; then
echo "cannot find existing input directory: ${video_path}"
exit -1
fi
else
printUsageAndExit
fi
if [ $# -gt 1 ]; then
out_frame_path=$2
else
out_frame_path=$(dirname $1)
out_frame_folder=$(basename $1)_images
out_frame_path=${out_frame_path}/${out_frame_folder}
fi
if [ $# -gt 2 ]; then
frame_nums_per_video=$3
else
frame_nums_per_video=8
fi
if [ ! -d $out_frame_path ]; then
echo "$out_frame_path does not exist, creating it"
mkdir -p $out_frame_path
if [ ! -d $out_frame_path ]; then
echo "cannot create diretory: ${out_frame_path}"
echo -1
fi
fi
echo "ffmpeg path: $ffmpeg_path"
echo "input video folder: $video_path"
echo "output image folder: $out_frame_path"
echo "frames per video: $frame_nums_per_video"
cd ${ffmpeg_path}
# Process each video file in the current directory
for video in ${video_path}/*.mp4
do
echo "cabird video: ${video}"
duration=$(ffprobe -v error -select_streams v:0 -show_entries format=duration -of csv=p=0 "$video")
interval=$(echo "$duration / $frame_nums_per_video" | bc -l)
filename=$(basename -- "$video")
prefix="${filename%.*}"
#extract frame_nums_per_video frames at the same time interval
ffmpeg -i "$video" -vf "sws_flags=lanczos+accurate_rnd+full_chroma_int:sws_dither=none:param0=5; fps=1/$interval" -vframes ${frame_nums_per_video} "$out_frame_path/${prefix}_%03d.png"
echo "Extracted frames for $video"
done