H.264 multi-pass encoding with FFmpeg

10,913

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

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

Share:
10,913

Related videos on Youtube

Happy Face
Author by

Happy Face

Watched too much Anime and you still want more but you can't find any good one anymore? Well well well, perhaps you can enjoy my profile picture then XD Top 25 Favorite Anime Series of All Time (Including its prequel(s) and sequel(s) & Update every month ;) ) Dragon Ball Z Hunter X Hunter: Reboot (2011) Naruto Shippuden Sword Art Online One-Punch Man Death Note Yuru Yuri Akama ga Kill! Bakuman Attack on Titan Kiseijuu: Sei no Kakuritsu (Parasyte: The Maxim) To Love-Ru Trouble Minami-Ke K-ON! Zero no Tsukaima (The Familiar of Zero) Ajin Detectice Conan (Case Closed) Shokugeki no Souma Prison School Sekirei Tokyo Ghoul Seitokai Yakuindomo Himouto! Umaru-chan Danshi Koukousei no Nichijou (Daily Lives of High School Boys) Kono Subarashii Sekai ni Shukufuku o! Top 10 Favorite Anime Movie of All Time Detective Conan: The Phantom of Baker Street Gyo: Tokyo Fish Attack Naruto Shippuden The Movie: Inheritors of the Will of Fire Detective Conan: Magician of the Silver Sky K-On! Movie Dragon Ball Z The Movie: Resurrection 'F' Dragon Ball Z The Movie: Battle of Gods The Girl Who Leapt Through Time Naruto Shippuden the Movie: The Lost Tower Gintama The Movie: The Final Chapter: Be Forever Yorozuya I usually watch Anime on Blu-ray or DVD, so I don't watch Anime that aired recently (up to 6 months). I'll seat and wait until the Blu-ray come out instead :D

Updated on September 18, 2022

Comments

  • Happy Face
    Happy Face over 1 year

    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?

    • Elisa Cha Cha
      Elisa Cha Cha over 8 years
      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.
    • Happy Face
      Happy Face over 8 years
      @LordNeckbeard If I specify -refs 8, will the preset mess it up? And do you mean crf is better than 2-pass?
    • Elisa Cha Cha
      Elisa Cha Cha over 8 years
      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.
    • Happy Face
      Happy Face over 8 years
      @LordNeckbeard Basically I want to encode a video as lossless as possible without having gigantic file size like using -qp 0 or -crf 0.
    • Elisa Cha Cha
      Elisa Cha Cha over 8 years
      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.
  • slhck
    slhck over 8 years
    Instead of creating a temporary file, Windows users can use NUL. See @LordNeckbeard's answer.
  • Gyan
    Gyan over 8 years
    I know, but I missed the file path cue and since there was no express OS indication, I went for the universally safe method.