4

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

prehistoricbeast
  • 405
  • 6
  • 16

1 Answers1

4

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.

ojdo
  • 8,280
  • 5
  • 37
  • 60
  • 1
    Hello, thanks for the response. What would you suggest for the maxrate? Like I am concerned about the file size too.. its like a 30 min full hd video should be less than a GB. – prehistoricbeast Apr 14 '21 at 16:31
  • Also, I'm confused with this value `-b:v` as I don't understand, what it does. – prehistoricbeast Apr 14 '21 at 16:34
  • 3
    As written (indirectly) in the linked guide, it seems to be the *target* bitrate for your videostream. It makes sense to specify only if you need a specific data rate and know which value to pick. In general, it is safer to only specify a target *quality* (using `-crf`) and let the codec do the rest. – ojdo Apr 15 '21 at 07:36