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 for datamoshing ( in an avi container), divides that video/s into n second chunks ( in a format we choose and in specific resolutions). Depending on what options are chosen when script is started it will run rgb shifting, displacement, and datamoshing on each chunk ( datamoshing is limited to removing iframes and tomatos pulse mode ) randomising file names then finally putting everything back together as one video in the output folder. It also removes files and cleans up after itself after ( having moved the source files into a folder named originals ) .
It works on linux and windows though to run this on windows ( tested on 10 only) you need to change the references to python3 to python , that's all ) you will also need to have tomato.py in the directory you run the script from and you will also need to have ffmpeg installed.
Copy and paste the script below and name it something interesting with .sh extension run from bash on linux and gitbash on windows 10.
#! /bin/bash
#which directory are we in ?
h=$(pwd)
echo $h
mkdir $h/originals
mkdir $h/work
mkdir $h/output
mkdir $h/dispt
mkdir $h/work2
mkdir $h/tmpd
echo -n "Source video extension ? : "
read f
#for f in *\ *; do mv "$f" "${f// /_}"; done
echo -n "Time segment (1-10 seconds in format 00) ? : "
read ts
echo -n "Codec to use (1)mpeg4, (2)h264, (3)mpeg2video, (4)h261,(5)theora, (6)Insta, (7)4:3 ? : "
read cd
#use rgb shift
echo -n "Use rgbashift (n=no, rh(red), gh(green), bh(blue)) ? : "
read rgb
#are we killing iframes?
echo -n "Kill Iframes (y/n) ? : "
read kif
#are we datamoshing ?
echo -n "Are we datamoshing (y/n) ? : "
read dm
# get values for pulse mode only
if [ $dm == "y" ] || [ $dm == "null" ]
then
echo -n "Number of frames to duplicate ? : "
read fdup
echo -n "Every n frames ? : "
read nfr
elif [ $dm == "n" ]
then
sleep 2
fi
echo -n "Are we using displacment (y/n) ? : "
read disp
if [ $disp == "y" ] || [ $disp == "null" ]
then
echo -n "Reverse the first video before displacement (y/n) ? : "
read rev
fi
#do we need to split long videos into thirty second chunks?
#echo -n "Cut up long videos (y/n) : ? "
#read cut
#if [ $cut == "y" ] || [ $cut == "null" ]
# then
# echo -n "Source video extension ? : "
#read f
#echo -n "Time segment (seconds in format 00) ? : "
#read ts2
#find . -maxdepth 1 -name '*.'$f''|while read filename; do echo ${filename};
#ffmpeg -i ${filename} -c copy -map 0 -segment_time 00:00:$ts2 -f segment -reset_timestamps 1 ${filename%.*}%3d.$f
#mv ${filename} $h/originals/
#done
# elif [ $cut == "n" ]
# then
#echo -n " Not cutting Long videos "
#fi
#find videos and convert them to codec and avi container and strip metadata with -map_metadata -1
if [ $cd == "1" ] || [ $cd == "null" ]
then
for i in *.$f; do ffmpeg -i "$i" -map_metadata -1 -vf "scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:-1:-1,setsar=1" -c:v mpeg4 -bf 0 -q 0 "${i%.*}.avi";done
elif [ $cd == "2" ]
then
for i in *.$f; do ffmpeg -i "$i" -map_metadata -1 -vf "scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:-1:-1,setsar=1" -c:v h264 -bf 0 -crf 23 "${i%.*}.avi";done
elif [ $cd == "3" ]
then
for i in *.$f; do ffmpeg -i "$i" -map_metadata -1 -vf "scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:-1:-1,setsar=1" -c:v mpeg2video -bf 0 -q 0 "${i%.*}.avi";done
elif [ $cd == "4" ]
then
for i in *.$f; do ffmpeg -i "$i" -map_metadata -1 -c:v h261 -bf 0 -q 0 -s 352x288 "${i%.*}.avi";done
elif [ $cd == "5" ]
then
for i in *.$f; do ffmpeg -i "$i" -map_metadata -1 -vf "scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:-1:-1,setsar=1" -c:v libtheora -qscale:v 7 -bf 0 "${i%.*}.avi";done
elif [ $cd == "6" ]
then
#for instagram and sqaure aspect ratio first crop and increase to 1080x1080 then rencode to get correct sar and dar and aspect ratio
for i in *.$f; do ffmpeg -i "$i" -map_metadata -1 -vf "scale=1080:1080:force_original_aspect_ratio=increase,crop=1080:1080,pad=1080:1080:-1:-1,setsar=1" -c:v mpeg4 -qscale:v 7 -bf 0 "${i%.*}.avi"; done
#for i in *.$f; do ffmpeg -i "$i" -map_metadata -1 -vf "scale=1080:1080:force_original_aspect_ratio=decrease,pad=1080:1080:-1:-1,setsar=1" -c:v mpeg4 -qscale:v 7 -bf 0 "${i%.*}.avi";done
elif [ $cd == "7" ]
then
for i in *.$f; do ffmpeg -i "$i" -map_metadata -1 -vf "scale=800:600:force_original_aspect_ratio=increase,crop=800:600,pad=800:600:-1:-1,setsar=1" -c:v mpeg4 -qscale:v 7 -bf 0 "${i%.*}.avi"; done
fi
mv *.$f $h/originals/
#Convert video/s into $ts time segments
for i in *.avi; do ffmpeg -i "$i" -c copy -map 0 -segment_time 00:00:$ts -f segment -reset_timestamps 1 $h/work/"${i%.*}%3d.avi";
done
#if we are rgb shifting do it now before everything else
if [ $rgb == "rh" ] || [ $rgb == "null" ]
then
cd $h/work/
for i in *.avi; do ffmpeg -i "$i" -vf "rgbashift=rh=-30" -pix_fmt yuv420p -q 0 rgb.avi;
mv rgb.avi "$i";done
elif [ $rgb == "gh" ]
then
cd $h/work/
for i in *.avi; do ffmpeg -i "$i" -vf "rgbashift=gh=-30" -pix_fmt yuv420p -q 0 rgb.avi;
mv rgb.avi "$i";done
elif [ $rgb == "bh" ]
then
cd $h/work/
for i in *.avi; do ffmpeg -i "$i" -vf "rgbashift=bh=-30" -pix_fmt yuv420p -q 0 rgb.avi;
mv rgb.avi "$i";done
elif [ $rgb == "n" ]
then
echo -n "No Rgb vaporwave goodness for u then!!!:"
fi
cd $h/
#move to $h/work/ and randomise files
cp tomato.py $h/work/
cd $h/work/
find . -maxdepth 1 -name '*.avi'|while read filename; do echo ${filename};
mv ${filename} ${RANDOM}${RANDOM}.avi; done
#use tomato or other to remove iframes in those chunks bar first frame
#find . -maxdepth 1 -name '*.avi'|while read filename; do echo ${filename};
#python3 tomato.py -i ${filename}
#rm ${filename}
#done
#NOTE TO SELF DISPLACE BEFORE IKILLER OR DATAMOSH
find . -maxdepth 1 -name '*.avi'|while read filename; do echo ${filename};
mv ${filename} ${RANDOM}${RANDOM}.avi; done
#are we using displacement as well ?
if [ $disp == "y" ] || [ $disp == "null" ]
then
#chop pulsed avis' down to 3 seconds for displacement
for i in *.avi; do ffmpeg -i "$i" -c copy -map 0 -segment_time 00:00:$ts -f segment -reset_timestamps 1 -q 0 "${i%.*}%3d.avi";done
cp *.avi $h/dispt/
cd $h/dispt/
find . -maxdepth 1 -name '*.avi'|while read filename; do echo ${filename};
mv ${filename} ${RANDOM}${RANDOM}.avi; done
i=$(ls *.avi | wc -l)
echo $i
while [ $i -gt 0 ]
do
#do displacement
find . -maxdepth 1 -name '*.avi' | head -n 2 | xargs -d $'\n' mv -t $h/work2/
cd $h/work2/
z=1
rename files to swap1 and swap2
find . -maxdepth 1 -type f -name '*.avi'|while read filename; do echo ${filename};
mv ${filename} swap$z.avi
((z++));
done
#reverse the first video before displacement
if [ $rev == "y" ] || [ $disp == "null" ]
then
ffmpeg -i swap1.avi -filter_complex "reverse" -an -q 0 reverse.avi
mv reverse.avi swap1.avi
fi
#
ffmpeg -i swap1.avi -i swap2.avi -lavfi '[1]split[x][y],[0][x][y]displace' -q 0 swap3.avi
#tm=$(date +%Y-%m-%d_%H%M%S)
mv swap3.avi $h/tmpd/${RANDOM}.avi
sleep 1
rm swap1.avi
rm swap2.avi
rm swap3.avi
cd $h/dispt/
i=$((i-=2))
done
cd $h/tmpd/
mv *.avi $h/work/
cd $h/work/
elif [ $disp == "n" ]
then
echo -n " No displacement then, right so "
fi
#Are we killing Iframes?
if [ $kif == "y" ] || [ $kif == "null" ]
then
find . -maxdepth 1 -name '*.avi'|while read filename; do echo ${filename};
python3 tomato.py -i ${filename}
rm ${filename}
done
elif [ $kif == "n" ]
then
echo -n " No Iframes were harmed in this process :"
fi
#are we datamoshing as well ?
if [ $dm == "y" ] || [ $dm == "null" ]
then
find . -maxdepth 1 -name '*.avi'|while read filename; do echo ${filename};
python3 tomato.py -i ${filename} -m pulse -c $fdup -n $nfr;
done
elif [ $dm == "n" ]
then
echo -n " Not datamoshing on to outputting Long videos "
fi
#find . -maxdepth 1 -name '*.avi'|while read filename; do echo ${filename};
#mv ${filename} ${RANDOM}${RANDOM}.avi; done
find . -maxdepth 1 -name '*.avi'|while read filename; do echo ${filename};
mv ${filename} ${RANDOM}${RANDOM}.avi; done
#concat
d=$(date +%Y-%m-%d_%H%M%S)
printf "file '%s'\n" ./*.avi > mylist.txt ; ffmpeg -f concat -safe 0 -i mylist.txt -c copy $d.avi ; rm mylist.txt
#clean up
cd $h/
rm *.avi
cd $h/work/
mv $d.avi $h/output/
rm *.avi
cd $h/