Resizing and shrinking videos with ffmpeg

ffmpeg resizing

You can reduce the size of a video by reducing the resolution with the ffmpeg program.

Install:

sudo apt install ffmpeg

Usage:

ffmpeg -i original-title.mp4 -r 30 -s 640*360 result-title.mp4

Explanation of -r and -s options:

$ man ffmpeg
-r[:stream_specifier] fps (input/output,per-stream)
   Set frame rate (Hz value, fraction or abbreviation).

-s[:stream_specifier] size (input/output,per-stream)
   Set frame size.

Batch compress movies files with ffmpeg

Shrink multiple files with these commands. The libx265 codec is faster, but the result can be choppy.

Enter folder with mp4 movies, and create folder "encoded"

cd movie_folder;
mkdir encoded;

Compress mp4 files in current folder into "encoded" folder

for f in *.mp4; do ffmpeg -i "$f" -vcodec libx264 \
-c:a aac -b:a 128k -vf scale=-2:720,format=yuv420p \
"encoded/${f%.mp4}.mp4"; done

Compress videos of all formats in current folder into "encoded" folder

for f in *.*; do ffmpeg -i "$f" -vcodec libx264 \
-c:a aac -b:a 128k -vf scale=-2:720,format=yuv420p \
"encoded/${f%}.mp4"; done