Thursday 22 April 2021

Bash script for hex editing, convolution and gmic all at the same time in a batch !

 

 

I've talked before about cutting videos into stills ( using ffmpeg -i yourfile.avi -vf fps=25 image-%05d.ppm)   to then hex edit them then putting that all back together afterwards ( ffmpeg -i image-%05d.ppm -vcodec libx264 -crf 23  -pix_fmt yuv420p newfile.mp4) . Lately I've been experimenting with bash scripting, heavily influenced by talks with Vedran Gligo and Dina Karadžić of format c over the last few weeks online in their informal hacklab01 sessions. Out of those sessions I returned to an older way I'd worked and thought about automating the process a bit more, bash scripting is the perfect way to do this. ( The source film for this is one I've used before from archive.org 'I love trouble' an old black and white film noir).

I wanted to incorporate things I'd learnt about using sed, command line convolution of images and gmic ( essentially a gmic script which mimics displacement ) and I finally came up with this which produces the images which lead to the above video. ( if you do try the script I advise using the editor geany because you'll want to change the formats you are working with for different effects and geany really does work well you can search and replace very easily and again you want to use near raw formats this will most likely break png and jpgs so stick with ppm, bmp, xwd etc. Also this works directly on the files in your working directory so back the originals up elsewhere)

#!/bin/bash

echo -n "How many times do you want flip your burgers ? : "
read n
i=0

while [ $i -lt $n ]
do
    ((i++))

find . -type f -name '*.tga'|while read filename; do echo ${filename} ;sed 's/fd/000/g' ${filename} > "${filename%tga}"_mod.tga;
#mv "${filename%tga}"_mod.tga ${filename};

#convolution section
mogrify -morphology Convolve '8x8:

-1, -0.7, 0, 0, -1, -0.1, 0, 1  ,
 1, 1, 1, -1, 1, 1, 1, 1 ,
 1, 1, -1, -1, 1, 1, 1, 0  ,
 1, -1, -1, -8.9, 1, 1, 1, 1 ,
 1, 1, -4, 0, -1, 1, 0, -1 ,
 1, -0.5, -6, -0.1, 0, 3, -2, 0 ,
 2, -1, -2, -0.2, 0, 0, 0, 0 ,
 2, 0.8, 0.9, 0.5, 0.6, 0.3, 0.8, 1 ' ${filename};


gmic ${filename} "${filename%tga}"_mod.tga -blend xor -o ${filename}
rm "${filename%tga}"_mod.tga

#you dont have to rotate after each iteration if you comment out the line below #remember to uncomment the following done or the script throws an error

mogrify -rotate 90 ${filename};done

#done





done


As you can see the script asks you to input the number of times you want to run over the files , usually I start with one but the video above is 2 iterations. You can choose to rotate the files during the process which can lead to more interesting variations.

Stills would look like this :




 

 

ikillerpulse ( requires tomato.py in working directory)

I've been working on this script for the last week or so. What does it do? It takes an input video/s,  converts to a format we can use f...