Changes between Version 53 and Version 54 of Scaling
- Timestamp:
- Jun 9, 2024, 6:00:20 AM (2 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Scaling
v53 v54 50 50 == Simple Rescaling == 51 51 52 If you need to simply resize your video to a specific size (e.g 320 ×240), you can use the scale filter in its most basic form:52 If you need to simply resize your video to a specific size (e.g 320x240), you can use the scale filter in its most basic form: 53 53 {{{ 54 54 ffmpeg -i input.avi -vf scale=320:240 output.avi … … 72 72 will set the width of the output image to 320 pixels and will calculate the height of the output image according to the aspect ratio of the input image. 73 73 74 The resulting image will have a dimension of 320 ×207 pixels.\\74 The resulting image will have a dimension of 320x207 pixels.\\ 75 75 [[Image( "input.jpg", 320px )]] 76 76 … … 79 79 ffmpeg -i input.jpg -vf scale=320:-2 output_320.png 80 80 }}} 81 The output will now be 320 ×206 pixels.81 The output will now be 320x206 pixels. 82 82 83 83 … … 121 121 122 122 123 == Fitting into a Rectangle / Statically-sized Player == 124 125 Sometimes you need to scale the input image so that it fits into a specified rectangle, e.g. when consolidating material from different sources. 126 127 You can achieve this with the `force_original_aspect_ratio` option. It has two possible values: 128 * `decrease`: The output video dimensions will automatically be decreased if needed. 129 * `increase`: The output video dimensions will automatically be increased if needed.130 131 This allows you to force the image to fit into a 320 ×240 box, downscaling it with the correct aspect ratio:132 {{{ 133 ffmpeg -i input.jpg -vf scale=w=320:h=240:force_original_aspect_ratio=decrease output_320.png134 }}} 135 136 This produces our 320 ×207 image that we had seen [#KeepingtheAspectRatio before].\\123 == Fitting into a Rectangle / Statically-sized Player == #fit 124 125 Sometimes you need to scale the input image so that it fits into a specified rectangle, e.g. when consolidating material from different sources.\\ 126 ͏ Achievable with "force_original_aspect_ratio". Accepts 3 possible values:\\ 127 ͏ |0| "disable" (default)\\ 128 ͏ |1| "decrease": auto-decrease output dimensions on need.\\ 129 ͏ |2| "increase": auto-increase output dimensions on need. 130 131 This allows you to force the image to fit into a 320x240 box, downscaling it with the correct aspect ratio: 132 {{{#!shell 133 ffmpeg -i "input.jpg" -vf "scale=w=320:h=240:force_original_aspect_ratio=decrease" "output_320.png" 134 }}} 135 136 This produces our 320x207 image that we had seen [#KeepingtheAspectRatio before].\\ 137 137 [[Image( "input.jpg", 320px )]] 138 138 139 You may have additional constraints such as adding black bars (pillar- and letterboxing) to fill up the remaining space when scaling to a certain rectangle. You can additionally add a black border using the `pad` filter: 140 {{{ 141 ffmpeg -i input.jpg -vf "scale=320:240:force_original_aspect_ratio=decrease,pad=320:240:(ow-iw)/2:(oh-ih)/2" output_320_padding.png 142 }}} 139 ͏ You may have additional constraints such as adding black bars (pillar- and letterboxing) to fill up the remaining space when scaling to a certain rectangle.\\ 140 ͏ You can additionally add a black border using the [https://ffmpeg.org/ffmpeg-filters.html#pad ͏"pad"] filter:\\ 141 ͏ `ffmpeg -i "input.jpg" -vf "scale=320:240:force_original_aspect_ratio=1,pad=320:240:(( (ow - iw)/2 )):(( (oh - ih)/2 ))" "output_320_padding.png"` 143 142 {{{#!div style="display: inline-block; margin-left: 0; overflow: hidden; width: 320px; height: 240px; padding: 0; background-color: #000" 144 143 [[Image( "input.jpg", width="100%" )]]
