The biggest part of creating this video was to generate satisfactory glitched material. I researched various ways how to glitch images using SoX tool and a glitch in pre-3.0 ffmpeg’s jpeg-le codec. Below is a BASH script which worked through all .mov videos in the current folder, extracted frames, glitched it and stitched back the videos from frames. Here’s the gist of all glitches in a summary:
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 |
# pre-3.0 ffmpeg jpeg-le glitch ffmpeg -i INPUT.ppm -c:v jpegls -pred 60 OUTPUT.jpg # all sox operations used a .ppm file format # interpreted as: RAWFILEOPTS="-e unsigned -r 44100 -b 8 -c 2" # which was then used like this: sox -t raw $RAWFILEOPTS INPUT.ppm -t raw $RAWFILEOPTS OUTPUT.ppm $EFFECT # and effects EFFECT used were: # echoes echos 0.2 0.2 6700 0.5 4900 0.5 9200 0.5 1400 0.5 # reversed echoes reverse echos 0.2 0.2 6700 0.5 4900 0.5 9200 0.5 1400 0.5 # earwax earwax # stretch stretch 1.00002 # chorus chorus 0.5 1 90 0.4 0.25 9 -t 60 0.32 0.4 0.2 -t 40 0.3 0.3 0.5 -s # downsample (use 50 or 99) downsample 50 # reverb 1 gain -15 reverb 75 0 100 100 0 10 # reverb 2 reverb -w 50 50 5 100 0 0 # trim repeat 3 \ trim $((RANDOM%3+1)) $((RANDOM%3+6)) $((RANDOM%3+8)) $((RANDOM%3+14)) $((RANDOM%3+19))\ trim $((RANDOM%3+1)) $((RANDOM%3+6)) $((RANDOM%3+8)) $((RANDOM%3+11)) $((RANDOM%3+14))\ trim $((RANDOM%3+1)) $((RANDOM%3+6)) $((RANDOM%3+8)) $((RANDOM%3+14)) $((RANDOM%3+19)) |
Here’s a full bash script:
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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
#!/bin/bash ###################################################################################################### # jpegLE! # $FFMPEG -loglevel 16 -i $i -pred 60 -c:v jpegls $i.jpgls.jpg # ffmpeg -loglevel 16 -i $i.jpgls.jpg -c:v png $i.png # folder: "jpegle" # SOXEFFECT="echos 0.2 0.2 6700 0.5 4900 0.5 9200 0.5 1400 0.5" # folder: echos # SOXEFFECT="reverse echos 0.2 0.2 6700 0.5 4900 0.5 9200 0.5 1400 0.5" # folder: "reverse_echo" # SOXEFFECT="earwax" # SOXEFFECT="stretch 1.00002" # SOXEFFECT="chorus 0.5 1 90 0.4 0.25 9 -t 60 0.32 0.4 0.2 -t 40 0.3 0.3 0.5 -s" # SOXEFFECT="downsample 50" # SOXEFFECT="downsample 99" # SOXEFFECT="gain -15 reverb 75 0 100 100 0 10" # SOXEFFECT="reverb -w 50 50 5 100 0 0" # SOXEFFECT="repeat 3 \ # trim $((RANDOM%3+1)) $((RANDOM%3+6)) $((RANDOM%3+8)) $((RANDOM%3+14)) $((RANDOM%3+19))\ # trim $((RANDOM%3+1)) $((RANDOM%3+6)) $((RANDOM%3+8)) $((RANDOM%3+11)) $((RANDOM%3+14))\ # trim $((RANDOM%3+1)) $((RANDOM%3+6)) $((RANDOM%3+8)) $((RANDOM%3+14)) $((RANDOM%3+19))" ###################################################################################################### # raw file interpretation by sox RAWFILEOPTS="-e unsigned -r 44100 -b 8 -c 2" # image header size in bytes - it will be preserved in new file HEADERSIZE=500 # ffmpeg executable ffmpeg="/usr/bin/ffmpeg -loglevel 16" # jpegls glitch needs an older ffmpeg oldffmpeg="/home/random/src/ffmpeg/ffmpeg-2.0.7/ffmpeg -loglevel 16" # run this in the folder with movie clips, please pwd=`pwd` mkdir $pwd/tmp mkdir $pwd/tmp/frames mkdir $pwd/tmp/jpegls mkdir $pwd/tmp/rvrsecho mkdir $pwd/tmp/echos mkdir $pwd/tmp/earwax mkdir $pwd/tmp/stretch mkdir $pwd/tmp/chorus mkdir $pwd/tmp/downsample50 mkdir $pwd/tmp/downsample99 mkdir $pwd/tmp/reverb1 mkdir $pwd/tmp/reverb2 mkdir $pwd/tmp/trim for i in *.mov do cd $pwd echo ">> processing clip: $i" # extract all frames echo "++ extracting frames ..." $ffmpeg -i "$i" tmp/frames/frame%6d.ppm cd tmp/frames for f in *.ppm do echo ">> processing frame $f" # fetch original file size FILESIZE=`stat -c%s $f` echo "-- jpegls ..." $oldffmpeg -i "$f" -c:v jpegls -pred 60 ../jpegls/$f.jpegls.jpg echo "-- soxed: echoes ..." sox -t raw $RAWFILEOPTS $f -t raw $RAWFILEOPTS $f.soxed echos 0.2 0.2 6700 0.5 4900 0.5 9200 0.5 1400 0.5 echo " . fixing headers..." head -c $HEADERSIZE $f > $f.header head -c $FILESIZE $f.soxed > $f.trimmed tail -c `expr $FILESIZE - $HEADERSIZE` $f.trimmed >> $f.header mv $f.header ../echos/$f.echos.ppm rm $f.soxed $f.trimmed echo "-- soxed: rvrsecho ..." sox -t raw $RAWFILEOPTS $f -t raw $RAWFILEOPTS $f.soxed reverse echos 0.2 0.2 6700 0.5 4900 0.5 9200 0.5 1400 0.5 echo " . fixing headers..." head -c $HEADERSIZE $f > $f.header head -c $FILESIZE $f.soxed > $f.trimmed tail -c `expr $FILESIZE - $HEADERSIZE` $f.trimmed >> $f.header mv $f.header ../rvrsecho/$f.rvrsecho.ppm rm $f.soxed $f.trimmed echo "-- soxed: earwax ..." sox -t raw $RAWFILEOPTS $f -t raw $RAWFILEOPTS $f.soxed earwax echo " . fixing headers..." head -c $HEADERSIZE $f > $f.header head -c $FILESIZE $f.soxed > $f.trimmed tail -c `expr $FILESIZE - $HEADERSIZE` $f.trimmed >> $f.header mv $f.header ../earwax/$f.earwax.ppm rm $f.soxed $f.trimmed echo "-- soxed: stretch ..." sox -t raw $RAWFILEOPTS $f -t raw $RAWFILEOPTS $f.soxed stretch 1.00002 echo " . fixing headers..." head -c $HEADERSIZE $f > $f.header head -c $FILESIZE $f.soxed > $f.trimmed tail -c `expr $FILESIZE - $HEADERSIZE` $f.trimmed >> $f.header mv $f.header ../stretch/$f.stretch.ppm rm $f.soxed $f.trimmed echo "-- soxed: chorus ..." sox -t raw $RAWFILEOPTS $f -t raw $RAWFILEOPTS $f.soxed chorus 0.5 1 90 0.4 0.25 9 -t 60 0.32 0.4 0.2 -t 40 0.3 0.3 0.5 -s echo " . fixing headers..." head -c $HEADERSIZE $f > $f.header head -c $FILESIZE $f.soxed > $f.trimmed tail -c `expr $FILESIZE - $HEADERSIZE` $f.trimmed >> $f.header mv $f.header ../chorus/$f.chorus.ppm rm $f.soxed $f.trimmed echo "-- soxed: downsample50 ..." sox -t raw $RAWFILEOPTS $f -t raw $RAWFILEOPTS $f.soxed downsample 50 echo " . fixing headers..." head -c $HEADERSIZE $f > $f.header head -c $FILESIZE $f.soxed > $f.trimmed tail -c `expr $FILESIZE - $HEADERSIZE` $f.trimmed >> $f.header mv $f.header ../downsample50/$f.downsample50.ppm rm $f.soxed $f.trimmed echo "-- soxed: downsample99 ..." sox -t raw $RAWFILEOPTS $f -t raw $RAWFILEOPTS $f.soxed downsample 99 echo " . fixing headers..." head -c $HEADERSIZE $f > $f.header head -c $FILESIZE $f.soxed > $f.trimmed tail -c `expr $FILESIZE - $HEADERSIZE` $f.trimmed >> $f.header mv $f.header ../downsample99/$f.downsample99.ppm rm $f.soxed $f.trimmed echo "-- soxed: reverb1 ..." sox -t raw $RAWFILEOPTS $f -t raw $RAWFILEOPTS $f.soxed gain -15 reverb 75 0 100 100 0 10 echo " . fixing headers..." head -c $HEADERSIZE $f > $f.header head -c $FILESIZE $f.soxed > $f.trimmed tail -c `expr $FILESIZE - $HEADERSIZE` $f.trimmed >> $f.header mv $f.header ../reverb1/$f.reverb1.ppm rm $f.soxed $f.trimmed echo "-- soxed: reverb2 ..." sox -t raw $RAWFILEOPTS $f -t raw $RAWFILEOPTS $f.soxed reverb -w 50 50 5 100 0 0 echo " . fixing headers..." head -c $HEADERSIZE $f > $f.header head -c $FILESIZE $f.soxed > $f.trimmed tail -c `expr $FILESIZE - $HEADERSIZE` $f.trimmed >> $f.header mv $f.header ../reverb2/$f.reverb2.ppm rm $f.soxed $f.trimmed echo "-- soxed: trim ..." sox -t raw $RAWFILEOPTS $f -t raw $RAWFILEOPTS $f.soxed repeat 3 \ trim $((RANDOM%3+1)) $((RANDOM%3+6)) $((RANDOM%3+8)) $((RANDOM%3+14)) $((RANDOM%3+19))\ trim $((RANDOM%3+1)) $((RANDOM%3+6)) $((RANDOM%3+8)) $((RANDOM%3+11)) $((RANDOM%3+14))\ trim $((RANDOM%3+1)) $((RANDOM%3+6)) $((RANDOM%3+8)) $((RANDOM%3+14)) $((RANDOM%3+19)) echo " . fixing headers..." head -c $HEADERSIZE $f > $f.header head -c $FILESIZE $f.soxed > $f.trimmed tail -c `expr $FILESIZE - $HEADERSIZE` $f.trimmed >> $f.header mv $f.header ../trim/$f.trim.ppm rm $f.soxed $f.trimmed done cd $pwd echo ">> creating JPEGLS movie file ..." $ffmpeg -i tmp/jpegls/frame%6d.ppm.jpegls.jpg tmp/jpegls/jpegls.$i echo "++ removing frames ..." rm tmp/jpegls/*.jpg echo ">> creating echos movie file ..." $ffmpeg -i tmp/echos/frame%6d.ppm.echos.ppm tmp/echos/echos.$i echo "++ removing frames ..." rm tmp/echos/*.ppm echo ">> creating rvrsecho movie file ..." $ffmpeg -i tmp/rvrsecho/frame%6d.ppm.rvrsecho.ppm tmp/rvrsecho/rvrsecho.$i echo "++ removing frames ..." rm tmp/rvrsecho/*.ppm echo ">> creating earwax movie file ..." $ffmpeg -i tmp/earwax/frame%6d.ppm.earwax.ppm tmp/earwax/earwax.$i echo "++ removing frames ..." rm tmp/earwax/*.ppm echo ">> creating stretch movie file ..." $ffmpeg -i tmp/stretch/frame%6d.ppm.stretch.ppm tmp/stretch/stretch.$i echo "++ removing frames ..." rm tmp/stretch/*.ppm echo ">> creating chorus movie file ..." $ffmpeg -i tmp/chorus/frame%6d.ppm.chorus.ppm tmp/chorus/chorus.$i echo "++ removing frames ..." rm tmp/chorus/*.ppm echo ">> creating downsample50 movie file ..." $ffmpeg -i tmp/downsample50/frame%6d.ppm.downsample50.ppm tmp/downsample50/downsample50.$i echo "++ removing frames ..." rm tmp/downsample50/*.ppm echo ">> creating downsample99 movie file ..." $ffmpeg -i tmp/downsample99/frame%6d.ppm.downsample99.ppm tmp/downsample99/downsample99.$i echo "++ removing frames ..." rm tmp/downsample99/*.ppm echo ">> creating reverb1 movie file ..." $ffmpeg -i tmp/reverb1/frame%6d.ppm.reverb1.ppm tmp/reverb1/reverb1.$i echo "++ removing frames ..." rm tmp/reverb1/*.ppm echo ">> creating reverb2 movie file ..." $ffmpeg -i tmp/reverb2/frame%6d.ppm.reverb2.ppm tmp/reverb2/reverb2.$i echo "++ removing frames ..." rm tmp/reverb2/*.ppm echo ">> creating trim movie file ..." $ffmpeg -i tmp/trim/frame%6d.ppm.trim.ppm tmp/trim/trim.$i echo "++ removing frames ..." rm tmp/trim/*.ppm done |