What is -crf used for in ffmpeg

19

6

When converting an array of jpegs to a video file (ogg format) I have been using the -crf option. What are the valid ranges for -crf? Currently I am using 23.

I cannot find the bookmark I read to know what this flag does and I have spent some time Googling around.

These are the arguments I am using at the moment:

-f image2 -r 10 -i " + _sourcePath + @"\img%05d.jpg -crf 18  -y -r 10 " + _destPath + "\\" + _filename + ".ogg"

Andrew Simpson

Posted 2013-11-18T17:53:56.043

Reputation: 437

1

I don't know any thing about this command, but it's very well documented here: http://www.ffmpeg.org/ffmpeg.html.

– Ben Plont – 2013-11-18T18:04:05.287

1Are you using libx264 (for H.264 video) or libvpx (for VP8 video)? Please show your ffmpeg command and the complete console output. – llogan – 2013-11-18T18:11:40.337

Hi, sorry for the delay. Had to walk the dog. I will amend my question. Thanks – Andrew Simpson – 2013-11-18T19:04:00.370

1So, the question is if you want to keep this question rather general to CRF, or if you have a specific issue you need help with. In the latter case we'd need to get the full commandline output (i.e. everything from "ffmpeg version…" to the last bit) and the actual command you're using, but it'd unfortunately render the existing answers useless. You might want to ask a new question if you're facing a concrete issue. – slhck – 2013-11-18T19:59:01.773

@slhck Hi, you are absolutely right. I do need to learn to be more specific and comprehensive in future. As it was your answer fitted my needs more than everyone else's but everyone else's were also informative. I will tread more carefully in the future :) Thank you for your time. Much appreciated. – Andrew Simpson – 2013-11-19T07:43:41.320

Answers

18

That refers to the Constant Rate Factor (crf).

As others have pointed out (Thanks all), the values will depend on which encoder you're using.

For x264 your valid range is 0-51:

The range of the quantizer scale is 0-51: where 0 is lossless, 23 is default, and 51 is worst possible. A lower value is a higher quality and a subjectively sane range is 18-28. Consider 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.

For vpx the range is 4-63 (as @sebastian-hoffner answered):

By default the CRF value can be from 4–63, and 10 is a good starting point. Lower values mean better quality.

In both cases, lower is better. In my experience, I see x264 much more often.

Slhck's shameless plug (an SU mod) link looks like it has some good info.

nerdwaller

Posted 2013-11-18T17:53:56.043

Reputation: 13 366

Range for VPX is from 0-63 not 4-63, recommended rate is 15-30 – Suhayb – 2019-10-13T22:00:23.423

3

The crf flag ensures a variable bitrate for constant quality, if I understand the page linked below correctly. The default range is from 4 to 63, but it can be tweaked further.

Have a look at https://trac.ffmpeg.org/wiki/vpxEncodingGuide for more information.

Sebastian Höffner

Posted 2013-11-18T17:53:56.043

Reputation: 131

I'm a little confused by this, we both link to the same site and each page says something slightly different (ranges, that is). In any case, both look legitimate to me, so I'm a little boggled by this. – nerdwaller – 2013-11-18T18:02:18.410

hi, thanks for that. I am looking to improve the quality of the video stream so a low crf will do it? – Andrew Simpson – 2013-11-18T18:04:05.993