Spiega documentation
- Knowledge sharing
- Portfolio
multimedia utils
Multimedia utils
Here is a collection of useful scripts created over 16y to manage multimedia 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
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', '.png', '.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}")
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
echo ${i/.mp4/.gif}
#ffmpeg -i $i -y -vf "fps=10,scale:500-1,palettegen" -loop 0 ${i/.mp4/.gif}
#ffmpeg -i $i -vf "palettegen" -y palette.png
#ffmpeg -i $i -y -vf "fps=10" -i palette.png -filter_complex "paletteuse" -loop 0 ${i/.mp4/.gif}
ffmpeg -i $i -y -vf "fps=10,scale=500:-1:flags=lanczos" \
${i/.mp4/.gif}
done
grouce_explosion.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
png2avi
init=0
for i in *png
do
j=$(printf "%04d" $init)
## mv $i render$j.png
mv $i render$i
init=$(($init + 1))
done
ffmpeg -i render%4d.png -pix_fmt yuv420p -r 25 output.mp4
rm -r tmp
mkdir -p tmp
x=1; for i in *png; 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.png -c:v prores_ks -profile:v 4444 -pix_fmt yuva444p10le -alpha_bits 8 -q:v 20 output.mov
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/1Subdevice #0: subdevice #0card 0: NVidia [HDA NVidia], device 7: HDMI 1 [HDMI 1]Subdevices: 1/1Subdevice #0: subdevice #0card 0: NVidia [HDA NVidia], device 8: HDMI 2 [HDMI 2]Subdevices: 1/1Subdevice #0: subdevice #0card 0: NVidia [HDA NVidia], device 9: HDMI 3 [HDMI 3]Subdevices: 1/1Subdevice #0: subdevice #0card 1: Generic [HD-Audio Generic], device 3: HDMI 0 [HDMI 0]Subdevices: 1/1Subdevice #0: subdevice #0card 2: Generic_1 [HD-Audio Generic], device 0: ALC245 Analog [ALC245 Analog]Subdevices: 1/1Subdevice #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.shcapture_video.shconvert_format.shdeshake.shdownload_website.shextract_frames.shframe_interpolate.shgrab_video.shimg2pdf.shimg2video.shmidi_bluetooth.shpackage_media.shpal2mp4.shplayer_bash.shrecordSoundCard.shrecord_soundcard.shreduce_video.shresize_video.shreverseClip.shrotate_180.shrotate_90.shrotate_metadata.shsnd_baudline.shsnd_cards.shsnd_convert.shsnd_recordSoundcard.shstabilize_clip.shstabilize_gyro.shstream_screen.shstream_usb.shtransparent_video.shwebcam.sh