FFmpeg


Summary

There are times when you want to communicate with people who are in remote areas for reasons such as remote work via video. Of course, text and still images are also effective methods, but video is a revolutionary way to express yourself.

Installation

Installation method is below:

  • Download from FFmpeg Official Site
  • Using package manager

Using Package Manager

macOS Catalina and later

brew install ffmpeg

After the installation is complete, output the version information of ffmpeg and confirm that the path has been passed.

$ ffmpeg -version
ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers

Reduce file size

It is a nightmare to not be able to finish uploading the video file you have prepared. If the file size of the video is simply too large, you can try adjusting the amount of information per second, or bit rate, of the video. Here is an example of how to do this.

ffmpeg -i input.mp4 -r 24 -s 1280x720 -vb 2m output.mp4

The most frequently used command arguments are as follows:

ItemDescription
iSpecify the input file
rSpecify the frame rate
sSpecify the video resolution.
If you want to resize the image while maintaining the aspect ratio, use -vf scale=1280:-1 with -1 on the side you want to use as the reference.
vbSpecify the bit rate of the video. Unit is k or m or g.

When changing the resolution, make sure to keep the aspect ratio, otherwise the video will be stretched. For example, the “Screen Capture” feature of the iPad Pro 12.9″ (2nd generation) will save the video at 1920 x 1440 resolution. If you just want to safely reduce the file size, the following command should be sufficient.

ffmpeg -i input.mp4 -r 24 -vb 5m output.mp4

To video format pixel size

When you are recording a PC screen, it is not uncommon for the pixel size to differ from the video standard, for example, 2488×1414. And if you reduce the pixel size of the video, you will encounter a situation where it becomes an odd number and cannot be divided.

For example, if you want to reduce a 2488 x 1414 video to 720 x …, you can do the following

ffmpeg -i input.mov -r 24 -vf "scale=720:ceil(ow/a/2)*2" output.mp4

Reformat

To MP4

The best way to deal with the above is to select MP4 and H.264 codecs, which will allow you to play videos on Windows, Mac, iPhone, and Android. If you pass vcodec libx264 to ffmpeg, it will encode the video to H.264. The following is an example of how to do this.

ffmpeg -i input.mp4 -vcodec libx264 output.mp4

To MP4 from QuickTime

As an exception, when playing MP4 from mov files, QuickTime on macOS reads the YUV from the file and gives it to you beforehand. The following is an example of how to do this.

ffmpeg -i input.mov -pix_fmt yuv420p output.mp4

To GIF animation

In some cases, you may not be able to display the video inline on your website.
To deal with that situation, run the following command to convert it to a GIF file.

fmpeg -i input.mp4 -r 24 -s 1280x720 -vb 2m output.gif