You can reduce the size of a video by reducing the resolution with the ffmpeg program.
Install:
sudo apt install ffmpeg
Lower the quality, for smaller files
Add for example -crf 26
to reduce the quality, where 23 is the default, 0 is lossless and 51 is worst quality.
This simple example, reduces the quality a bit with the -crf 26
parameter, while simply copying the sound:
ffmpeg -i video.mp4 -vcodec libx264 -acodec copy -crf 26 video-crf-26.mp4
This example resizes to max 360p in vertical screen resolution, or height, in pixels, lowering the quality a bit with -crf 26
:
ffmpeg -i video.mp4 -vcodec libx264 -crf 26 -c:a aac -b:a 128k -vf scale=-2:360,format=yuv420p video-360p.mp4
Batch compress movies files with ffmpeg
Shrink multiple files with these commands. The libx265 codec is faster, but the result can be choppy.
Inside a folder with mp4 movies, create a folder called "encoded"
mkdir encoded;
Compress mp4 files in current folder into "encoded" folder
Compressing a video with -crf 26
can reduce a video size with around 60%.
for f in *.mp4; do ffmpeg -i "$f" -vcodec libx264 -acodec copy -crf 26 "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 -acodec copy -crf 26 "encoded/${f%}.mp4"; done
Edit video length
To shorten a video, define starting position with -ss
and duration with -t
.
-ss
: First argument time is from time
-t
: Second argument is duration (not end time) in seconds
ffmpeg -ss 25 -t 13 -i my-movie.mp4 -vcodec copy -acodec copy my-movie-edited.mp4
Or define start and end time, from 00:42:30 to 00:51:00:
ffmpeg -ss 00:42:30 -to 00:51:00 -i "input.mp4" -c copy output.mp4
Bulk create thumbnails
Ratio based on 1920x1080, 16:9 aspect ratio:
for f in *.mp4; do ffmpeg -i "$f" -ss 00:00:03 -vframes 1 -s 640x360 "${f%.mp4}.jpg"; done