FFmpeg - handling multimedia files

FFmpeg is the leading multimedia framework, able to decode, encode, transcode, mux, demux, stream, filter and play pretty much anything that humans and machines have created. It supports the most obscure ancient formats up to the cutting edge. No matter if they were designed by some standards committee, the community or a corporation. It is also highly portable: FFmpeg compiles, runs, and passes our testing infrastructure FATE across Linux, Mac OS X, Microsoft Windows, the BSDs, Solaris, etc. under a wide variety of build environments, machine architectures, and configurations.

It is the most convenient to handle multimedia file such as mp4, mp3, etc. using FFmpeg. The followings are the best and simple command for day to day tasks.

Converting

$ ffmpeg -i input.mp4 output.mp3

Cutting out or extracting a selected part from a movie (it can also be applied to audio file like .mp3)

$ ffmpeg -i input.mp4 -ss 00:05:00 -to 00:15:23 -c copy output.mp4

Scaling Image/Video

$ ffmpeg -i input.jpg -vf scale=320:240 output_320x240.pnf

$ ffmpeg -i input.avi -vf scale=320:240 output.avi

Scaling Image/Video Keeping Aspect Ratio

$ ffmpeg -i input.jpg -vf scale=320:-1 output_320.png

$ ffmpeg -i input.mp4 -vf scale=1200:-1 output_1200.mp4

Scaling - some codes require the size of width and height to be a multiple of n.

$ ffmpeg -i input.jpg -vf scale=320:-2 output_320.png

$ ffmpeg -i input.mp4 -vf scale=1200:-2 output_1200.mp4

see more details for scaling @ http://trac.ffmpeg.org/wiki/Scaling or scaling_ffmpeg_self_hosting_pdf

Reducing video file size

$ ffmpeg -i input.mp4 -vcodec libx265 -crf 28 output.mp4

the number after -crf can also be 28 or 24 or adjusted...

see https://unix.stackexchange.com/questions/28803/how-can-i-reduce-a-videos-size-with-ffmpeg and https://www.codegrepper.com/code-examples/shell/reduce+video+file+size+using+ffmpeg

Increasing/decreasing volume of media file

$ ffmpeg -i input.mp4 -vcodec copy -af "volume=30dB" output.mp4

the number of 30dB can be adjusted as 20dB or 50dB.

see https://www.axllent.org/docs/increase-volume-with-ffmpeg/ and https://vuyisile.com/linux-how-to-increase-video-volume-without-re-encoding-video/

...