Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Compress mp4 using FFMPEG
$ ffmpeg -i input.mp4 -vcodec h264 -acodec mp2 output.mp4
@ochen1
Copy link

ochen1 commented Mar 3, 2021

Before: 60.0MB
After: 96.3MB
Didn't work for me! 🙁

@Rachidbendadande
Copy link

Rachidbendadande commented Mar 4, 2021

@k0ssa
Copy link

k0ssa commented Mar 16, 2021

image
didn't work for me xD

@7thstorm
Copy link

7thstorm commented Mar 23, 2021

I'm using the -crf parameter

ffmpeg -i output_fr_20210322020810.avi -c:v libx264 -crf 28 output_fr_20210322020810.mp4

it is working for me. depending on your use case, you may want to decrease the crf value for higher quality and large file size, or increase it for smaller file size

@Rachidbendadande
Copy link

Rachidbendadande commented Mar 24, 2021

@henfrydls
Copy link

henfrydls commented Apr 2, 2021

I used h.265 codec and the file quality remaind while drop down from 3.31GB to 1.36GB (41.09%), I also used "acodec copy" in order to keep the original audio.

ffmpeg -i input.mp4 -vcodec libx265 -acodec copy output.mp4

@henfrydls
Copy link

henfrydls commented Apr 2, 2021

image
didn't work for me xD

Try it using libx265 instead of h264

@tincho
Copy link

tincho commented Apr 6, 2021

Commands using Linux with ffmpeg to shrinking big MP4 video file to smaller sizes

  • ffmpeg -i input.mp4 -vcodec h264 -acodec mp2 out.mp4
    • 3.6 Gb to 556 Mb, great quality 🥇
  • ffmpeg -i input.mp4 -s 1280x720 -acodec copy -y output.mp4
    • 3.6 Gb to 62 Mb, quality "good enough"/acceptable 👍
  • ffmpeg -i input.mp4 -vcodec h264 -b:v 1000k -acodec mp3 output.mp4
    • 3.6 Gb to 30 Mb, very shitty quality 💩

@tlboright
Copy link

tlboright commented Apr 29, 2021

ffmpeg -i input.mp4 -vcodec h264 -acodec aac output.mp4
13.6 GB recorded from obs to 197MB

Thank you guys!

@j-masci
Copy link

j-masci commented May 11, 2021

Compressed my video from 9mb to 2mb, but when I opened it 80% of the video was missing. I guess that's one way to compress a video.

@dgcollard
Copy link

dgcollard commented May 12, 2021

help i tried this and smoke came out of my laptop and all the birds fell out of the sky

video works great though, thanks

@mtemel123
Copy link

mtemel123 commented May 26, 2021

folder and subfolder
echo START %date% %time% >> C:\zv.txt && FORFILES /s /p . /m "*.mp4" /C "cmd /c ffmpeg -i @file -vcodec h264 -acodec aac v_@file && for %I in (v_@file) do (echo @path;@fsize;%~zI) >> C:\zv.txt && del @file && ren v_@file @file" && echo ==FINISH== %date% %time% >> C:\zv.txt && rundll32 user32.dll,MessageBeep && msg "%username%" video comp done

@irishgordo
Copy link

irishgordo commented Jul 6, 2021

rad little trick!
great for doing some quick screengrabs with Kazam, then squeezin' um down!
Got a screencast that was around a minute long - from 9.6MB down to 3.9MB 🔥 🔥
(was great because max file size was 8MB on upload for chat app)
hella rad!
thank ya!!!

@ChiaraLinaCasadei
Copy link

ChiaraLinaCasadei commented Aug 2, 2021

It worked excellently

At first Powershell didn't recognize "ffmpeg" as valid, but I made a little change suggested by @Patacon13 , I hope it helps people with the same issue

./ffmpeg -i input.mp4 -vcodec h264 -acodec mp3 out.mp4

125mb to 57.7mb

@HinaAroraByjus
Copy link

HinaAroraByjus commented Aug 24, 2021

Its not work for me, I want reduce an webm video and 616mb to 480mb and very time spended =/

Hi,
I am also working on Webm file. But I need need end result in mp4.
Should I convert it in mp4 first and then reduce the size ??

@HinaAroraByjus
Copy link

HinaAroraByjus commented Aug 24, 2021

For webm file, it didn't work as expected.
Input SIze - 9144478
Output Size - 20795660

@ArnabXD
Copy link

ArnabXD commented Sep 16, 2021

For webm file, it didn't work as expected.
Input SIze - 9144478
Output Size - 20795660

Probably this is the reason. I noticed this to be true many times

WebM vs MP4: File Size and Quality

But since WebM is specially designed for the Internet, the compression ratio of WebM is generally higher than MP4 in theory, which leads to more original quality loss than MP4. And the file size of WebM is a little bit smaller than MP4.

https://www.winxdvd.com/answers/webm-vs-mp4.htm

@HinaAroraByjus
Copy link

HinaAroraByjus commented Sep 16, 2021

For webm file, it didn't work as expected.
Input SIze - 9144478
Output Size - 20795660

Probably this is the reason. I noticed this to be true many times

WebM vs MP4: File Size and Quality

But since WebM is specially designed for the Internet, the compression ratio of WebM is generally higher than MP4 in theory, which leads to more original quality loss than MP4. And the file size of WebM is a little bit smaller than MP4.

https://www.winxdvd.com/answers/webm-vs-mp4.htm

