-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvideoToImageSequence.sh
More file actions
executable file
·52 lines (44 loc) · 1.69 KB
/
videoToImageSequence.sh
File metadata and controls
executable file
·52 lines (44 loc) · 1.69 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
#!/bin/bash
source @includes.sh
echo '###################################################'
echo '# Description: Extract image sequence from a video'
echo '# Usage: $ ./videoToImageSequence.sh /path/to/video.mov [jpg]'
echo '# Param 1: Video file'
echo '# Param 2 [Optional]: Output file format [jpg]'
echo '# Requires: ffmpeg'
echo '###################################################'
echoNewline
################################################################################
################################################################################
# check parameters & set defaults
if [[ $1 == "" ]] ; then
echoError '1st arg must be a video file'
exit 1
fi
outputFormat="png"
if [[ $2 == "" ]] ; then
echoInfo "[Optional]: Using default image format of $outputFormat"
else
outputFormat=$2
fi
################################################################################
################################################################################
# get filename
filename=$1
extension=$(extension $filename)
echoInfo "Saving images from video: $filename"
# create output directory
newDir="$filename-frames"
mkdir $newDir
echoInfo "Created directory: $newDir"
# do conversion
if [ $outputFormat = "jpg" ]; then
# jpeg quality info: http://stackoverflow.com/questions/10225403/how-can-i-extract-a-good-quality-jpeg-image-from-an-h264-video-file-with-ffmpeg
ffmpeg -i $filename -qscale:v 1 $newDir/ffout%08d.jpg
else
ffmpeg -i $filename $newDir/ffout%08d.png
fi
################################################################################
################################################################################
# complete
echoSuccess "Extracted video frames: \n# $newDir"