title: two pass encoding in ffmpeg
body: <p>I will be encoding different videos uploaded by the user asynchronously in my server. I saw <a href="http://trac.ffmpeg.org/wiki/Encode/H.264#Two-PassExample" rel="noreferrer">this pos</a>t, and according to this, this is how to endcode two pass encoding:</p>
  
  <pre><code>ffmpeg -y -i input -c:v libx264 -preset medium -b:v 555k -pass 1 -c:a libfdk_aac -b:a 128k -f mp4 /dev/null &amp;&amp; \
  
  ffmpeg -i input -c:v libx264 -preset medium -b:v 555k -pass 2 -c:a libfdk_aac -b:a 128k output.mp4
  </code></pre>
  
  <p>I noticed the -pass 1 and -pass 2 flags. But I tried encoding a video by just giving it a -pass 2 flag without first encoding in -pass 1 flag. Although I had this warning, it executed anyway:</p>
  
  <blockquote>
    <p>2nd pass has more frames than 1st pass</p>
  </blockquote>
  
  <p>So, my concern is how will ffmpeg know which one is the first pass so that it can do its pass 2 encoding? And since many videos will be uploaded simultaneously I can't keep them all at the /dev/null won't it will replace one with another. So how can I manage it?</p>
  
  <p>Your help and guidance will be very much appreciated.</p>
  
  <p>Thank you.</p>
  
  <p><strong>Upadate</strong></p>
  
  <p>ffmpeg cmd:</p>
  
  <pre><code>ffmpeg -i input.mp4 -codec:v libx264 -tune zerolatency -profile:v main -preset medium -b:v 1500k -maxrate 1500k -bufsize 15000k -s hd720 -threads 0 -pass 1 -an -f mp4 /dev/null
  
  ffmpeg -i input.mp4 -codec:v libx264 -tune zerolatency -profile:v main -preset medium -b:v 1000k -maxrate 1000k -bufsize 10000k -s hd720 -threads 0 -pass 2 -codec:a libfdk_aac -movflags +faststart output.mp4
  </code></pre>