Spiega documentation
- Knowledge sharing
- Portfolio
multimedia utils
automate audio, video, sound pipelines
Multimedia utils
Here is a collection of useful scripts created over 16y to manage multimedia processing.

Figure 1: audio processing
audio
#cat ~/lav/src/malastro/media/audio_extract.sh ffmpeg -i $1 -q:a 0 -map a $outF.mp3
player
A nice terminal player
sudo apt install moc mocp
pipewire
We currently use pipewire.
#sudo apt install pipewire pipewire-audio wireplumber pipewire-pulse pipewire-alsa pipewire-jack systemctl --user enable pipewire pipewire-pulse wireplumber systemctl --user start pipewire pipewire-pulse wireplumber systemctl --user disable pulseaudio systemctl --user mask pulseaudio pw-cli --version pactl info | grep "Server Name"
pw-cli Compiled with libpipewire 1.6.2 Linked with libpipewire 1.6.2 Server Name: PulseAudio (on PipeWire 1.6.2)
jack audio
Low latency, high quality audio routing ref1.
sudo apt-get install jackd2 qjackctl #sudo apt install carla # more featured interface sudo groupadd realtime sudo usermod -a -G realtime $USER
Start
pulseaudio --kill jack_control start jack_control exit pulseaudio --start #jackd -r 44100 -p 256 -d alsa
Connect
jack_connect synthesizer:output_1 daw:input_1
images
web optimization
Png to jpg and rescale
cd $HOME/lav/src/spiega/script/ python3 image_for_web.py ~/Pictures/bkp_png/f_stage
from PIL import Image
import os, sys
max_edge = 1000
baseDir = os.environ['HOME'] + '/lav/siti/f/f_storia/'
fL = os.listdir(baseDir)
for f in fL:
supported_formats = ('.jpg', '.jpeg', '.jpg', '.bmp', '.tiff', '.webp')
with Image.open(baseDir + f) as img:
width, height = img.size
larger_dimension = max(width, height)
if larger_dimension > max_edge:
scale_factor = max_edge / larger_dimension
new_width = int(width * scale_factor)
new_height = int(height * scale_factor)
resized_img = img.resize((new_width, new_height), Image.LANCZOS)
resized_img.save(baseDir + f, quality=85, optimize=True)
print(f"Resized {f} from {width}x{height} to {new_width}x{new_height}")
raw pictures
Using darktable and ligthzone
sudo add-apt-repository ppa:lightzone-team/lightzone -y sudo apt install darktable lightzone

