Warm tip: This article is reproduced from serverfault.com, please click

ffmpeg commands to transcode any format video into different resolutions?

发布于 2020-11-28 14:53:20

How to trancode any format video into different resolutions like YouTube with the help of ffmepg. I need best commands to do that Reduce video size, change resolutions and video-audio bits too.

Qualitys are

  • 1080p
  • 720p
  • 480p
  • 360p
  • 240p And 144p

Output will be in mp4 h.264/AVC video formats.

Questioner
Priyanshu Roy
Viewed
0
llogan 2020-11-29 02:37:17

Use the scale filer:

ffmpeg -i input.mp4 -filter_complex
"[0]scale=-2:1080,format=yuv420p[1080];
 [0]scale=-2:720,format=yuv420p[720];
 [0]scale=-2:480,format=yuv420p[480];
 [0]scale=-2:360,format=yuv420p[360];
 [0]scale=-2:240,format=yuv420p[240];
 [0]scale=-2:144,format=yuv420p[144]"
-map "[1080]" -map 0:a -c:v libx264 -c:a aac -movflags +faststart 1080.mp4
-map "[720]" -map 0:a -c:v libx264 -c:a aac -movflags +faststart 720.mp4
-map "[480]" -map 0:a -c:v libx264 -c:a aac -movflags +faststart 480.mp4
-map "[360]" -map 0:a -c:v libx264 -c:a aac -movflags +faststart 360.mp4
-map "[240]" -map 0:a -c:v libx264 -c:a aac -movflags +faststart 240.mp4
-map "[144]" -map 0:a -c:v libx264 -c:a aac -movflags +faststart 144.mp4

A more efficient but more complicated method using the tee muxer so the audio is only encoded 1 time instead of 6 times:

ffmpeg -i input.mp4 -filter_complex
"[0]scale=-2:1080,format=yuv420p[1080];
 [0]scale=-2:720,format=yuv420p[720];
 [0]scale=-2:480,format=yuv420p[480];
 [0]scale=-2:360,format=yuv420p[360];
 [0]scale=-2:240,format=yuv420p[240];
 [0]scale=-2:144,format=yuv420p[144]"
-map "[1080]" -map "[720]" -map "[480]" -map "[360]" -map "[240]" -map "[144]" -map 0:a
-c:v libx264 -c:a aac -f tee
"[select=\'v:0,a\':movflags=+faststart]1080.mp4|[select=\'v:1,a\':movflags=+faststart]720.mp4|[select=\'v:2,a\':movflags=+faststart]480.mp4|[select=\'v:3,a\':movflags=+faststart]360.mp4|[select=\'v:4,a\':movflags=+faststart]240.mp4|[select=\'v:5,a\':movflags=+faststart]144.mp4"

I broke the commands into separate lines to help visualize the command. Make it 1 line before running the command.