Конвертирование картинок, видео и звука в CLI.

Обработка картинок

Нужен imagemagic, установка: apt install imagemagick

# Install imagemagick for convert
$ sudo apt install imagemagick


# change image format. add  optiona: -quality 90
$ convert sbni.png sbni.jpg

# resize to width 1000 (keep aspect ratio)
$ convert sbni.png -resize 1000 resized.png
$ file resized.png 
resized.png: PNG image data, 1000 x 271, 8-bit/color RGBA, non-interlaced

# resize to height 100 (keep aspect ratio)
$ convert sbni.png -resize x100 resized.png
$ file resized.png 
resized.png: PNG image data, 370 x 100, 8-bit/color RGBA, non-interlaced

# resize to 1000x1000 square (change aspect ratio)
$ convert sbni.png -resize 1000x1000! resized.png
$ file resized.png 
resized.png: PNG image data, 1000 x 1000, 8-bit/color RGBA, non-interlaced

# rotate
$ convert horizontal.jpg -rotate 90 vertical.jpg

# remove transparency to white (e.g. convert transparent png to jpg)
$ convert myimage.png -quality 80 -background white -alpha remove -alpha off myimage.jpg

Обработка звука

ffmpeg -i filename.ogg -acodec libmp3lame filename.mp3

# or even simpler!
ffmpeg -i filename.ogg filename.mp3

# lower volume
ffmpeg -i beep-10.mp3 -filter:a "volume=0.3" beep-10-low.mp3

Обработка видео

# convert and make size to ~100M
ffmpeg -i video.mp4 -fs 100M out.mov
# convert video for WhatsApp (16Mb limit)
ffmpeg -i MyVideo.mp4 -c:v libx264 -profile:v baseline -level 3.0 -pix_fmt yuv420p -fs 16M whatsapp.mp4
comments powered by Disqus