Figure 2: darktable
alpha
White to alpha, alpha to white
cd ~/Pictures/bkp_png/f_stage/
for i in *png;
do
convert $i -alpha remove -background white -compose over $i
done
convert raw
for i in *CR2
do
###### convert -define jpeg:size=128x128 $i -thumbnail 128x128 ${i/CR2/jpg}
##dcraw -z $i;
##touch -r $i $i.jpg
done
video to gif
We need to convert video clips into light gif for blog posts
cd ~/VideoProd/clip/
#for i in *mp4; do
for i in *webm; do
outF=${i/.webm/.gif}
echo $outF
#ffmpeg -i $i -y -vf "fps=10,scale:500-1,palettegen" -loop 0 ${i/.mp4/.gif}
#ffmpeg -i $i -vf "palettegen" -y palette.jpg
#ffmpeg -i $i -y -vf "fps=10" -i palette.jpg -filter_complex "paletteuse" -loop 0 ${i/.mp4/.gif}
ffmpeg -i $i -y -vf "fps=10,scale=500:-1:flags=lanczos" $outF
done
internet_search.gif
audio from video
Extract audio from video
cd ~/VideoProd/in_prog/stagno/
for i in *mp4; do
#echo $i
ffmpeg -i $i -q:a 0 -map a ${i/mp4/mp3}
done
remove silence from video
We want to remove silence from video clip
cd ~/VideoProd/clip/ bash ~/lav/src/malastro/media/video_cut_silence.sh obs_try.mp4 obs_voice.mp4
video
deshake video
To deshake a video we need first to create a vector transform which computes the camera movements compared to the images movement and reconstruct the 3d scene.
#cat ~/lav/src/malastro/media/deshake.sh ffmpeg -y -i unstable_$fName -vf vidstabdetect -f null - ffmpeg -y -i unstable_$fName -vf vidstabtransform,unsharp=5:5:0.8:3:3:0.4 $fName
jpg2avi
init=0
for i in *jpg
do
j=$(printf "%04d" $init)
## mv $i render$j.jpg
mv $i render$i
init=$(($init + 1))
done
ffmpeg -i render%4d.jpg -pix_fmt yuv420p -r 25 output.mp4
rm -r tmp mkdir -p tmp x=1; for i in *jpg; do counter=$(printf %04d $x); ln "$i" tmp/img"$counter".jpg; x=$(($x+1)); done ffmpeg -y -f image2 -r 5 -i tmp/img%04d.jpg -s 1920x1080 -vcodec mjpeg -vcodec libx264 -r 25 out.mp4
compress video
for i in *mkv;
do
fOut=../MP4/${i/mkv/mp4}
echo $fOut
ffmpeg -i "$i" -map 0 -c copy -c:a aac tmp.mp4
ffmpeg -i tmp.mp4 -vf scale=1920:1080 "$fOut"
rm tmp.mp4
done
Compress web
ffmpeg -y -i "$1" -s 720x480 -c:a copy small_$1
transparent video
ffmpeg -framerate 30 -i scene%04d.jpg -c:v prores_ks -profile:v 4444 -pix_fmt yuva444p10le -alpha_bits 8 -q:v 20 output.mov
codec
We need to install some propertary codecs
sudo apt mpv # video player sudo apt install gstreamer1.0-plugins-bad sudo apt install libavcodec-extra gstreamer1.0-plugins-ugly gstreamer1.0-libav sudo apt install ubuntu-restricted-extras
digital audio workstation
How to work with a DAW
interfaces
Current choice is pipewire.
grep audio /etc/group aplay -l
audio:x:29: **** List of PLAYBACK Hardware Devices **** card 0: NVidia [HDA NVidia], device 3: HDMI 0 [HDMI 0] Subdevices: 1/1 Subdevice #0: subdevice #0 card 0: NVidia [HDA NVidia], device 7: HDMI 1 [HDMI 1] Subdevices: 1/1 Subdevice #0: subdevice #0 card 0: NVidia [HDA NVidia], device 8: HDMI 2 [HDMI 2] Subdevices: 1/1 Subdevice #0: subdevice #0 card 0: NVidia [HDA NVidia], device 9: HDMI 3 [HDMI 3] Subdevices: 1/1 Subdevice #0: subdevice #0 card 1: Generic [HD-Audio Generic], device 3: HDMI 0 [HDMI 0] Subdevices: 1/1 Subdevice #0: subdevice #0 card 2: Generic_1 [HD-Audio Generic], device 0: ALC245 Analog [ALC245 Analog] Subdevices: 1/1 Subdevice #0: subdevice #0
cd /tmp/ sox -b 16 -n test.wav rate 44100 channels 2 synth 1 sine 440 gain -1 aplay -D hw:0 test.wav
systemctl --user start pulseaudio.socket pulseaudio.service pipewire-pulse.socket pipewire-pulse.service pipewire.socket pipewire.service
midi
There are different options to work with midi ref1.
Let’s install standard packages
#sudo apt install fluidsynth timidity sox fluid-soundfont-gm alsa-utils aconnectgui
We can play midi with alsa, fluidsynth or timidity.
cd ~/lav/viudi/mus/bolla/ fluidsynth --audio-driver=alsa -o audio.alsa.device=hw:2 /usr/share/sounds/sf2/FluidR3_GM.sf2 Corsa.midi
timidity
timidity -Oj -iAD
Couldn't open JACK device (`j')
aplaymidi -l
| Port | Client | name | Port | name | |
| 14:0 | Midi | Through | Midi | Through | Port-0 |
aplaymidi -p 14:0 ~/lav/viudi/mus/bolla/Corsa.midi
aconnect -i aconnect 129:0 128:0
client 0: 'System' [type=kernel]
0 'Timer '
1 'Announce '
client 14: 'Midi Through' [type=kernel]
0 'Midi Through Port-0'
VST
install juce desktop and mobile c++ platform for desktop and mobile applications and cmake to build c++ code.
sudo apt install -y juce-tools juce-modules-source wget https://github.com/BaraMGB/JuMake/releases/latest/download/jumake-linux-x64.deb sudo dpkg -i jumake-linux-x64.deb
Compile vst source
cd ~/Elŝutujo/ #git clone https://github.com/DatanoiseTV/epi.git cd ./epi-main cmake . -B cmake-build -DJUCE_BUILD_EXAMPLES=ON -DJUCE_BUILD_EXTRAS=ON #cmake --build build --target EpiHeadless
-- Configuring incomplete, errors occurred!
Lauch datanoise VST with pipewire jack
cd ~/Elŝutujo/epi-linux/stage/Epi/ pw-jack ./Epi
other
ls ~/lav/src/malastro/media/
audio_extract.sh capture_video.sh convert_format.sh deshake.sh download_website.sh extract_frames.sh frame_interpolate.sh grab_video.sh img2pdf.sh img2video.sh midi_bluetooth.sh package_media.sh pal2mp4.sh player_bash.sh recordSoundCard.sh record_soundcard.sh reduce_video.sh resize_video.sh reverseClip.sh rotate_180.sh rotate_90.sh rotate_metadata.sh snd_baudline.sh snd_cards.sh snd_convert.sh snd_recordSoundcard.sh stabilize_clip.sh stabilize_gyro.sh stream_screen.sh stream_usb.sh transparent_video.sh webcam.sh
Created: 2026-11-26 Thu 14:45