Convert video files with ffmpeg

Stephen Lee
2 min readJun 3, 2023

I have a projector which can play videos, but it might be too old, it can only play videos with H264 encoding, but sometimes, the video has H265 encoding, so I need to change the encoding to adapt on my projector.

This is the command that I used to convert the video file with H264 encoding.

ffmpeg -i <input_video_file_name> \
-c:v libx264 \
-crf 17 \
-vf "scale=1280:720" \
-c:a copy \
<output_video_file_name>
  • Options -c:v libx264 is convert the video file with H264 encoding.
  • Option -crf 17 crf is the Constant Rate Factor.

The range of the CRF scale is 0–51, where 0 is lossless (for 8 bit only, for 10 bit use -qp 0), 23 is the default, and 51 is worst quality possible. A lower value generally leads to higher quality, and a subjectively sane range is 17–28. Consider 17 or 18 to be visually lossless or nearly so; it should look the same or nearly the same as the input but it isn’t technically lossless.

  • Option -vf "scale=1280:720" this is used to convert video to 720P, sometime when the video has 1080P, and convert to H264 it is too slow, and on my projector, 720P is also OK, so I add this option to generate video in 720P.
  • Option -c:a copy This option means copy the audio from original video to destination video file.

--

--

Stephen Lee

I am a software engineer, I like to use the computer to solve problems. website: https://blog.y9i.cc/