-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathreverse.sh
executable file
·93 lines (79 loc) · 1.95 KB
/
reverse.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
90
91
92
93
#!/bin/bash
########################
#Check for requirements#
########################
#zenity=$(which zenity)
#if [ "$zenity" == "" ]; then
# echo "You must have zenity installed"
# exit 1
#fi
# Check if avconv in installed, fallback to ffmpeg (avconv's previous name, still used on some systems)
avconv=$(which avconv)
if [ "$avconv" == "" ]; then
avconv=$(which ffmpeg)
fi
if [ "$avconv" == "" ]; then
# zenity --error --text="You must have avconv installed"
echo "You must have either avconv or ffmpeg installed."
exit 1
fi
##############################
#Check command line arguments#
##############################
if [ -z $1 ]; then
echo "No input file supplied."
exit 1
fi
if [ ! -e $1 ]; then
echo "File $1 does not exist."
exit 1
fi
if [ -z $2 ]; then
output_file='reversed_'$1
else
output_file=$2
fi
if [ -e $output_file ]; then
echo "File $output_file already exists."
exit 1
fi
#ffmpeg=$(which ffmpeg)
#if [ "$ffmpeg" == "" ]; then
# echo "You must have ffmpeg installed"
# exit 1
#fi
##################################
#Spawn frames into images/ folder#
##################################
mkdir images
cd images
$avconv -i ../$1 %d.jpg
##############
#Count images#
##############
images=0
for i in $(ls | grep .jpg); do
let images=images+1
done
#####################################
#Rename images in the opposite order#
#####################################
i=1
factor=0
while [ $factor -lt $images ]; do
new_name=$((images-factor))
printf $new_name' '
mv $i.jpg image$new_name.jpg
let factor=factor+1
let i=i+1
done
echo ''
###############################################
#Finally convert newly named images into video#
###############################################
#$avconv -f image2 -i image%d.jpg -vcodec mjpeg -b 12000k -r 30 ../$output_file
$avconv -f image2 -i image%d.jpg -vcodec mpeg4 ../$output_file
#######################
#Remove temporal files#
#######################
rm *jpg