Digital residency on feminist peertube instance

Jump to navigation Jump to search

/// [PEERTUBE] ///

LOG// Bash notes ± documentation during the residency// use these at your own risk ;) // i am interested in working with both code and language from the accentuated position of auto (the self), because I am driven to bring attention to unedited, raw, unapologetic, "failed", local, small scale approaches to the production of knowledge //in a way trying to nurture the curiosity for code rather than the efficiency or correctness, because one has to start somewhere and have fun(!) and personal DIY learning can bring out a certain creativity and ideas (and naughtiness) that an academic approach cant // not everyone can afford a CS degree or bootcamp or spend alot of time on self-learning, therefore practicing when we can and how we can should feel less naughty ;)

Week 1[edit]

Tesseract - documentation

> to convert jpg to png // multiple files in a folder:

ls -1 *.JPG | xargs -n 1 bash -c 'convert "$0" "${0%.JPG}.png"'

> to rotate 1 img 90 degrees clockwise:

 convert file.jpg -rotate 90 file.jpg 

> to rotate all imgs in a folder:

 for photo in *.jpg ; do convert $photo -rotate 90 $photo ; done


> takes an img > recognizes txt > creates pdf with the image and txt selectable and searchable:

 tesseract IMG_5223.png IMG_5223 -l eng --psm 11 pdf 

> multiple:

 ls -1 *.png | xargs -n 1 bash -c 'tesseract "$0" "${0%.png}" -l eng --psm 11 pdf' 

> output txt from the pdf in same layout as in the img:

 pdftotext -layout IMG_5223.pdf - 

> output all txt from all img-pdfs into a collected .txt file:

 for i in *.pdf; do pdftotext -layout $i - >> coke.txt; done


> turn .txt file into text2speech sound file:
espeak documentation

 espeak -w coke.wav < coke.txt 

playing videos on mpv[edit]

> playing 2 videos on loop at the same time:

mpv --loop --screen=1 --autofit=100%x100% cokevid.mp4 --external-file=cokevid.mp4 --lavfi-complex='[vid1] [vid2] hstack [vo]'

> playing 4 videos on loop at the same time:

mpv --loop --screen=1 --autofit=100%x100% cokevid.mp4 --external-file=cokevid.mp4 --external-file=cokevid.mp4 --external-file=cokevid.mp4 --lavfi-complex='[vid1] [vid2] hstack [t1] ; [vid3] [vid4] hstack [t2] ; [t1] [t2] vstack [vo]'

make a video from imgs[edit]

> if imgs are not numbered sequentially

ffmpeg -framerate 10 -pattern_type glob -i "IMG_*.png" cokevid.mp4

> if they have proper order in the folder then:

ffmpeg -framerate 10 -i %d.png coketext.mp4

to produce blank video[edit]

> method 1:

ffmpeg -f lavfi -i color=black:s=1920x1080:r=24000/1001 -f lavfi -i anullsrc -ar 48000 -ac 2 -t 20 output.mp4

> method 2: step1: make a blank image with imagemagick:

convert -size 1920x1080 xc:black black.png

step2: loop the video with ffmpeg

ffmpeg -loop 1 -i black.png -acodec copy -shortest output.mp4

some explanations of settings:

-t:       length of the video (in H:m:s format 00:00:00 or in seconds 0.000)
-s:       frame size
-f:       video format
-pix_fmt: pixel format
-r:       fps
-i:       input -- textfile-2-video[edit]

ingredients: - imagemagick - ffmpeg - mpv



#needed to get a sentance instead of one word

echo save as #to give a video name
read savename
echo enter text filename # to choose the textfile to be used for video
read textname

#takes the text file outputs a line or word at a time and makes a png-img for each line/word 
for line in $(cat $textname.txt);
# for line in $(cat this.txt);
	# echo "$n $line" #word per line
	echo "$n ${line}" #sentance per line
	sleep 1
	# convert -size 1200x800 xc:red -pointsize 72 -fill white  -draw "text 25,65 '$line'" $n.png
	convert -size 1200x800 xc:red -pointsize 72 -fill white  -draw "text 25,65 '${line}'" $n.png
IFS="$OFS" #needed to get a sentance instead of one word

# takes the pngs and makes them into a video
ffmpeg -framerate 5 -i %d.png $savename.mp4
rm *.png #deletes all the png image frames

