Saturday, 2 December 2023

Multigifatron - make gifs from single files and videos from those gifs

 Multigifatron - make gifs from single files and videos from those gifs


* if using windows and git bash you will need to add magick to begining of imagemagick commands like convert or mogrify you will need to install imagemagick and ffmpeg to use webscraping via lynx you will have to install lynx on linux on windows you will have to download lynx and place it into the git bash /usr/bin folder

#! /bin/bash
#make directory to hold output
h=$(pwd)
echo $h
mkdir $h/work
mkdir $h/originals
p=$(date +%Y-%m-%d_%H%M%S)
mkdir $p
mkdir $h/discard
echo -n "Grab images from website (y/n) ? : "
read yn
# If yes then grab images from specified website if no carry on to next section
if [ $yn == "n" ] || [ $yn == "null" ]
          then   
          echo -n "Source image format ? : "
          read f
          echo -n "Image format to use  ? : "
          read t      
          z=$(ls *.$f | wc -l)
          echo $z         
           elif [ $yn == "y" ]
           then
           mkdir scraped_images
            cd $h/scraped_images
            echo -n "Url to grab ? : "
            read url
             echo -n "Image format to transcode to ( Downloaded images in jpg) ? : "
            read t
             
              for i in `lynx -image_links -dump $url | grep 'jpg' \
| grep http | awk '{print $2}'`; do wget $i; done
#remove nonstandard characters
find . -maxdepth 1 -name '*' |while read filename; do echo ${filename}; mv ${filename} ${RANDOM}.jpg; done
mv *.jpg $h/
cd $h/
z=$(ls *.jpg | wc -l)
echo $z     
            fi
cp *.$f $h/originals/       
echo -n "colourize ? (y/n) : "
read cz
if [ $cz == "y" ] || [ $cz == "null" ]
then
echo -n "Color depth ? : "
read c
find . -maxdepth 1 -name '*.'$f''|while read filename; do echo ${filename};
mv ${filename} test.$f
convert +dither -posterize $c test.$f ${filename};
rm test.$f
done
elif [ $cz == "n" ]
           then
           echo -n "Not colorizing"
           fi       

echo -n "How many iterations per image (whole number) : "
read ng

#get required width and height
echo -n "Width ? : "
read gw
echo -n "height ? : "
read gh
echo -n "Randomise images (y/n) ? : "
read yn
#mogrify to desired width and height
find . -maxdepth 1  -type f -name '*.'$f''|while read filename; do echo ${filename};
convert -resize "$gw"x"$gh"\! ${filename} test.$f
mv test.$f ${filename};done
#randomise if yes to randomise
if [ $yn == "y" ] || [ $yn == "null" ]
          then  
          echo -n "Randomising "
              find . -maxdepth 1 -name '*.'$f''|while read filename; do echo ${filename}; mv ${filename} ${RANDOM}.$f; done       
              elif [ $yn == "n" ]
            then
           echo -n "Not randomising "
              #sleep 1
            fi
#loop over images and do stuff to them below here

find . -maxdepth 1 -type f -name '*.'$f''|while read filename; do echo ${filename} ;
convert ${filename} $h/work/test.$t
mv ${filename} $h/originals/

cd $h/work/

i=0
while [ $i -lt $ng ]
do
    ((i++))

 #get header
  #sed '2,$d' test.$t > head.$t;

#strip header ( to avoid damaging it)
  #sed '1d'  test.$t > swap.$t
 from=$(openssl rand -hex 1)
  to=$(openssl rand -hex 2)
sed 's/\x'$from'/\x'$to'\xDA/g' test.$t > help.$t
#xxd -p swap.$t | sed 's/'$from'/'$to'/g' | xxd -p -r > help.$t

#put the header back
#cat head.$t help.$t> headswap.$t;

convert help.$t  ${RANDOM}.$f

rm help.$t



done
rm test.$t

#mogrify -format $f *.$t

#convert -delay 5 *.$f -morph 14  gifatron-${RANDOM}.gif
convert -delay 20 -loop 0 *.$f $h/$p/${RANDOM}.gif
#rm *.$t
mv *.$f $h/discard/
cd $h
done
cd $h/$p/
#mkdir $h/baseline
find . -type f -name '*.gif'|while read filename; do echo ${filename} ;
sleep 3


