Tuesday, 14 December 2021

Auto hex script


Thought I'd post a few of the scripts I've been working on during the year. This one takes a video , divides it into the number of stills you specify in an image format you specify and then hex edits each still in turn with the values you give the script then reassembles everything back into video at the end , then cleans up after itself. Example here . Its fairly unforgiving in that you have to type in precisely names of files and numbers, there are no backsies if you make a mistake and notice it before the script goes to work you will have to ctrl c and start again and also remember to name the output file differently to the input file. Longer videos can generate a lot of stills so make sure you have the space for that and depending on computer speed and speed of i/o ie ssd vs spinning disk this can take a long time. Minutes for a small 1 minute video to hours for something larger, depending on the frames per second you specify . You will need to have imagemagick and ffmpeg installed for it to work. Should work on Windows 10 from git-bash, definitely works on linux obviously open terminal or navigate to the folder where your video file is. Anyways this is the script : 


#!/bin/bash
# based on this script
#  find . -type f -name '*.png'|while read filename; do echo ${filename};xxd -p ${filename} | sed 's/de/0a/g' | xxd -r -p >/home/user/transit/${filename}; done

echo -n "File to work on ? : "
read n

echo -n "Image format to work with ? : "
read im

echo -n "Hex value from ? : "
read fr

echo -n "Hex value to ? : "
read ft

echo -n "What do you want to name output file ? : "
read z

echo -n "Framerate as a number between 1 and 30 ? : "
read m

echo -n "crf value for final video ? :"
read o

# convert to image format

ffmpeg -i $n -vf fps=$m image-%05d.$im

#find and hex edit each image

find . -type f -name '*.'$im''|while read filename; do echo ${filename};

#get header
 head -n 3 ${filename} > head.$im

#strip header ( to avoid damaging it)
  sed '1d'  ${filename} > swap.$im;

#copy that to 2nd swap file to avoid overwriting
mv swap.$im swap2.$im
 
xxd -p swap2.$im |sed 's/'$fr'/'$ft'/g'| xxd -r -p > swap.$im;

cat head.$im swap.$im > ${filename};

rm head.$im
rm swap.$im
rm swap2.$im
 

done 


ffmpeg -i image-%05d.$im -vcodec libx264 -r $m -crf $o  -pix_fmt yuv420p $z


rm *.$im







Mark Fisher – ‘Ghosts of my life’, Fukuyama’s ‘End of history’ and rebooting the future with glitch art.

Note- this was the introduction I gave during a recent online discussion with Verena Voigt ( https://www.verena-voigt-pr.de/ ) a...