How to get ffmpeg configuration similar to that of youtube for 480p and 1080p video? I have got a function but the output quality is too low

1k views Asked by At

Hey guys I am learning to develop a website that converts videos to youtube quality (or close enough) 480p and 1080p, I am not much familiar with ffmpeg and struggling with its documentation.

I have these functions,

video_480p      = subprocess.call([FFMPEG_PATH, '-i', input_file, '-codec:v', 'libx264', '-crf', '20', '-preset', 'medium',
                    '-b:v', '1000k', '-maxrate', '1000k', '-bufsize', '2000k','-vf', 'scale=-2:480', '-codec:a', 'aac', '-b:a',
                     '128k', '-strict', '-2', file_480p])

similarly I have another function,

new_video       = subprocess.call([FFMPEG_PATH, '-i', input_file, '-codec:v', 'libx264', '-crf', '20', '-preset', 'medium',
                    '-b:v', '1000k', '-maxrate', '1000k', '-bufsize', '2000k','-vf', 'scale=-2:1080', '-codec:a', 'aac', '-b:a',
                     '128k', '-strict', '-2', output_file])

Both these functions, transcode the video, but returns low quality videos, Can anyone provide me with the right settings for 480p and 1080p which is similar or close to youtube quality?

Thanks

1

There are 1 answers

3
ojdo On BEST ANSWER

My guess is that your -maxrate argument is severly limiting the quality. Try dropping everything except -crf 20 and the scaling option. For higher quality, reduce its value (technical range: 0 = lossless, but huge filesize; 51 = worst quality, smallest size). Practical values are 23 (the default), and 17-18 for "visually lossless". The second dial is -preset, which you could set to slow or slower if you have time to spend for better quality.

For more details, see FFMPEG's own H.264 Encoding Guide.