乐闻世界logo
搜索文章和话题

How to use ffmpeg to resize images

1个答案

1

FFmpeg is a highly versatile tool capable of processing both video and audio, as well as images. Resizing images is one of its common applications.

When using FFmpeg to resize images, the primary parameter employed is -vf, which stands for Video Filter. Specifically, the scale filter is used to adjust image dimensions.

Here is a concrete example. Assume we have an image named input.jpg and wish to resize it to a width of 800 pixels and a height of 600 pixels:

bash
ffmpeg -i input.jpg -vf "scale=800:600" output.jpg

This command reads input.jpg, applies the resizing filter, and saves the result as output.jpg.

Additionally, more advanced options can be utilized, such as maintaining the aspect ratio of the image. For instance, if you want to change the image width to 800 pixels while preserving the original aspect ratio, use the following command:

bash
ffmpeg -i input.jpg -vf "scale=800:-1" output.jpg

Here, -1 indicates that FFmpeg automatically calculates the height to maintain the original aspect ratio. This is particularly useful when handling images of various sizes, as it prevents distortion or unwanted stretching.

In summary, FFmpeg offers highly flexible and powerful capabilities for resizing both images and videos.

2024年8月9日 01:54 回复

你的答案