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







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...