Published on

Changing Resolution of Video Files with FFmpeg

Authors
  • avatar
    Name
    Hieu Cao
    Twitter

Introduction

FFmpeg is a powerful multimedia tool that allows you to manipulate video and audio files with ease. Changing the resolution of video files is one of its most commonly used features. In this blog, we will explore how to resize video files using FFmpeg.


Why Change Video Resolution?

Changing the resolution of video files can be beneficial in various scenarios:

  1. Optimize for Web or Mobile: Reduce file size for faster loading and better performance on low-bandwidth devices.
  2. Standardize Resolution: Ensure all videos in a collection have consistent dimensions.
  3. Create Previews or Thumbnails: Generate lower-resolution versions for quick previews.

How to Change Video Resolution Using FFmpeg

Step 1: Basic Command to Resize Video

To change the resolution of a video file, use the following command:

ffmpeg -i input-video.mp4 -vf scale=1280:720 output-video.mp4
  • -i input-video.mp4 specifies the input video file.
  • -vf scale=1280:720 sets the resolution to 1280x720.
  • output-video.mp4 is the output file.

Step 2: Preserve Aspect Ratio

If you want to maintain the aspect ratio while resizing:

ffmpeg -i input-video.mp4 -vf "scale=1280:-1" output-video.mp4
  • -1 lets FFmpeg automatically calculate the height to preserve the aspect ratio.

Step 3: Resize to a Percentage of Original Size

To scale the video to a percentage of its original size:

ffmpeg -i input-video.mp4 -vf "scale=iw*0.5:ih*0.5" output-video.mp4
  • iw and ih represent the input width and height, respectively.
  • iw*0.5 and ih*0.5 scale the video to 50% of its original size.

Step 4: Common Resolutions and Their Commands

Here are some commonly used resolutions with FFmpeg commands:

  • 1080p (Full HD):

    ffmpeg -i input-video.mp4 -vf scale=1920:1080 output-video.mp4
    
  • 720p (HD):

    ffmpeg -i input-video.mp4 -vf scale=1280:720 output-video.mp4
    
  • 480p (SD):

    ffmpeg -i input-video.mp4 -vf scale=854:480 output-video.mp4
    
  • 360p:

    ffmpeg -i input-video.mp4 -vf scale=640:360 output-video.mp4
    

Conclusion

Changing the resolution of video files with FFmpeg is straightforward and versatile. Whether you’re optimizing for different devices or creating standardized video libraries, FFmpeg provides the tools you need. Try these commands and elevate your video processing workflow!