-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathffmpeg-webm-backforth
91 lines (83 loc) · 2.27 KB
/
ffmpeg-webm-backforth
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
#!/bin/bash
# ffmpeg-webm-backforth
# Bash script to create webms which go back and forth. No audio is included.
# ffmpeg is required.
# See https://github.com/WhatIsThisImNotGoodWithComputers/ffmpeg-webm-scripts for usage.
# Created by WhatIsThisImNotGoodWithComputers (ohgod AT whatisthisimnotgoodwithcomputers DOT com)
#vars
TEMP_FOLDER="ffmpeg-temp"
OUTPUT_FILE="output.webm"
FRAMERATE="4500K"
TEMP=`getopt --long -o "i:s:t:o:f:c:a:" "$@"`
#params
eval set -- "$TEMP"
while true ; do
case "$1" in
-i )
INPUT_FILE=$2
shift 2
;;
-s )
START_TIME=$2
shift 2
;;
-t )
TO_TIME=$2
shift 2
;;
-o )
OUTPUT_FILE=$2
shift 2
;;
-f )
FRAMERATE=$2
shift 2
;;
-c )
#process cropping values
IFS=',' read -ra ARR <<< "$2"
NEW_CROP="$((${ARR[2]} - ${ARR[0]})):$((${ARR[3]} - ${ARR[1]})):${ARR[0]}:${ARR[1]}"
#add
if [ -n "$CROPSCALE" ]; then
CSTEMP="$CROPSCALE"',crop='$NEW_CROP
CROPSCALE=$CSTEMP
else
CROPSCALE='-vf crop='$NEW_CROP
fi
shift 2
;;
-a )
if [ -n "$CROPSCALE" ]; then
CSTEMP="$CROPSCALE"',scale='$2
CROPSCALE=$CSTEMP
else
CROPSCALE='-vf scale='$2
fi
shift 2
;;
*)
break
;;
esac
done;
#work
if [[ -d $TEMP_FOLDER ]]; then
echo -e "\033[01;41;35mERROR: there's a directory $TEMP_FOLDER here.\033[0m"
#exit 0
else
#create dir
echo -e "\033[05;44;33mCreating temp dir: $TEMP_FOLDER ...\033[0m"
mkdir $TEMP_FOLDER
#create shots
echo -e "\033[05;44;33mUsing ffmpeg to create snapshots...\033[0m"
ffmpeg -i "${INPUT_FILE}" -ss $START_TIME -to $TO_TIME -an -qscale 1 $TEMP_FOLDER/%06d.jpg
#create webm
echo -e "\033[05;44;33mUsing ffmpeg to encode snapshots into BACK FORTH webm\033[0m"
cat $(ls $TEMP_FOLDER/*jpg && ls -r $TEMP_FOLDER/*jpg) | ffmpeg -f image2pipe -vcodec mjpeg -r 25 -i - -c:v libvpx -crf 20 -b:v $FRAMERATE $CROPSCALE -threads 0 -an $OUTPUT_FILE
#cleaning up
echo -e "\033[05;44;33mCleaning up...\033[0m"
rm -r $TEMP_FOLDER
#Uncomment following line if you're having trouble with cropping and or scaling
#echo $CROPSCALE
fi
exit 0