ffmpeg -nostdin -i ${filename} -c:v libx264 -pix_fmt yuv420p -profile:v baseline -level 1 ${RANDOM}.mp4


done







Saturday, 30 September 2023

Xor everything - script to use gmic displacement on multiple images

 




A script to use gmic to displace adjacent images in a folder and output into a second folder - should work on Linux and Windows ( using git-bash and downloading gmic cli and placing it in the C:\Program Files\Git\usr\bin directory) . Copy script into notepad ++ and save as file with .sh extension. It also handily resizes all images to the same size before operating the gmic function.

#! /bin/bash
#make directory to hold output
h=$(pwd)
echo $h
#make folder to store originals
mkdir $h/originals
mkdir $h/frames
p=$(date +%Y-%m-%d_%H%M%S)
mkdir $p
echo -n "Source image format ? : "
read f
#copy originals to $h/originals
cp *.$f $h/originals/
#randomise
echo -n "Randomise ? (y/n) : "
read rn
if [ $rn == "y" ] || [ $rn == "null" ]
          then
          find . -maxdepth 1 -name '*.'$f''|while read filename; do echo ${filename}; mv ${filename} ${RANDOM}.$f; done  
          elif [ $rn == "n" ]
           then
           echo -n "Not randomising"
           fi
                     
#get dimensions
echo -n "Landscape(l),square(s),portrait(p)? : "
read lsp
#modify to size depending lsp variable
if [ $lsp == "s" ] || [ $lsp == "null" ]
          then   
          mogrify -resize 800x800! *.$f      
             
           elif [ $lsp == "l" ]
           then
           mogrify -resize 800x600! *.$f
           elif [ $lsp == "p" ]
           then
           mogrify -resize 600x800! *.$f
          
           fi
i=$(ls *.$f | wc -l)
echo $i
while [ $i -gt 0 ]
do
#move 2 files to $h/frames with find
find . -maxdepth 1 -name '*.'$f'' | head -n 2 | xargs -d $'\n' mv -t $h/frames/

#move to frames directory
cd $h/frames/
z=1
#rename files to swap1 and swap2
find . -maxdepth 1 -type f -name '*.'$f''|while read filename; do echo ${filename};
mv ${filename} swap$z.$f
((z++));
done
gmic swap1.$f swap2.$f  -blend xor -o swap3.$f
d=$(date +%Y-%m-%d_%H%M%S)
mv swap3.$f $h/$p/$d.$f
sleep 1
rm swap1.$f
rm swap2.$f
cd $h
i=$((i-=2))
done



Tuesday, 26 September 2023

Grid and split your images.

 

With Xavier Dallet aka chan-something star


Whoppa whoppa whoppa

Ever wanted to take a series of images and make grids from them? Ever wanted to loop over the images and create ever more fractured but yet somehow consistent glitchy grids? Then this script is for you. Inspired by Xavier Dallet aka chan somethingstar and his Instagram group Baobab users  https://www.instagram.com/baobab_users/

Requires imagemagick, bash and a basic knowledge of how to run shell scripts. Linux Script below. Name it and save with .sh extension.  Modified version for  windows 10+ using git bash, after the linux version - I've tested both as working.

#! /bin/bash
#make directory to hold output
h=$(pwd)
echo $h
#make folder to store originals
mkdir $h/originals
mkdir $h/frames
#make folder to hold output
mkdir rotator
#get formats to use
echo -n "Source image format ? : "
read f
echo -n "Image format to use  ? : "
read t
echo -n "Discard cut in ? : "
read disin
echo -n "No to discard ? : "
read dis
#get grid dimensions
echo -n "Grid height ? : "
read gw
echo -n "Grid width ? : "
read gh
echo -n "Number of loops ? : "
read lo
echo -n "Use apple corer ? (no(n) OR /north/east/south/west/center)  : "
read ac
#calculate no of frames to move to frames gw x gh
gwgh=$(($gw * $gh))
echo $gwgh   
echo -n "Landscape(l),square(s),portrait(p)? : "
read lsp           
#copy originals to $h/originals
cp *.$f $h/originals/
#new stuff should go between here and infinite loop
#infinite loop
lp=0
while [ $lp -lt $lo ]
do
    ((lp++))
