Suddenly, your disk is full of photos and videos, and there are new trips ahead. What to do, buy a new one, rent a disk space on the cloud, or can it better compress video files via ffmpeg ?
But why limit yourself to saving disk space? I propose to learn the amazing possibilities of processing photos, audio and video data, command line utilities.
The open source library ffmpeg is most likely already installed on your operating system. If not, install it with a regular package management program; it won't take long.
ffmpeg -i file.<old_extension> [options] file.<new_extension>
Reduce the video recorded on the camera:
ffmpeg -i MVI_4703.MOV MVI_4703.avi
The same, but with quality control.
ffmpeg -i MVI_4703.MOV -q:v 4 MVI_4703.avi
The video size has decreased by more than 5 times without noticeable loss of quality. The -qscale:vn
option, abbreviated to -q:vn
allows you to set the quality level of the generated video stream, where n
takes values in the range from 1 to 31. Value 1 corresponds to the best quality, and 31 - to the worst.
-rw-r--r-- 1 mig users 124M 18 23:29 foto/MVI_4703.avi -rw-r--r-- 1 mig users 686M 27 21:38 foto/MVI_4703.MOV
To select the codec we need, use the -c:a <codec> -c:v <codec>
keys.
ffmpeg -i video.mp4 -c:v vp9 -c:a libvorbis video.mkv
You can see all supported codecs using the ffmpeg -codecs
.
Now take this user case happening. Your TV's built-in player supports the mkv format, but does not support m4v. In order to change the container, use the following command.
ffmpeg -i video.m4v -c:av copy video.mkv
If you only need to change the sound, and leave the video as it is, run this command. For some reason, Phillips TVs understand only the AAC / AC3 audio formats.
ffmpeg -i video.m4v -c:v copy -c:a aac video.mkv
Simply enumerate the input files and set the output.
ffmpeg -i video.mp4 -i audio.ogg video_sound.mp4
If you just need to extract the sound, then you can.
ffmpeg -i video.MOV -vn audio.ogg
Specify the format of the extracted audio track.
ffmpeg -i video.MOV -vn -c:a flac audio.flac
Indicates the acceptable bitrate, by default 128k will be recorded.
ffmpeg -i video.MOV -vn -c:a flac -b:a 192k audio.flac
The same case, when it was smooth on paper. In practice, you have to walk around the rake, pushing through the inconsistency of formats, codecs, sizes and orientation of photos.
ffmpeg -r .3 -pix_fmt rgba -s 1280x720 -pattern_type glob -i "*.JPG video.mkv
Some explanation is required.
ffmpeg -pix_fmts
. Not with all formats it turns out to set the desired frame size.printf
format, for example image%03d.png
for all image0001.png
, image0002.png
, etc.Suppose you do not need the entire video file, but only a part of it. This command cuts 10 seconds of video starting from the first minute.
ffmpeg -i video_full.m4v -c:av copy -ss 00:01:00 -t 10 video_short.m4v
How to improve the quality of audio or video streams? To do this, use the key bit- -b
.
ffmpeg - video.webm -c:a copy -c:v vp9 -b:v 2M final.mkv
To capture the screen, an x11grab
device is x11grab
, and ffmpeg should be built with the --enable-x11grab
.
ffmpeg -f x11grab -framerate 25 -video_size 4cif -i :0.0 out.mpg
info ffmpeg-utils
.For automatic photo processing is convenient to work with the program ImageMagick . Change the size of all photos in the folder.
mogrify -resize 60% *.png
Accurate image sharpening, like Smart Sharpen using a Perl script that uses convert
and composite
from the ImageMagick toolkit .
Source: https://habr.com/ru/post/333664/
All Articles