How to resize a video to make it smaller with FFmpeg

115

43

Is it possible to resize my videos to make them smaller with FFmpeg?

I have an original video dimensions of 1024x576, now I want to resize the video to 720x480 to meet the requirement.

How can I do this?

Alan

Posted 2012-11-30T06:38:03.513

Reputation: 1 251

ffmpeg may be deprecated, see here and here – nutty about natty – 2015-06-29T09:57:23.437

18@nuttyaboutnatty The "deprecated" messages applied only to the old, dead, fake "ffmpeg" from the Libav fork, not ffmpeg from FFmpeg which returned in 15.04. – llogan – 2015-06-29T18:28:43.660

Answers

182

The most basic example is this:

ffmpeg -i input.avi -s 720x480 -c:a copy output.mkv

Using the scale filter will provide more flexibility:

ffmpeg -i input.avi -filter:v scale=720:-1 -c:a copy output.mkv

The -1 will tell ffmpeg to automatically choose the correct height in relation to the provided width to preserve the aspect ratio. -1 can also be used for width if you provide a given height.


One downside of scale when using libx264 is that this encoder requires even values and scale may automatically choose an odd value resulting in an error: width or height not divisible by 2. You can tell scale to choose an even value for a given height (720 in this example):

scale="trunc(oh*a/2)*2:720"

...or a given width (1280 in this example):

scale="1280:trunc(ow/a/2)*2"

Note that your ffmpeg build could complain about not recognizing -c or -filter options. It also may not support scale. In that case you should use a newer ffmpeg, which you can download as a static build, or compile yourself.

jimhark

Posted 2012-11-30T06:38:03.513

Reputation: 1 936

This answer seems to be outdated, -filter:v doesn't work for me at all. – MightyPork – 2014-12-24T12:07:33.330

1@MightyPork probably your ffmpeg build is outdated - what problems happen?. Anyway, this really helped me (with ffmpeg version 2.4.10) to reduce the size of some massive videos to free up some space - thanks! – Wilf – 2015-06-24T21:32:39.893

ffmpeg may be deprecated, see here and here – nutty about natty – 2015-06-29T09:57:50.537

I have to use "-c copy", but in other side I want to resize screen. How can I achieve this? – Dr.jacky – 2015-12-14T12:48:44.217

1What does the -c:a copy flag do? I can't seem to find it in the documentation. – Brian – 2016-02-05T20:53:09.197

5'-c' is short for -codec, ':a' specifies audio stream(s), 'copy' specifies the copy codec, which copies the stream(s) (in this case audio) without reencoding. Basically the audio streams will pass through. This is common when you are only manipulating the video stream. – jimhark – 2016-02-05T23:27:28.860

I was 1-pixel too large after scaling so I added a 1-pixel crop as described in this answer to a similar question: https://unix.stackexchange.com/questions/190431/convert-a-video-to-a-fixed-screen-size-by-cropping-and-resizing

– Nick – 2018-01-22T00:22:09.603

4You can tell scale to provide even value by using scale=720:-2 – Barafu Albino – 2018-05-30T17:38:13.247

Not working with syntax 720x480 but works with 720:480 as in answer below but it also hangs at a place – Rushi M Thakker – 2019-08-29T05:19:43.687

1I tried ffmpeg -i output.mkv -filter:v scale=720:-1 -acodec copy -threads 12 output_shrink.mkv (in ffmpeg version 0.8.6-6:0.8.6-0ubuntu0.12.10.1) but got the error Unrecognized option 'filter:v' – doug65536 – 2013-04-26T15:41:37.433

6After digging through the man page for ffmpeg several times I found that instead of -filter:v, the option appears to have been changed to -vf. – doug65536 – 2013-04-26T15:51:55.953

2@doug65536 -filter:v and -vf are both fine. The Ubuntu version you were using is broken and outdated—it's not really FFmpeg's ffmpeg, but the binary supplied by Libav (the FFmpeg fork) under the same name. – slhck – 2013-07-26T06:41:58.067

21

I use following commands to do rescaling for videos and images. For fixed width and height -

ffmpeg -i input.avi -vf scale="720:480" output.avi

and if you want to retain aspect ratio just give height as -1 and it will automatically resize based on the width -

ffmpeg -i input.avi -vf scale="720:-1" output.avi

If you want to scale based on input size Eg. lets say reduce the width/height yo half you can do-

ffmpeg -i input.avi -vf scale="iw/1:ih/2" output.avi

NOTE :

iw : input width
ih : input height

Static build can be downloaded from - https://johnvansickle.com/ffmpeg/

Documentation : https://ffmpeg.org/ffmpeg.html#filter_005foption

Aniket Thakur

Posted 2012-11-30T06:38:03.513

Reputation: 597

Not working. Stuck at handler_name : Sound Handle – Rushi M Thakker – 2019-08-29T05:17:33.427

I got a terrible video quality with this command. Much better if I create output.mp4, not avi. So extension matters. – sekrett – 2019-10-04T20:12:28.160