#play the clip on loop
mpv --loop --screen=1 $savename.mp4

video overlay[edit]

> to place a video on top of another video:

ffmpeg -i background-video.mp4 -i overlay-video.mp4 -filter_complex "[1:v]scale=800:-1[tmp];[0][tmp]overlay=shortest=1:x=10:y=10" overlay-video.mp4

> if the overlay-video is shorter than the background-video, looping the overlay-video possible for the duration of the background-video by adding "-stream_loop -1"

ffmpeg -i background-video.mp4 -stream_loop -1 -i overlay-video.mp4-filter_complex "[1:v]scale=800:-1[tmp];[0][tmp]overlay=shortest=1:x=10:y=10" overlay-video.mp4

scrolling text[edit]

> text (from text file) scrolling up on top of a background-video:

ffmpeg -i background-video.mp4 -filter_complex "[0]split[txt][orig];[txt]drawtext=fontfile=helvetica.ttf:fontsize=95:fontcolor=white:box=1:boxcolor=blue:x=10:y=h-30*t:textfile=yourtextfile.txt[txt];[orig]crop=iw:50:0:0[orig];[txt][orig]overlay" -c:v libx264 -y -preset ultrafast output.mp4

> text scrolling from right to left on black 1920x1080 background:

ffmpeg -f lavfi -i color=s=1920x1080 -ss 00:00:00 -t 00:01:00 -filter_complex "[0]split[txt][orig];[txt]drawtext=fontfile=tahoma.ttf:fontsize=40:fontcolor=green:x=(w-text_w)/2+20:y=h-40*t:textfile=yourtextfile.txt:bordercolor=white:borderw=2[txt];[orig]crop=iw:50:0:0[orig];[txt][orig]overlay" -c:v libx264 -y -preset ultrafast output.mp4 

> text scrolling from right to left on top of a background-video:

ffmpeg -i background-video.mp4 -vf "drawtext=textfile=yourtextfile.txt:fontfile=bpmono.ttf:y=h-line_h-800:x=w-mod(max(t-1\,0)*(w+tw)/300\,(w+tw)):fontcolor=00ff00:fontsize=300:shadowx=2:shadowy=2" output.mp4

some explanations of settings:

fontfile:       font-family
fontsize:       text size
fontcolor:      text color
textfile:  the file you want to use
instead of textfile its possible to use just a line of text > instead of "textfile=yourtextfile.txt" use "text='hello-world'"
bordercolor:    text border color
borderw:        text border width
scale:          scale of video in px
x:              video position on x axis
y:              video position on y axis
color=s= :      video size (width x height)

others i havent looked into yet, please feel free to add/edit :)       

results week1[edit]

> [hhypercoem]
> [week1_auto_tut]

Week 2[edit][edit]

> a script to create short audio experiemnts/recordings with a reversed audio effect :) > basically > (rec1_reversed + rec2_reversed) + rec3_not_reversed = result_audio_composition
I have only tested this on Mac, so if you try it on Linux/Windows and modify, please share your version!


echo enter the title: #name of the end audio file
read audioname 

echo start recording 1 now #record 60 sec audio 1
ffmpeg -f avfoundation -i ":1" -t 60 first.mp3

echo start recording 2 now #record 60 sec audio 2
ffmpeg -f avfoundation -i ":1" -t 60 second.mp3

echo start recording 3 now #record 60 sec audio 3
ffmpeg -f avfoundation -i ":1" -t 60 $audioname.mp3

#reverse audio-1 and audio-2
ffmpeg -i first.mp3 -af areverse first-rev.mp3
ffmpeg -i second.mp3 -af areverse second-rev.mp3

#merge reversed audio-1 and reversed audio-2
ffmpeg -i second-rev.mp3 -i first-rev.mp3 -filter_complex "[0:a][1:a]amerge=inputs=2[a]" -map "[a]" rev-output.mp3 
#merge output of previous merge with audio-3 (which is not reveresed)
ffmpeg -i rev-output.mp3 -i $audioname.mp3 -filter_complex "[0:a][1:a]amerge=inputs=2[a]" -map "[a]" $audioname-output.mp3 

mv $audioname-output.mp3 $audioname.mp3 #rename the file from previous step to its final name
mkdir results #make folder for final audio files
mv $audioname.mp3 results
rm *.mp3 #delete all mp3s apart from the final
mpv results/$audioname.mp3 #listen :)

