-
Notifications
You must be signed in to change notification settings - Fork 10
/
ffmpeg.sh
executable file
·89 lines (74 loc) · 2.47 KB
/
ffmpeg.sh
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
# Check if deps are installed
sudo dpkg -l | grep -qw ffmpeg || sudo apt-get install ffmpeg -y
# Function to avoid repating the code
ffmpeg_func() {
# Get video's path
read -e -p "Drag & drop your video file: " video_file
eval video_file="$video_file"
# Echo the video's path
echo Full path: "$video_file"
# Get the filename without the extension
video_file_name=$(basename "$video_file")
video_file_name_without_ext="${video_file_name%.*}"
# Check if the folder already exists
if [ -d "/tmp/extracted_video/$video_file_name_without_ext" ]; then
while [ -z "$prompt" ]; do
read -p "This folder already exists! Overwrite it? (y/n): " choice
case "$choice" in
y|Y )
rm -rf "/tmp/extracted_video/$video_file_name_without_ext"
mkdir -p "/tmp/extracted_video/$video_file_name_without_ext"
break
;;
n|N )
exit 0
;;
esac
done
else
mkdir -p "/tmp/extracted_video/$video_file_name_without_ext"
fi
# Cd into it
cd "/tmp/extracted_video/$video_file_name_without_ext"
}
mainmenu() {
echo -ne "
1) Output every single frame
2) Output one image every x second or x minute
0) Exit
Choose an option: "
read -r ans
case $ans in
1)
ffmpeg_func
# EXtract every single frame from the selected video
ffmpeg -i "$video_file" "frame%d.png"
echo "The output is inside /tmp/extracted_video/$video_file_name_without_ext"
;;
2)
ffmpeg_func
echo ""
echo "Examples"
echo ""
echo "To output one image every second enter 1 when asked"
echo "To output one image every minute enter 1/60 when asked"
echo "To output one image every 10 minutes enter 1/600 when asked"
echo ""
# Ask to the user
read -p "Defines the time : " selected_time
# Output one image every x second or minute
ffmpeg -i "$video_file" -vf fps="$selected_time" "out%d.png"
echo "The output is inside /tmp/extracted_video/$video_file_name_without_ext"
;;
0)
echo "Bye bye."
exit 0
;;
*)
echo "Wrong option."
mainmenu
;;
esac
}
mainmenu