-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvideoToImagePoster.sh
More file actions
executable file
·83 lines (70 loc) · 2.6 KB
/
videoToImagePoster.sh
File metadata and controls
executable file
·83 lines (70 loc) · 2.6 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
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
source @includes.sh
echo '###################################################'
echo '# Description: Extract a poster frame from a video or videos in a directory'
echo '# Usage: $ ./videoToImagePoster.sh /path/to/video.mov [2.0]'
echo '# $ ./videoToImagePoster.sh /path/to/videos/directory [2.0]'
echo '# Param 1: Video file or directory containing video files'
echo '# Param 2 [Optional]: Time in seconds'
echo '# Requires: ffmpeg'
echo '###################################################'
echoNewline
################################################################################
################################################################################
# check parameters & set defaults
if [[ $1 == "" ]] ; then
echoError '1st arg must be a video file or directory'
exit 1
fi
extractTime=0
if [[ -z "$2" ]] ; then
echoInfo "[Optional]: Using default frametime of ${extractTime} seconds"
else
extractTime=$2
fi
################################################################################
################################################################################
# Function to process a single video file
processPosterFrame() {
local videoFile="$1"
local extractTime="$2"
# Skip if file doesn't exist
if [ ! -f "$videoFile" ]; then
echoError "File not found: $videoFile"
return 1
fi
# Get filename and create output filename
local filename="$videoFile"
local extension=$(extension "$filename")
local outputFile="$filename.$extractTime.jpg"
echoInfo "Saving thumbnail for movie: $filename at $extractTime seconds"
# Do conversion
ffmpeg -ss "$extractTime" -i "$videoFile" -t 1 -q:v 0 -f image2 "$outputFile"
if [ $? -eq 0 ]; then
echoSuccess "Extracted poster frame at $extractTime seconds: \n# $outputFile"
return 0
else
echoError "Failed to extract poster frame from: $videoFile"
return 1
fi
}
# Check if path is a directory or a file
if [ -d "$1" ]; then
# Process directory
echoInfo "Processing all video files in directory: $1"
# Process all video files in the directory
for file in "$1"/*.{mp4,mov,avi,mkv,wmv}; do
# Skip if no matches found
[ -e "$file" ] || continue
echoNewline
echoInfo "Processing: $file"
# Process the file
processPosterFrame "$file" "$extractTime"
done
echoNewline
echoSuccess "Finished processing all videos in directory: $1"
else
echoInfo "Processing file: $1"
# Process single file
processPosterFrame "$1" "$extractTime"
fi