How do I resize a video to make it smaller with FFmpeg? (e.g. from 1024x576 to 720x480.)
2 Answers
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.
-
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 Apr 26 '13 at 15:41
-
11After 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 Apr 26 '13 at 15:51
-
6@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 Jul 26 '13 at 06:41
-
This answer seems to be outdated, `-filter:v` doesn't work for me at all. – MightyPork Dec 24 '14 at 12:07
-
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 Jun 24 '15 at 21:32
-
`ffmpeg` may be deprecated, see [here](http://askubuntu.com/a/162014/16023) and [here](https://answers.launchpad.net/ubuntu/+question/223855) – nutty about natty Jun 29 '15 at 09:57
-
I have to use "-c copy", but in other side I want to resize screen. How can I achieve this? – Dr.jacky Dec 14 '15 at 12:48
-
1What does the `-c:a copy` flag do? I can't seem to find it in the documentation. – Brian Feb 05 '16 at 20:53
-
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 Feb 05 '16 at 23:27
-
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 Jan 22 '18 at 00:22
-
18You can tell scale to provide even value by using `scale=720:-2` – Barafu Albino May 30 '18 at 17:38
-
Not working with syntax 720x480 but works with 720:480 as in answer below but it also hangs at a place – Rushi M Thakker Aug 29 '19 at 05:19
-
1if by "smaller size" one also means file size, then using H.265 will typically give better (smaller) results than H.264, e.g., `ffmpeg ... -c:v libx265 -vtag hvc1 ... ` and optionally setting `-crf` and/or a `-preset` value (see https://trac.ffmpeg.org/wiki/Encode/H.265 ) – michael Mar 01 '21 at 07:31
-
The syntax of `scale` with a negative size (which asks a divisibility and keep ratio approximately) may seem practical, but i prefer the scale options `force_original_aspect_ratio=decrease` and `force_divisible_by=2` along with one or two dimensions, because it is much more obvious than relying on the negative arbitrary convention. I have no idea of which option belongs to which ffmpeg version so i do not know how relevant it is. – Link-akro Sep 16 '21 at 23:23
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 e.g. lets say reduce the width/height to half you can do -
ffmpeg -i input.avi -vf scale="iw/2: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
- 1,185
- 10
- 9
-
-
I got a terrible video quality with this command. Much better if I create output.mp4, not avi. So extension matters. – sekrett Oct 04 '19 at 20:12
-