Today I was looking to compress a video for upload to social media. It was a few minutes of video from my phone. I figured 1MiB/min is good enough for MP3, so perhaps at 5MiB/min we can get good enough video? I actually only really cared about the audio, so video quality I was ready to sacrifice.
The video I got from the phone was 1015MiB. One Gigabyte! 🙄
A simple rescaling to CGA resolution suggested by @sejo brought that down to 14MiB!
ffmpeg -i "$1" -vf scale=320:240 "small-$1"
@makeworld added that I should be using “-acodec copy” in order to prevent audio from getting reencoded. Good point!
The following gets it down to 9MiB, based on a solution I found on StackExchange. Increasing “-crf” reduces the quality with up to 30 being noted as OK.
ffmpeg -i "$1" -vf "scale=trunc(iw/8)*2:trunc(ih/8)*2" \ -c:v libx265 -crf 28 "small-$1"
@ajroach42 had more to say. He suggested the VP9 codec, which isn’t super fast, but it’s still 10× faster than AV1. I tried it, and it is extremely slow. The key is that he uses a variable bit-rate and sets it so that a target size can be reached. I said I felt 4MiB/min was good and so you need to tweak that “-b:v 375” parameter below. Also note how he uses Opus for audio and reencodes that.
ffmpeg -i "$1" -c:v libvpx-vp9 -b:v 375K -c:a libopus -b:a 96k -ac 1 "small-$1.webm"
I find it amazing that we can get video size down by two orders of magnitude and it’s still good enough for sharing online.
@ajroach42 says:
I like webm with vp9 or AV1 and opus audio, with the bitrate forced down to something around 50Kbps for the video and 25Kbps for the audio.
And then he sends me a video that uses about 1MiB/min. Wow. And of course on his website he has examples using AV1 with less than 200KiB/min.
I’ve been playing with encoding videos at very low bitrates. My entry in the Small File Media Festival won Lowest Bitrate, clocking in at around 30Kbps. … It was fun, but I thought we could do better. – Unreasonably Low Bitrates
Amazing.
#Video
(Please contact me if you want to remove your comment.)
⁂
Phones and ridiculously huge file sizes, name a better duo. I still haven’t figured out how to change things on the phone end, it’s tedious having to do it once the file is uploaded.
– 2021-11-06 01:50 UTC
---
@kelbot suggested Video Transcoder on Android phones.
basically just a simple GUI frontend to ffmpeg.
– Alex 2021-11-06 10:39 UTC
---
Just now, to get 5s of train below 100k:
ffmpeg -i IMG_7239.MOV -vf scale=320:-1,hue=s=0 -ss 0:00:02 -to 0:00:07 \ -c:v libvpx-vp9 -r 10 -b:v 100K -c:a libopus -b:a 10k -ac 1 train.webm
– Alex 2021-12-10 10:11 UTC
---
@brion recently posted:
Stabilize handheld footage with this one weird command line trick:
`ffmpeg -i VID_20190628_090724.mp4 -vf 'vidstabdetect=tripod=1:shakiness=1' -y dummy.mp4 || exit 1`
`ffmpeg -i VID_20190628_090724.mp4 -vf 'vidstabtransform=tripod=1' -y un-stable.mp4`
– Alex 2022-05-04 06:21 UTC