echo "Press Ctrl+C to stop..."
#count how many files we have
cd $h
i=$(ls *.$f | wc -l)
echo  $i
#convert everything to specified format or convert then randomise
#randomise yes
echo -n "Randomising "
mogrify -format $t *.$f
find . -maxdepth 1 -name '*.'$t''|while read filename; do echo ${filename}; mv ${filename} ${RANDOM}.$t; done
#crop to 1:1 4:3 or 3:4 depending on lsp before resizing details here https://stackoverflow.com/questions/21262466/imagemagick-how-to-minimally-crop-an-image-to-a-certain-aspect-ratio
if [ $lsp == "s" ] || [ $lsp == "null" ]
          then   
          find . -maxdepth 1 -name '*.'$t''|while read filename; do echo ${filename}; convert ${filename} -gravity center -crop 1:1 swap.$t; mv swap.$t ${filename};done
          elif [ $lsp == "l" ]
           then
           find . -maxdepth 1 -name '*.'$t''|while read filename; do echo ${filename}; convert ${filename} -gravity center -crop 4:3 swap.$t; mv swap.$t ${filename};done
            elif [ $lsp == "p" ]
           then
           find . -maxdepth 1 -name '*.'$t''|while read filename; do echo ${filename}; convert ${filename} -gravity center -crop 3:4 swap.$t; mv swap.$t ${filename};done
        fi
#resize for preffered size grid
#mogrify -resize 600x600! -gravity center -extent 600x600 *.$t
#modify to size depending lsp variable
if [ $lsp == "s" ] || [ $lsp == "null" ]
          then   
          mogrify -resize 800x800! *.$t      
             
           elif [ $lsp == "l" ]
           then
           mogrify -resize 800x600! *.$t
           elif [ $lsp == "p" ]
           then
           mogrify -resize 600x800! *.$t
          
           fi


#mogrify -rotate 90 *.$t
#mogrify -flop *.$t
#loop to make montages $gwgh at a time so as not to exhaust imagemagick cache
while [ $i -gt 0 ]
do
#move gwxgh images to frames
find . -maxdepth 1 -name '*.'$t'' | head -n $gwgh | xargs -d $'\n' mv -t $h/frames/
#move to frames directory
cd $h/frames/
d=$(date +%Y-%m-%d_%H%M%S)
montage *.$t -geometry +3+3 -tile $gwx$gh $d.$t
#move output back to source folder
convert $d.$t $d.$f
mv $d.$f $h/rotator
#decrease counter by gwgh
i=$((i-="$gwgh"))
#tidy up
rm *.$t
cd $h
done
cd $h/rotator

if [ $ac == "n" ] || [ $ac == "null" ]
          then   
          mv *.$f $h       
             
           elif [ $ac == "center" ]
           then
find . -maxdepth 1 -name '*.'$f''|while read filename; do echo ${filename}; convert ${filename} -gravity center -crop 1300x1300+0+0 swap.$f;
 mv swap.$f ${RANDOM}${RANDOM}.$f;done
            elif [ $ac == "north" ]
            then
find . -maxdepth 1 -name '*.'$f''|while read filename; do echo ${filename}; convert ${filename} -gravity north -crop 1300x1300+0+0 swap.$f;
 mv swap.$f ${RANDOM}${RANDOM}.$f;done
            elif [ $ac == "east" ]
            then
find . -maxdepth 1 -name '*.'$f''|while read filename; do echo ${filename}; convert ${filename} -gravity east -crop 1300x1300+0+0 swap.$f;
 mv swap.$f ${RANDOM}${RANDOM}.$f;done
            elif [ $ac == "south" ]
            then
find . -maxdepth 1 -name '*.'$f''|while read filename; do echo ${filename}; convert ${filename} -gravity south -crop 1300x1300+0+0 swap.$f;
 mv swap.$f ${RANDOM}${RANDOM}.$f;done
            elif [ $ac == "west" ]
            then
