Compress Video for Slack using FFmpeg

So yesterday, I wanted to share a screen recording with a colleague over Slack. I didn’t however want them to spend unnecessary seconds downloading a “huge file” so obviously I went to Google, to figure out how to make a video for Slack smaller!

I know, I know.. There are plenty of websites where you can upload the video, and they will compress it for you for free, but do I really want to upload my videos to random places on the internet? Who know where it’ll end up!?

Enter FFmpeg! From this answer on StackOverflow, on the question How can I reduce a video’s size with ffmpeg? it was suggested to compress it using libx264 and further using libx265. So, on to my WSL,

sudo apt-get install ffmpeg -y

A ~260MB bundle of joy later, and I was ready to compress my mkv! And off I went with libx265..

ffmpeg -i 2021-06-24-21-07-54.mkv vcodec libx265 -crf 28 output.mp4

From 84MB to ~4.16MB a pretty nice reduction if I must say so myself! 4.95% of the original filesize to be exact.

I posted it on Slack and what happened. I’d sent a small video on Slack! “Yay….wait..” It didn’t work, the video did not play on Slack. My colleague could download the video and play it, but that’s not really what I wanted by “sending a video over Slack.” On to this issue MP4 videos are not playing in Slack with the solution “…Changing it to h264 fixed it!”

So I thought… The answer on SO actually did have an older solution embedded, where they just suggested libx264… Let’s try that,

ffmpeg -i 2021-06-24-21-07-54.mkv vcodec libx264 -crf 28 output-lib264.mp4

And great success! The compression was “only” to 4.25MB, so 5.05% of the original filesize, negligibly more than the 4.95%, but even better… It plays on Slack! Which was the problem I was trying to solve in the first place 💪

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.