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

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

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

# Install imagemagick for convert
$ sudo apt install imagemagick


# change image format. add  optional: -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

# resize to 50%
convert screenshot.png  -resize 50%  screenshot.png

# 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

# convert to black and white
$ convert color.jpeg -type Grayscale blackwhite.jpeg

Metadata

Посмотреть метаданные:

identify -verbose file.jpg

Удалить метаданные:

mogrify -strip file.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
# speed-up video 2x times (new video duration is 0.5 of old video duration)
ffmpeg -i decap-cms.mp4 -filter:v "setpts=0.5*PTS" decap-cms-fast.mp4

# slow-down video 2x times (new video duration is 2x of old video duration)
ffmpeg -i decap-cms.mp4 -filter:v "setpts=2.**PTS" decap-cms-slow.mp4
# Reverse video only
ffmpeg -i input.mp4 -vf reverse reversed.mp4

# Reverse video + audio
ffmpeg -i input.mp4 -vf reverse -af areverse reversed.mp4
# concatenate two or more video
echo file file1.mp4 >  mylist.txt 
echo file file2.mp4 >> mylist.txt
echo file file3.mp4 >> mylist.txt

:: Concatenate Files
ffmpeg -f concat -i mylist.txt -c copy output.mp4
comments powered by Disqus