find . -maxdepth 1 -name '*.'$f''|while read filename; do echo ${filename}; convert ${filename} -gravity west -crop 1300x1300+0+0 swap.$f;
 mv swap.$f ${RANDOM}${RANDOM}.$f;done
 
 
 fi
#mirror vertically
find . -maxdepth 1 -name '*.'$f''|while read filename; do echo ${filename};
convert ${filename} -gravity east -chop 50%x0 output.$f
convert output.$f -flop output2.$f
convert output.$f output2.$f -gravity North +append ${RANDOM}.$f
rm output.$f
rm output2.$f;
done
#mogrify -monochrome *.$f

#uncomment below to create a negative image on each alternate run
#mogrify -negate *.$f
mv *.$f $h
cd $h

# move x no of images to to new folder
new=$(ls *.$f | wc -l)
if (($new > $disin ))
then
dd=$(date +%Y-%m-%d_%H%M%S)
mkdir $h/$dd
find . -maxdepth 1 -name '*.'$f'' | head -n $dis | xargs -d $'\n' mv -t $h/$dd
fi

done

(Below is a modified version for Windows 10 running gitbash with imagemagick installed and on path)

#! /bin/bash
#make directory to hold output
h=$(pwd)
echo $h
#make folder to store originals
mkdir $h/originals
mkdir $h/frames
#make folder to hold output
mkdir rotator
#get formats to use
echo -n "Source image format ? : "
read f
echo -n "Image format to use  ? : "
read t
echo -n "Discard cut in ? : "
read disin
echo -n "No to discard ? : "
read dis
#get grid dimensions
echo -n "Grid height ? : "
read gw
echo -n "Grid width ? : "
read gh
echo -n "Number of loops ? : "
read lo
echo -n "Use apple corer ? (no(n) OR /north/east/south/west/center)  : "
read ac
#calculate no of frames to move to frames gw x gh
gwgh=$(($gw * $gh))
echo $gwgh   
echo -n "Landscape(l),square(s),portrait(p)? : "
read lsp           
#copy originals to $h/originals
cp *.$f $h/originals/
#new stuff should go between here and infinite loop
#infinite loop
lp=0
while [ $lp -lt $lo ]
do
    ((lp++))
echo "Press Ctrl+C to stop..."
#count how many files we have
cd $h
i=$(ls *.$f | wc -l)
echo  $i
#convert everything to specified format or convert then randomise
#randomise yes
echo -n "Randomising "
magick mogrify -format $t *.$f
find . -maxdepth 1 -name '*.'$t''|while read filename; do echo ${filename}; mv ${filename} ${RANDOM}.$t; done
#crop to 1:1 4:3 or 3:4 depending on lsp before resizing details here https://stackoverflow.com/questions/21262466/imagemagick-how-to-minimally-crop-an-image-to-a-certain-aspect-ratio
if [ $lsp == "s" ] || [ $lsp == "null" ]
          then   
          find . -maxdepth 1 -name '*.'$t''|while read filename; do echo ${filename}; magick convert ${filename} -gravity center -crop 1:1 swap.$t; mv swap.$t ${filename};done
          elif [ $lsp == "l" ]
           then
           find . -maxdepth 1 -name '*.'$t''|while read filename; do echo ${filename}; magick convert ${filename} -gravity center -crop 4:3 swap.$t; mv swap.$t ${filename};done
            elif [ $lsp == "p" ]
           then
           find . -maxdepth 1 -name '*.'$t''|while read filename; do echo ${filename}; magick convert ${filename} -gravity center -crop 3:4 swap.$t; mv swap.$t ${filename};done
        fi
#resize for preffered size grid
#mogrify -resize 600x600! -gravity center -extent 600x600 *.$t
#modify to size depending lsp variable
if [ $lsp == "s" ] || [ $lsp == "null" ]
          then   
          magick mogrify -resize 800x800! *.$t      
             
           elif [ $lsp == "l" ]
           then
           magick mogrify -resize 800x600! *.$t
           elif [ $lsp == "p" ]
           then
           magick mogrify -resize 600x800! *.$t
          
           fi


