I would like to encode a video in H.264 with multi-pass. I tried :

ffmpeg -y -ss 00:00:12.0 -i "c:\vid\example.mkv" -vframes 420 -vcodec libx264 -preset veryslow -refs 8 -b:v 1200k -an -pass 1 -f h264 /dev/null

ffmpeg -y -ss 00:00:12.0 -i "c:\vid\example.mkv" -vframes 420 -vcodec libx264 -preset veryslow -refs 8 -b:v 1200k -acodec copy -pass 2 "c:\vid\encoded.mkv"

but it shows error messages :

/dev/null: No such file or directory

ratecontrol_init: can't open stats file

Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height

Did I do something wrong? I'm not sure how to use multi-pass with FFmpeg by the way, any ideas how to fix the error?

  • Are you sure you need to use two-passes? Unless you're targeting a specific output file size just use a single pass with -crf instead. See FFmpeg Wiki: H.264 Video Encoding Guide for more info on that. Why did you add -refs 8? The preset will handle refs. Lastly, you can change -f h264 to -f matroska since that's the container format your second command uses.
    – llogan
    Jan 29, 2016 at 17:21
  • @LordNeckbeard If I specify -refs 8, will the preset mess it up? And do you mean crf is better than 2-pass?
    – Happy Face
    Jan 29, 2016 at 17:30
  • Are you trying to output to a certain file size? You didn't explain why you're using 2-pass or why you're adding -refs. Adding -refs should override the refs set by the preset, but I'm unsure why you're setting that in the first place.
    – llogan
    Jan 30, 2016 at 1:39
  • @LordNeckbeard Basically I want to encode a video as lossless as possible without having gigantic file size like using -qp 0 or -crf 0.
    – Happy Face
    Jan 30, 2016 at 5:38
  • Then use the highest crf value that still provides an acceptable quality and the slowest preset you have patience for. However, one of the two answers here should be an appropriate solution to the specific error for the question you posted.
    – llogan
    Jan 30, 2016 at 7:55

2 Answers 2


Windows doesn't have /dev/null. Use NUL instead.

For more details, see the FFmpeg Wiki post on H.264 encoding.



ffmpeg -y -ss 00:00:12.0 -i "c:\vid\example.mkv" -vframes 420 -vcodec libx264 -preset veryslow -refs 8 -b:v 1200k -an -pass 1 -f matroska dummy

ffmpeg -y -ss 00:00:12.0 -i "c:\vid\example.mkv" -vframes 420 -vcodec libx264 -preset veryslow -refs 8 -b:v 1200k -acodec copy -pass 2 "c:\vid\encoded.mkv"

Delete the dummy file created in the first pass after 2nd pass is done.

  • 1
    Instead of creating a temporary file, Windows users can use NUL. See @LordNeckbeard's answer.
    – slhck
    Jan 30, 2016 at 18:05
  • I know, but I missed the file path cue and since there was no express OS indication, I went for the universally safe method.
    – Gyan
    Jan 30, 2016 at 19:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.