> to list your available audio/video devices use:

ffmpeg -f avfoundation -list_devices true -i ""

some explanations of settings:

avfoundation -i:     audio input number // my built-in mic is ":1", but when i use audio interface it changes to ":1" // that is where the command above (listing devices) is handy
-t:                  the length of a recording // in seconds[edit]

> i made this script for cropping a number of videos in the same size (in this case in strips) and then joining them together:



echo save as
read result

echo number of diff videos to be used # enter a digit
read v

echo enter video filenames without format and amount that chosen previously # video1 video2 video3 // sequance is important
read -a arr #create an array with video filenames

# crop each video in the array 
for i in ${arr[@]}
   ffmpeg -i $i.mp4 -ss 00:00:00 -t 00:01:00 -filter:v "crop=192:1080:1:1" $result-$x.mp4 #could also be -i pathtovideos/$.mp4

ffmpeg -i $result-1.mp4 -i $result-2.mp4 -filter_complex hstack -c:v libx264 -crf 0 output-$y.mp4 #joins 2 first videos into one

# joins the rest
for (( n=3; n<=$v; n++ ))
	ffmpeg -i output-$y.mp4 -i $result-$n.mp4 -filter_complex hstack -c:v libx264 -crf 0 output-$((y+1)).mp4

mv output-$(($v-1)).mp4 results #moves the final video to a folder "results" < need to mkdir this folder before hand
rm *.mp4 #deletes all the other workfile videos
crop=w:h:x:y:      w - width of the crop 
                   h - height of the crop 
                   x - the point on x-axis where the crop starts 
                   y - the point on y-axis where the crop starts[edit]

This script is similar to script, just here I discovered how to use arrays in bash :) also it is abit more simple and shorter script that does not use a texfile, but instead encourages writing. It uses Imagemagick and ffmpeg, so at the end it becomes a video and looses transparency. It could definitely be turned into a gif, maybe it is something i will work on later.

before I ran the script I created a png image (a shape) I could work with and overlay each word in the array with. I used this code:

convert -size 1000x600 xc:transparent -fill red -stroke black -draw "ellipse 500,300 400,200 0,360" draw_ellipse.png

and got this:



echo animation name
read anim

echo write your text 
read -a arr # time to write your txtxtxtxtxt // lets get creative and/or auto personal // creates an array

echo background image filename # the png image created before hand 
read imgb

for word in ${arr[@]} # i learned that @ is for all elements in array
	convert results/$imgb.png  xc:transparent -fill white -stroke white -font Helvetica -pointsize 200 -gravity center -draw "text 0,0 '$word'" $anim-$x.png
done # the background image needs to be put in the folder named results

ffmpeg -framerate 4 -i $anim-%d-0.png $anim.mp4 # for some reason it creates blank white images for the gaps between words but I made this part to ignore those and just use the good pngs :)

mv *.mp4 results # need to mkdir a folder named results before hand
rm *.png # deletes all the trash

mpv --loop --screen=1 results/$anim.mp4 # lets you preview the animation-video immediately on a loop which I found helpful

some explanations of imagemagick settings:

xc:transparent      makes the background of text transparent, but could also use color here
-fill               text color
-font               font-family
-pointsize          font-size
-gravity            here i use center, which places text in the middle of the shape-image

here are some ways I found to use arrays:

 ${myArray[@]}          all elements (space delimited)
"${myArray[@]}"         all elements (separate words)
"${myArray[*]}"         all elements (single word, separated by first character of IFS)
"${myArray[1]}"         specific element
"${myArray[@]:1:2}"     two elements, starting at second item
"${!myArray[@]}"        (indices) of an array

Week 3[edit]

I found this very usefull command in order to make a list of files in a folder and write that list into a txt file// this one works on Mac, there is also documentation for windows here (also were i found the code)// its was handy for joining multiple video snippets into one video:

> make a list

 for f in *.png; do echo "file '$f'" >> mylist.txt; done


> to join multiple videos into one:

 ffmpeg -f concat -safe 0 -i mylist.txt -c copy output.wav 

This week I was exploring ImageMagick and some distortion effects/options/modes :
- morphology
- #shepards
- #distort

morphology tests[edit]