#magick mogrify -rotate 90 *.$t
#magick mogrify -flop *.$t
#loop to make montages $gwgh at a time so as not to exhaust imagemagick cache
while [ $i -gt 0 ]
do
#move gwxgh images to frames
find . -maxdepth 1 -name '*.'$t'' | head -n $gwgh | xargs -d $'\n' mv -t $h/frames/
#move to frames directory
cd $h/frames/
d=$(date +%Y-%m-%d_%H%M%S)
magick montage *.$t -geometry +3+3 -tile $gwx$gh $d.$t
#move output back to source folder
magick convert $d.$t $d.$f
mv $d.$f $h/rotator
#decrease counter by gwgh
i=$((i-="$gwgh"))
#tidy up
rm *.$t
cd $h
done
cd $h/rotator

if [ $ac == "n" ] || [ $ac == "null" ]
          then   
          mv *.$f $h       
             
           elif [ $ac == "center" ]
           then
find . -maxdepth 1 -name '*.'$f''|while read filename; do echo ${filename}; magick convert ${filename} -gravity center -crop 1300x1300+0+0 swap.$f;
 mv swap.$f ${RANDOM}${RANDOM}.$f;done
            elif [ $ac == "north" ]
            then
find . -maxdepth 1 -name '*.'$f''|while read filename; do echo ${filename}; magick convert ${filename} -gravity north -crop 1300x1300+0+0 swap.$f;
 mv swap.$f ${RANDOM}${RANDOM}.$f;done
            elif [ $ac == "east" ]
            then
find . -maxdepth 1 -name '*.'$f''|while read filename; do echo ${filename}; magick convert ${filename} -gravity east -crop 1300x1300+0+0 swap.$f;
 mv swap.$f ${RANDOM}${RANDOM}.$f;done
            elif [ $ac == "south" ]
            then
find . -maxdepth 1 -name '*.'$f''|while read filename; do echo ${filename}; magick convert ${filename} -gravity south -crop 1300x1300+0+0 swap.$f;
 mv swap.$f ${RANDOM}${RANDOM}.$f;done
            elif [ $ac == "west" ]
            then
find . -maxdepth 1 -name '*.'$f''|while read filename; do echo ${filename}; magick convert ${filename} -gravity west -crop 1300x1300+0+0 swap.$f;
 mv swap.$f ${RANDOM}${RANDOM}.$f;done
 
 
 fi
#mirror vertically
find . -maxdepth 1 -name '*.'$f''|while read filename; do echo ${filename};
magick convert ${filename} -gravity east -chop 50%x0 output.$f
magick convert output.$f -flop output2.$f
magick convert output.$f output2.$f -gravity North +append ${RANDOM}.$f
rm output.$f
rm output2.$f;
done
#magick mogrify -monochrome *.$f
magick mogrify -negate *.$f
mv *.$f $h
cd $h

# move x no of images to to new folder
new=$(ls *.$f | wc -l)
if (($new > $disin ))
then
dd=$(date +%Y-%m-%d_%H%M%S)
mkdir $h/$dd
find . -maxdepth 1 -name '*.'$f'' | head -n $dis | xargs -d $'\n' mv -t $h/$dd
fi

done







Monday, 3 July 2023

Gmic and sox script redux.




 I started using Windows 10 again recently (22h2 with all relevant updates) because I'm doing more online stuff again with Format C and pragmatically when talking to  people who are trying to learn glitch art  techniques for the first time most will be using windows ( mac os people you are on your own I just cant be bothered ), I needed to relearn stuff myself so fresh install of Windows 10 , deal with the usual frustrations and on I go.

 Sooooo long story short I discovered that having used gmic cli in Windows 10 previously , installing it via chocolatey so it was available for use via scripts in git-bash that that option was no longer there , no gmic in chocolatey ( to avoid messing around with path) and worse the gmic add on for gimp was now being identified by windows security as a pup plus the cli version I wanted to use couldnt be added to path or even function within git-bash - oh yea I could use cmd , but who wants to go back to the dark ages of dos cli ( unless im using dos but thats a different post altogether - freedos rocks) 