Thanks ArnabXD,
I have change my approach little.
I was converting the puppeteer stream into mp4 and wanted to stitch the local files and then upload to S3.

Now, I am using AWS Media Converter to perform the same on S3 bucket itself.

@justCatalyst
Copy link

justCatalyst commented Oct 12, 2021

Compressed from 14.1 mb to 4.9 mb. But lost sound( how can i fix it? Any options?

the output for audio is mp2 - maybe you don't have a codec for that?

@143maha
Copy link

143maha commented May 8, 2022

how to live telecast 24/7

@abdennour
Copy link

abdennour commented May 27, 2022

WORKS EXCELLENT

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

for MacOs, you need to preserve compatibility encoding H.265/HEVC for QuickTime:

ffmpeg -i input.mp4 -c:v libx265 -preset fast -crf 28 -tag:v hvc1 -c:a eac3 -b:a 224k output.mp4

@dotkt
Copy link

dotkt commented Jun 8, 2022

thank you

@Thomashighbaugh
Copy link

Thomashighbaugh commented Jun 14, 2022

ffmpeg -i input.mp4 -vcodec h264 -acodec mp2 out.mp4
3.6 Gb to 556 Mb, great quality 1st_place_medal
ffmpeg -i input.mp4 -s 1280x720 -acodec copy -y output.mp4
3.6 Gb to 62 Mb, quality "good enough"/acceptable +1
ffmpeg -i input.mp4 -vcodec h264 -b:v 1000k -acodec mp3 output.mp4
3.6 Gb to 30 Mb, very shitty quality hankey

Thanks worked beautifully for me on Linux, really appreciate tip!

@deroverda
Copy link

deroverda commented Jun 27, 2022

ffmpeg -i input.mp4 -vcodec h264 -acodec mp2 out.mp4
3.6 Gb to 556 Mb, great quality 1st_place_medal
ffmpeg -i input.mp4 -s 1280x720 -acodec copy -y output.mp4
3.6 Gb to 62 Mb, quality "good enough"/acceptable +1
ffmpeg -i input.mp4 -vcodec h264 -b:v 1000k -acodec mp3 output.mp4
3.6 Gb to 30 Mb, very shitty quality hankey

Thanks worked beautifully for me on Linux, really appreciate tip!

tried the 1st_place_medal ffmpeg command AKA ffmpeg -i input.mp4 -vcodec h264 -acodec mp2 out.mp4

before: 49 mb
after: 63 mb

in other words, not gold medal for me. using win 10.

@mcagabe19
Copy link

mcagabe19 commented Jul 28, 2022

ffmpeg -i input.mp4 -vcodec libx265 -acodec aac -crf 28 output.mp4
best way (used termux)

@gideonseven
Copy link

gideonseven commented Aug 16, 2022

Commands using Linux with ffmpeg to shrinking big MP4 video file to smaller sizes

ffmpeg -i input.mp4 -vcodec h264 -acodec mp2 out.mp4
3.6 Gb to 556 Mb, great quality 🥇
ffmpeg -i input.mp4 -s 1280x720 -acodec copy -y output.mp4
3.6 Gb to 62 Mb, quality "good enough"/acceptable 👍
ffmpeg -i input.mp4 -vcodec h264 -b:v 1000k -acodec mp3 output.mp4
3.6 Gb to 30 Mb, very shitty quality 💩

using

ffmpeg -i input.mp4 -vcodec h264 -acodec mp2 out.mp4

from 52MB to 28MB

works well for me on windows 11, thank you @tincho

@async-dime
Copy link

async-dime commented Aug 30, 2022

thankyou!
using ffmpeg -i input.avi -c:v libx264 -crf 18 output.mp4
input: 1.4 GB
output: 132.2 MB

@ligantx
Copy link

ligantx commented Sep 4, 2022

Commands using Linux with ffmpeg to shrinking big MP4 video file to smaller sizes

  • ffmpeg -i input.mp4 -vcodec h264 -acodec mp2 out.mp4
    • 3.6 Gb to 556 Mb, great quality 🥇
  • ffmpeg -i input.mp4 -s 1280x720 -acodec copy -y output.mp4
    • 3.6 Gb to 62 Mb, quality "good enough"/acceptable 👍
  • ffmpeg -i input.mp4 -vcodec h264 -b:v 1000k -acodec mp3 output.mp4
    • 3.6 Gb to 30 Mb, very shitty quality 💩

good enough worked fine for me..To my "average human" eye, i coudlnt find any real difference with the original video compared side by side (original: 1gb to good enough: 296mb)

Edit:
if you wanna go lower try changinng -b:v value e.g.:
ffmpeg -i input.mp4 -vcodec h264 -b:v 700k -acodec mp3 output.mp4
and if you don't want sound try:
ffmpeg -i input.mp4 -vcodec h264 -b:v 700k -an output.mp4

My experiment:

  • ffmpeg -i input.mp4 -vcodec h264 -b:v 1000k -an output.mp4
    32MB to 3.6MB
  • ffmpeg -i input.mp4 -vcodec h264 -b:v 200k -an output.mp4
    32MB to 742KB

@basicbh
Copy link

basicbh commented Sep 17, 2022

dont forget the FPS,its amazing.

@MdHassan413
Copy link

MdHassan413 commented Sep 28, 2022

I'm passing media from Postman and getting an error.
[WinError 2] The system cannot find the file specified
I'm compressing media like this :
subprocess.run(f'ffmpeg -i {media} -vcodec h264 -acodec {file_type} temp_location/{new_uuid}')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment