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
@ankurhora

This comment has been minimized.

Copy link

@ankurhora ankurhora commented May 31, 2016

It increased the size instead of descreasing ?

@samhh

This comment has been minimized.

Copy link

@samhh samhh commented Jun 29, 2016

Worked well for me, from ~67MB to ~14MB. Thanks!

Edit: Appears to not play in IE. Blast.

@BeetLab

This comment has been minimized.

Copy link

@BeetLab BeetLab commented Sep 22, 2016

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

@ksharsha

This comment has been minimized.

Copy link

@ksharsha ksharsha commented Oct 31, 2016

@ankurhora This code basically does transcoding, hence if the input video is already compressed, the output video could be larger than the input one. To achieve compression, we can reduce the bit rate. Look at the code here https://gist.github.com/ksharsha/b06d184391290bc3b87fdadadb73c5bc#file-ffmpeg-compress

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Jun 3, 2017

@BeetLab I faced the same problem. Changing -acodec mp2 to -acodec mp3 did the trick for me.

@TryTryAgain

This comment has been minimized.

Copy link

@TryTryAgain TryTryAgain commented Aug 5, 2017

ffmpeg -i input.mp4 -vcodec h264 -acodec aac output.mp4 brought mine from 86457565 Bytes > 17195361 Bytes ~17MB ...wow, quality is really not even noticeably different. Thank you. -acodec mp3 was slightly smaller at 17195155. Now I'm looking to get my webm file down in size, hoping in a similar way.

@tigercosmos

This comment has been minimized.

Copy link

@tigercosmos tigercosmos commented Sep 8, 2017

@TryTryAgain It works pretty well, and do it twice can compress more.

@AffanIndo

This comment has been minimized.

Copy link

@AffanIndo AffanIndo commented Nov 16, 2017

It compress from 450 MB to 60 MB!
This is amazing.
But what is the thing that this command remove? Since I can't find any difference. Is the bitrate decreased?

@Noppez

This comment has been minimized.

Copy link

@Noppez Noppez commented Dec 23, 2017

worked great, from 294 MB to 46.7 MB and still good quallity

Thanks!

@sunnyarora21

This comment has been minimized.

Copy link

@sunnyarora21 sunnyarora21 commented Jan 16, 2018

Worked not expected.. I used 68.5Mb and get 65 MB ..

Thanks!

@Drgabi18

This comment has been minimized.

Copy link

@Drgabi18 Drgabi18 commented Feb 2, 2018

220 MB to 21MB

coder moment

@dheerajbhaskar

This comment has been minimized.

Copy link

@dheerajbhaskar dheerajbhaskar commented Feb 7, 2018

163mb to 60mb. This worked

@vkudyushev

This comment has been minimized.

Copy link

@vkudyushev vkudyushev commented Feb 12, 2018

5Gb mov file (from after effects) downgraded to 250 Mb. Perfect!

@KievAndres

This comment has been minimized.

Copy link

@KievAndres KievAndres commented May 7, 2018

De 1.06 GB a 229 MB. Genial!

@bassel999

This comment has been minimized.

Copy link

@bassel999 bassel999 commented May 20, 2018

I tried to have the same code but doing the bulk compress but it didn't work anyone can help?'

for %%a in ("*.mp4") do ffmpeg -i "%%a" -i vcodec h264 -b:v 700k -acodec mp3 "FB\%%~na.mp4"

@crazy4groovy

This comment has been minimized.

Copy link

@crazy4groovy crazy4groovy commented Jun 2, 2018

try:

for %%a in ("*.mp4") do ffmpeg -i "%%a" -vcodec h264 -b:v 700k -acodec mp3 "FB%%a~na.mp4"

@JanOwiesniak

This comment has been minimized.

Copy link

@JanOwiesniak JanOwiesniak commented Jun 13, 2018

Worked as expected

ffmpeg -i input.mp4 -vcodec h264 -acodec aac output.mp4

Before 32.8 MB

After 6.8 MB

@lfuelling

This comment has been minimized.

Copy link

@lfuelling lfuelling commented Jun 27, 2018

4,40 GB to 3,84 GB... I expected better.

@flamendless

This comment has been minimized.

Copy link

@flamendless flamendless commented Jul 1, 2018

Woah, 300mb to 8mb

@Agile-SM

This comment has been minimized.

Copy link

@Agile-SM Agile-SM commented Jul 26, 2018

I have 33MB and it command do a file more big...

@Ehsan-khaveh

This comment has been minimized.

Copy link

@Ehsan-khaveh Ehsan-khaveh commented Sep 13, 2018

3.2gb to 320mb. And quality difference is very hard to see!

@ahmubashshir

This comment has been minimized.

Copy link

@ahmubashshir ahmubashshir commented Sep 15, 2018

ffmpeg -i input.mp4 -vcodec libx265 -acodec aac -crf 23 output.mp4

Did the trick for me.

Before 400 mb

After 150 mb

@7statum

This comment has been minimized.

Copy link

@7statum 7statum commented Sep 28, 2018

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

Before : 124,2 mb

After ffmpeg 113,4 mb 👎

@IgorDePaula

This comment has been minimized.

Copy link

@IgorDePaula IgorDePaula commented Nov 1, 2018

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

@thepante

This comment has been minimized.

Copy link

@thepante thepante commented Nov 3, 2018

Here 14,9mb to 2,9mb - 00:56 yuv420p 480x480

@SwapnilSoni1999

This comment has been minimized.

Copy link

@SwapnilSoni1999 SwapnilSoni1999 commented Nov 10, 2018

Worked! Thanks a lot

used ffmpeg -i input.mp4 -vcodec h264 -acodec aac output.mp4
Before 738MB
After 192MB
with no quality loss + flawless sound!

@CobaltXII

This comment has been minimized.

Copy link

@CobaltXII CobaltXII commented Nov 11, 2018

Worked. Before: 1.6 MB. After: 132 KB. However, it doesn't work on videos with a width or height that is not divisible by 2. Not a big issue though.

@opensas

This comment has been minimized.

Copy link

@opensas opensas commented Nov 21, 2018

Great!!

I tried compressing following this thread: https://gist.github.com/ksharsha/b06d184391290bc3b87fdadadb73c5bc

ffmpeg -i video.mp4 -vcodec h264 -b:v 1000k -acodec mp3 output.mp4

and went from 1.1 GB to 69 MB!!!

@tylerphillip

This comment has been minimized.

Copy link

@tylerphillip tylerphillip commented Dec 28, 2018

So, first all thanks to the developers and coder. I've been using FFMPEG with the Sick Beard MP4 automator and it's working beautifully! Now as I'm watching it work, I wish I could shrink the file size down when it auto converts. So, I stumbled upon this thread. i am a total noob to all of this so forgive my ignorance, but where do I add this script to make FFMPEG compress as the automator is working? I'm running Sonarr, Radarr, SabNZBd, and of course the Sick Beard MP4 Automator scripts.

Thanks in advance and again sorry for my ignorance if this is a totally stupid question!

@x3inspire

This comment has been minimized.

Copy link

@x3inspire x3inspire commented Jan 1, 2019

try:

for %%a in ("*.mp4") do ffmpeg -i "%%a" -vcodec h264 -b:v 700k -acodec mp3 "FB%%a~na.mp4"

Does it work?

@Zeryther

This comment has been minimized.

Copy link

@Zeryther Zeryther commented Apr 8, 2019

27 GB -> 9.56 GB 👍

@baskax

This comment has been minimized.

Copy link

@baskax baskax commented Apr 29, 2019

with mp3 as audio codec 832MB -> 53.1MB
thanks a lot!

@Ardeshir81

This comment has been minimized.

Copy link

@Ardeshir81 Ardeshir81 commented May 17, 2019

Great
from 274 to 36
Thanks
(But changed mp2 to mp3)

@JamesSMF

This comment has been minimized.

Copy link

@JamesSMF JamesSMF commented May 19, 2019

I guess this works great for large size videos. I got my video from 750 mb to 57 mb. Thanks.

@neelkadia

This comment has been minimized.

Copy link

@neelkadia neelkadia commented Jun 11, 2019

This is legit! Thanks!

@eshanokpe

This comment has been minimized.

Copy link

@eshanokpe eshanokpe commented Aug 22, 2019

pls how do i impliment this

@Thearas

This comment has been minimized.

Copy link

@Thearas Thearas commented Jan 7, 2020

Try this:
ffmpeg -i input.mp4 -c:v libx265 -preset veryfast -tag:v hvc1 -vf format=yuv420p -c:a copy output.mp4

or this if you want to decrease the resolution and bitrate, it should be much more smaller than above:
ffmpeg -i input.mp4 -c:v libx265 -preset veryfast -tag:v hvc1 -b:v new_bitrate -vf scale=new_width:new_height,format=yuv420p -c:a copy output.mp4
e.g. ffmpeg -i input.mp4 -c:v libx265 -preset veryfast -tag:v hvc1 -b:v 800k -bufsize 1200k -vf scale=1080:1920,format=yuv420p -c:a copy output.mp4

of course, you can decrease the bitrate of audio stream either:
ffmpeg -i input.mp4 -c:v libx265 -preset veryfast -tag:v hvc1 -b:v 800k -bufsize 1200k -vf scale=1080:1920,format=yuv420p -b:a 128k output.mp4

If your device does not support h265, just change the -c:v libx265 into -c:v libx264 and remove the -tag:v hvc1.

@vcorbit

This comment has been minimized.

Copy link

@vcorbit vcorbit commented Feb 19, 2020

This worked really well for me, made my videos much smaller and the quality was still comparable.

However, I'm curious if you could expand on how the "h264" line is compressing? Is it using a default CRF level? I found that instead compressing using "libx264 -crf 10" produced a MUCH larger video.

@geekmichael

This comment has been minimized.

Copy link

@geekmichael geekmichael commented Apr 12, 2020

Worked! Thanks a lot

used ffmpeg -i input.mp4 -vcodec h264 -acodec aac output.mp4
Before 738MB
After 192MB
with no quality loss + flawless sound!

Thanks for sharing this trick! Worked for me as well. I had one video file successfully compressed to 253.9MB from 950.1MB.

updated version

But using 'ffmpeg -i input.mp4 -vcodec libx265 -crf 28 output.mp4' it reduced to 105MB which is much better.

@BruceGitHub

This comment has been minimized.

Copy link

@BruceGitHub BruceGitHub commented May 11, 2020

top 👍

@gopukrishnantec

This comment has been minimized.

Copy link

@gopukrishnantec gopukrishnantec commented Jun 2, 2020

711M input.MP4
101M output.mp4
Awesome (y)

@msarelo

This comment has been minimized.

Copy link

@msarelo msarelo commented Jul 14, 2020

19 MB input
39 MB output
👎

@abkoradiya

This comment has been minimized.

Copy link

@abkoradiya abkoradiya commented Jul 15, 2020

19 MB input
39 MB output
👎

Have you found any solution?

@jonathanrodriguezs

This comment has been minimized.

Copy link

@jonathanrodriguezs jonathanrodriguezs commented Jul 21, 2020

280MB to 80MB (71% less) thanks

@abkoradiya

This comment has been minimized.

Copy link

@abkoradiya abkoradiya commented Jul 25, 2020

280MB to 80MB (71% less) thanks

Can you show your command?

@Rachidbendadande

This comment has been minimized.

Copy link

@Rachidbendadande Rachidbendadande commented Jul 29, 2020

I used This : ffmpeg -i Input.mov -c:v libx265 -preset veryfast -tag:v hvc1 -vf format=yuv420p -c:a copy output.mp4 ----- and went from 301 mb To 30.9 mb ---- with a littel bit of quality loss. but it works for Me if I want to get my video to Facebook.
for youtube I would use : ffmpeg -i input.mp4 -vcodec h264 -acodec aac output.mp4 --- probably no quality Loss. So I'm happy 👍

@Scylla2020

This comment has been minimized.

Copy link

@Scylla2020 Scylla2020 commented Aug 15, 2020

Worked. Before: 1.6 MB. After: 132 KB. However, it doesn't work on videos with a width or height that is not divisible by 2. Not a big issue though.
Divisible or not it still didnt work for me. I had a 6min 1920x1040 file at 186MB and it only went down to 123MB

@savrajsingh-temboo

This comment has been minimized.

Copy link

@savrajsingh-temboo savrajsingh-temboo commented Aug 24, 2020

712 mb gopro video of office down to 86 mb! almost 1/10th the size!
command ffmpeg -i input.mp4 -vcodec h264 -acodec aac output.mp4

@kranthi0987

This comment has been minimized.

Copy link

@kranthi0987 kranthi0987 commented Oct 2, 2020

not working for me i am saving the file from ipcam and need to reduce the size

original size is 13 mb
ffmpeg -i input.mp4 -vcodec h264 -acodec aac output.mp4
after size is 19 mb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.