So whats the solution, and I have to admit this post is mainly for me when I next have to use windows 10 ( god I really hope not - its illogical and ridiculous - where is everything stored why cant I use techniques i use on linux in windows the ridiculous cr lf v's lf - why arent we using utf 8 ? why why why - but I digress) 

The solution is simple , download the gmic cli zip file for windows 10, unzip it then go into the folder copy everything then paste all of that into the git bash folder at C:\Program Files\Git\usr\bin , which then allows me to use this shiny new script which is a work in progress so use at your own risk ( oh yes you need to install sox portable via chocolatey for it to work)- what does it do - it sonifies images and optionally applies a gmic xor blend to your images if you want - it can apply sonification or not ( the none option) and gmic or not - the y/n option or neither !! Its a work in progress so if you enter wrong values it prolly wont work as intended - I may or may  not add more features . Inspired by Vedran Gligo's Megaglitchatron script ( find that here - https://gitlab.com/hacklab01/MegaGlitchATron) copy it and post it into notepad++ or similar  save it as whatever name you want to give it with the .sh extension then run it as 'bash whateveryounameit.sh' via git-bash :

#! /bin/bash
#make directory to hold output
h=$(pwd)
echo $h
mkdir $h/frames
mkdir $h/originals
#get input formats
echo -n "Source image format ? : "
read f
#get destination format
echo -n "Image format to use ? : "
read t
#get effect
echo -n "Effect to use ? : "
read fx
#are we using gmic ( after downloading gmic cli zip and placing that in  C:\Program Files\Git\usr\bin )
echo -n "Use gmic y/n ? : "
read yn
cp *.$f $h/originals

find . -maxdepth 1 -name '*.'$f''|while read filename; do echo ${filename};
#get date to rename file
d=$(date +%Y-%m-%d_%H%M%S)

mv ${filename} test.$f
magick mogrify -format $t test.$f
#rm test.$f
#strip header section for windows
#get header
  head -n 3 test.$t > head.$t;
#strip header ( to avoid damaging it)
  sed -b '1d'  test.$t > swap.$t
 
  #copy that to raw file so we can use sox
cp swap.$t frame.raw
 
#apply effect specified by fx variable
 if [ $fx == "echo" ] || [ $fx == "null" ]
          then
           effect="echos 0.8 0.7 700 0.25 900 0.3 norm"
        elif [ $fx == "reverb" ]
          then
           effect="gain -3 pad 2 8 reverb"
        elif [ $fx == "hilbert" ]
          then
           effect="hilbert -n 5001"
        elif [ $fx == "phaser" ]
          then
           effect="phaser 0.8 0.74 3 0.7 0.5"
        elif [ $fx == "flanger" ]
          then
           effect="flanger 0 2 0 71 0.5 25 lin"
        elif [ $fx == "overdrive" ]
          then
           effect="overdrive 17"   
        elif [ $fx == "none" ]
          then
           effect=""
        fi
#add the effect

sox -r 482170 -e u-law frame.raw frame2.raw $effect
    #try or add these
    #"bass 5"
    #"echo 0.8 0.88 60 0.4"
    #"flanger 0 2 0 71 0.5 25 lin"
    #"hilbert -n 5001"
    #"loudness 6"
    #"norm 90"
    #"overdrive 17"
    #"phaser 0.8 0.74 3 0.7 0.5"
    #"phaser 0.8 0.74 3 0.4 0.5"
    #"pitch 2"
    #"riaa"
    #"sinc 20-4k"
    #"vol 10"

cp frame2.raw swap.$t;
cat head.$t swap.$t > test.$t;

if [ $yn == "n" ] || [ $yn == "null" ]
          then
              magick convert test.$t  $h/frames/$d.$f
           elif [ $yn == "y" ]
          then
            gmic test.$f  test.$t -blend xor -o $h/frames/$d.$f;
        rm test.$f
        fi
#if using displacement comment out line below
#cat head.$t swap.$t > test.$t;
#magick convert test.$t  $h/frames/$d.$f
#mv test.$t $h/frames/$d.$t

rm head.$t
rm test.$f
rm test.$t
rm swap.$t
rm frame.raw
rm frame2.raw

done




 


Saturday, 3 June 2023

3gifomaticwin.sh

 This is a script for windows ( using git-bash terminal and with imagemagick installed) to glitch images in batches of 3 and then makes those images into a single gif - it  copies the original source files into a folder called originals to keep them safe, then moves each batch of three files into the frames folder , glitches them then creates a gif from them then dletes the original images - it does this until images in directory where script is running from are gone !! A work in progress use at your peril .

 

#! /bin/bash
#make directory to hold output
h=$(pwd)
echo $h
mkdir $h/frames
mkdir $h/originals
echo -n "Source image format ? : "
read f
cp *.$f $h/originals/
i=$(ls *.$f | wc -l)

echo $i
echo -n "Image format to use  ? : "
read t
#for loop should go here

while [ $i -gt 0 ]
do
d=$(date +%Y-%m-%d_%H%M%S)
#move three files to $h/frames with find
find . -maxdepth 1 -name '*.'$f'' | head -n 3 | xargs -d $'\n' mv -t $h/frames/
cd $h/frames/

 
magick mogrify -format $t *.$f
find . -type f -name '*.'$t''|while read filename; do echo ${filename};
#do the random number thing
 #generate no from 1 to 16
sugar1=$(( $RANDOM % 16 + 1 ))
sugar3=$(( $RANDOM % 16 + 1 ))
sugar2=$(( $RANDOM % 16 + 2 ))
sugar4=$(( $RANDOM % 16 + 2 ))
#convert to hex
from=$(printf '%x\n' $sugar1)
to=$(printf '%x\n' $sugar2)
from2=$(printf '%x\n' $sugar3)
to2=$(printf '%x\n' $sugar4)

magick convert -resize 640x640\! ${filename} test.$t
xxd -p test.$t| sed -b '5,$s/'"$from""$from2"/"$to""$to2"'/g' | xxd -p -r > ${filename};
done
magick convert -delay 20 -loop 0 *.$t $d.gif
rm *.$f
rm *.$t
cd $h
i=$((i-=3))
#cd $h/frames/
done




Thursday, 11 May 2023

Burner - video and scripts

 

(*Note these scripts were created using before recent changes to ffmpeg's syntax ie -s now becomes -video_size, -pix_fmt becomes -pixel_format)

 Two ffplay windows generating feedback via two cli scripts plus an extra script to keep the mouse pointer present. 


First script is simpleish - 

ffplay -f x11grab -follow_mouse centered -framerate 23 -vf "rotate=-1.23" -vf vflip -video_size 640x640 -i :0.0
 

Second script is slightly more complex - 

ffmpeg -f x11grab -follow_mouse centered -framerate 23 -video_size 640x640 -i :0.0 -f x11grab -follow_mouse centered -framerate 23 -video_size 640x640 -i :0.0 -lavfi '[1]split[x][y],[0][x][y]displace' -f rawvideo -pix_fmt yuv420p - | ffplay -f rawvideo -pix_fmt yuv420p -vf "rotate=1.23" -s 640x640 -


The most complex script is the one to focus the mouse and keep it awake and move it slightly every so often - run as a bash script from the command line -

echo "Press CTRL+C to stop…"
sleep 10
eval $(xdotool getmouselocation --shell)
echo $X,$Y
while :
do

xdotool mousemove $X $Y
sleep 5
xdotool mousemove_relative -- 0 -5
sleep 2
xdotool mousemove_relative -- 5 -5
sleep 2
xdotool mousemove_relative 0 5
sleep 2
xdotool mousemove_relative -- -5 5

#list for user change of mouse position

xdotool click 5
EXIT_CODE=$?
if [ $EXIT_CODE -eq 0 ]; then
eval $(xdotool getmouselocation --shell)
echo $X,$Y
fi
done


For topicality here is a chatgpt explanation of the second ffmpeg script.I originally fed the script in and asked it to suggest or add different filters and it just regurgitated the original script I'd just asked it to add too, but the explanation is pretty spot on I do love stochastic parrots). Maybe bard will do a better job!!

'Here's a breakdown of the filters used in this script:

    Input: -f x11grab -follow_mouse centered -framerate 23 -video_size 640x640 -i :0.0
    This sets up the first x11grab input for capturing the screen at a framerate of 23, with a video size of 640x640 pixels. The follow_mouse centered option captures the region around the mouse cursor and centers it in the output.

    Input: -f x11grab -follow_mouse centered -framerate 23 -video_size 640x640 -i :0.0
    This sets up the second x11grab input, similar to the first one.

    Filter: -lavfi '[1]split[x][y];[0][x][y]displace'
    This filter splits the second input into two streams ([x][y]) and performs the displace filter on the first input using the two streams. The split filter is used to duplicate the second input stream, so it can be used in both the [x] and [y] parts of the displace filter.

    Filter: -vf "rotate=1.23"
    This filter applies a rotation transformation to the video frames. The 1.23 value represents the rotation angle in radians.

    Output: -f rawvideo -pix_fmt yuv420p -
    This sets up the output format as raw video with YUV420 pixel format and pipes it to the next command.

    Player: | ffplay -f rawvideo -pix_fmt yuv420p -s 640x640 -
    This pipes the raw video output to ffplay for playback. The -s 640x640 option specifies the output display size as 640x640 pixels.

Feel free to adjust the parameters or add more filters as per your requirements.


I've also experimented with using the mandelbrot filter in place of one of the x11grab inputs ie replacing this -f x11grab -follow_mouse centered -framerate 23 -video_size 640x640 -i :0.0 with this -f lavfi -i mandelbrot=s=640x640 -framerate 23 which will give me this :

 


so there is a lot of room for variation and exploration within this space.



Wednesday, 26 April 2023

Four or five windows.

 

Ever had the need to have five or six ffplay windows running on screen at the same time and in specified places? Well after much reading of a manual page and trial and error for placement I came up with this script on PureOS linux. I've migrated most of my boxes over to fully fsf approved os's now. More info on PureOS here https://www.pureos.net/ and list of FSF approved Linux distros here https://www.gnu.org/distros/free-distros.html . 

Its taken a while for me to get to this stage and I had to abandon the idea of using a non systemd based distro like Gnuinos and I really don't have the  time to install Parabola which though good can be a little haphazard and no longer has an up to date Live Lxde version which for most people is the easiest way of running and installing ( I've installed from both the live lxde version and the cli installation version and the cli install is just antiquated and painful ) so PureOS it is . I had tried Trisquel  but as great as it is it doesnt allow for installing python3-pip without workarounds, I get the argument that python3-pip is problematic but as PureOS allows me to install it PureOS it is . 

Below is the script for opening multiple windows on a linux system running PureOS ( though it should work in other linux distros with a recent ffmpeg installed)  on ICEWM - adjust window size and position for your screen size - this is for 1366x768)

#! /bin/bash
#./background.sh &
ffplay -f x11grab -follow_mouse centered -framerate 5 -video_size 1280x720 -i :0.0 &
# top left hand corner
ffplay -left 0 -top 0 -f x11grab -follow_mouse centered -framerate 5 -video_size 320x288 -i :0.0 &
# top right hand corner
ffplay -left 1035 -top 0 -f x11grab -follow_mouse centered -framerate 5 -video_size 320x288 -i :0.0 &
# bottom left hand corner above toolbar
ffplay -left 0 -top 420 -f x11grab -follow_mouse centered -framerate 5 -video_size 320x288 -i :0.0 &
# bottom right corner
ffplay -left 1035 -top 420 -f x11grab -follow_mouse centered -framerate 5 -video_size 320x288 -i :0.0 &
# centre large 640x480
#ffplay -f x11grab -follow_mouse centered -framerate 5 -video_size 640x480 -i :0.0 &
# centre small
ffplay -f x11grab -follow_mouse centered -framerate 5 -video_size 320x288 -i :0.0

So ya gotta shiny new mac and want to run linux scripts?

 So, you've sold your soul to the devil and bought a shiny new or second hand ( in my case ) mac book pro ( with the shiny new apple sil...