what I did first was to just create a simple png img that i could work with and test

convert -size 100x100 xc:red -fill white -stroke white -font Helvetica -pointsize 50 -gravity center -draw "text 0,0 'test'" test.png


then I explored different options (from the documentation page) to see how it would affect the test-image:

 for r in 1 2 3 4; do
    # convert test.png -morphology Dilate Diamond:$r -scale 800% Diamond:$r.png
    # convert test.png -morphology Dilate Square:$r -scale 800% square:$r.png
    # convert test.png -morphology Dilate Disk:$r -scale 800% Disk:$r.png
    # convert test.png -morphology Dilate Corners:$r -scale 800% Corners:$r.png
    # convert test.png -morphology Dilate Rectangle:7+4x5+$r -scale 800% Rectangle:$r.png
    # convert test.png -morphology Dilate Ring:4.3,$r -scale 800% Ring:$r.png

shepards tests[edit]

it is quite an interesting distortion option, that I spent some time testing as I couldnt quite understand how exactly it affects the img, but the results were very exciting:

convert test.png -virtual-pixel Black -define shepards:power=8.0 -distort Shepards '32,11 20,11  50,29 58,29' t4.png
convert test.png -virtual-pixel Black -define shepards:power=8.0 -distort Shepards '35,11 20,11  55,29 58,29' t5.png
convert test.png -virtual-pixel Black -define shepards:power=8.0 -distort Shepards '15,11 20,11  65,29 58,29' t8.png
convert test.png -virtual-pixel Black -define shepards:power=8.0 -distort Shepards '45,11 20,11  50,29 58,29' t11.png
convert test.png -virtual-pixel Black -define shepards:power=8.0 -distort Shepards '85,11 20,11  5,29 58,29' t12.png
convert test.png -virtual-pixel Black -define shepards:power=8.0 -distort Shepards '35,1 20,11  99,99 58,29' t24.png
convert test.png -virtual-pixel Black -define shepards:power=8.0 -distort Shepards '35,15 20,11  39,35 58,29' t28.png
convert test.png -virtual-pixel Black -define shepards:power=32.0 -distort Shepards '35,11 50,11  39,37 1,29' t40.png
convert test.png -virtual-pixel Black -define shepards:power=10.0 -distort Shepards '35,11 20,11  39,37 89,29' t50.png
convert test.png -virtual-pixel Black -define shepards:power=10.0 -distort Shepards '35,11 110,11  39,37 35,29' t56.png
convert test.png -virtual-pixel Black -define shepards:power=10.0 -distort Shepards '35,11 80,59  39,37 15,11' t61.png
convert test.png -virtual-pixel Black -define shepards:power=10.0 -distort Shepards '35,11 80,9  39,37 15,99' t63.png
convert test.png -virtual-pixel Black -define shepards:power=25.0 -distort Shepards '45,11 20,11 50,29 58,29 50,29 20,11 35,11 80,29' t75.png
convert test.png -virtual-pixel Black -define shepards:power=15.0 -distort Shepards '35,11 80,11 35,11 39,37 35,11 80,99  39,37 15,1' t80.png
convert test.png -virtual-pixel Black -define shepards:power=15.0 -distort Shepards '85,11 20,11 45,29 58,29 35,1 20,11  99,55 58,2' t83.png
convert test.png -virtual-pixel Black -define shepards:power=15.0 -distort Shepards '32,11 20,11 50,29 58,29 35,11 20,11 55,29 58,29 45,11 20,11 50,29 58,29 50,29 20,11 35,11 80,29 35,11 80,29  39,37 15,11' t88.png
convert test.png -virtual-pixel Black -define shepards:power=8.0 -distort Shepards '35,11 100,11  39,37 1,29 35,55 20,11  55,55 58,29 32,11 20,11 50,29 58,29 39,37 15,11' t90.png

> I made 90 tests and then wanted to make gif out of them, basically pair each 3 following pngs (1-3, 4-6, 7-9, ...) and then output as a gif. for loops have always been a difficult concept for me for some reason, I always would forget how it works and in general didnt quite understand I think before really how it works, but I feel like during thsi residency I finally got more of a grip of them! this is what I came up with as a solution for my gif-wishes:


s=1 #first image number (from)
f=3 # last image number in loop (to)

for (( c=1; c<=30; c++)) # 90 images divided in 3 would make 30 loops/times to repeat the action
   	echo "$c loop" # this is just to print inside terminal, so I could see what is going on
  	for (( x=$s; x<=$f; x++)) #inside loop
  		echo "file 't$x.png'" #prints inside terminal
   		echo "'t$x.png'" >> mylist.txt; # puts the png file name into a text file
   		convert @mylist.txt $s-$f.gif # make a gif out of the named png files in the list 
   		mv $s-$f.gif gifs # moves each gif to a folder gifs // need to make this folder before hand
	sleep 1
   	s=$((s+3)) # add 3 to the first image number (so from 1-3 becomes 4-3)
   	f=$((f+3)) # add 3 to the last image number (so from 4-3 becomes 4-6)
   	rm mylist.txt #deletes the previous list


echo write your text 
read -a arr # time to write your txtxtxtxtxt // lets get creative and/or auto personal // creates an array

for word in ${arr[@]} # i learned that @ is for all elements in array
do #so it produces a png per words typed and then applies the arch effect with different degrees (30, 60, 90 ...) and outputs each arc degree to separate png
	convert -size 100x100 xc:red -fill white -stroke white -font Helvetica -pointsize 50 -gravity center -draw "text 0,0 '$word'" $word.png
	for r in 30 60 90 120 180 240 300 360; do 
		convert $word.png -distort Arc $r $word-$r.png
		mv $word-$r.png arc

rm $word.png # deletes the not distorted pngs
convert arc/$word-*.png $word.gif # makes the gif
mv $word.gif arc
rm arc/*.png

Arc-test.gif Arc-e.gif


a few other smaller commands I found use-full and tried out:

- cropping a circle shape out of a rectangle shape (this is based on rectangle image with dimensions 100x100):

 convert test.png -crop 100x100+0+0 +repage \( +clone -fill Black -colorize 16 -fill White -draw "circle 50,50,50,99" \) -alpha off -compose CopyOpacity -composite -fill None -stroke Red -strokewidth 1 -draw "circle 50,50,50,99" test-cirle.png

Test-circle.png Test2-circle.png

- the following command takes that circle and makes it rotate > turns it into animated gif:

 convert test-circle.png  -duplicate 29  -virtual-pixel none -distort SRT '%[fx:360*t/n]' -set delay '%[fx:t==0?240:10]' -loop 0 test-rotate.gif 

Test-rotate.gif Test2-rotate.gif

- this takes the rotate.gif further and makes this "roll" animation effect, which can create some glitchy effects if the text inside the circle is going over the border:

 convert test-rotate.gif  -duplicate 29  -virtual-pixel tile -distort SRT '0,0 1, 0, %[fx:w*t/n],%[fx:h*t/n]' -set delay 10 -loop 0 test-roll.gif 

Test-roll.gif Test2-roll.gif

Week 4[edit]

Trying out SoX (audio editing/production) for the first time instead of Ffmpeg.[edit]

Script/ composition sketch:



echo --save-as-- # enter the name for the recording (session)
read filename 

sox -d -c 1 $filename.wav trim 0 01:00 # one minute audio recording with one channel (mono)

sox $filename.wav $filename-c1.wav trim 00:30 00:05 pad 00:05 repeat 5 remix 0 1 # creates audio for right side
sox $filename.wav $filename-c2.wav trim 00:25 00:05 pad 0 00:05 repeat 5 remix 1 0 # creates audio for left side
sox $filename.wav $filename-c3.wav reverb 50 50 100 reverb 50 50 100 reverb 50 50 100 echo 0.8 0.9 1000 0.3 1800 0.25 # adds reverb and echo on the original recording and creates audio file 3

sox -m $filename-c1.wav $filename-c2.wav $filename-c4.wav # mix audio1 + audio2
sox -m $filename-c3.wav $filename-c4.wav $filename-final.wav # gain 30 # mix output of previous step with audio3

play $filename-final.wav

-c 1                  : 1 channel
trim 00:30 00:05      : audio length <start-point> <length-from-the-starting-point> 
pad 00:05             : adds 5 sec of silence before the audio clip
pad 0 00:05           : adds 5 sec of silence after the audio clip
repeat 5              : loops audio 5 times
remix 0 1             : mutes sound on left side
gain 30               : increase level by 30dB (if mic is silent)