title: Why does ffmpeg.exe not always terminate?
body: <p>I have a script in php that shells out to ffmpeg using exec() - it creates an mp4 out of an image and an mp3.</p>
  
  <p>This is the command I am executing:</p>
  
  <pre><code>"C:\\Program Files\\ffmpeg\\bin\\ffmpeg.exe" -loop 1 -r 0.1 -i image.jpg -i mp3.mp3 -c:v libx264 -preset ultrafast -crf 18 -tune stillimage -c:a copy -filter:v "[in] scale=-1:720, pad=1280:720:640-iw/2 [out]" -shortest out.mp4 -report
  </code></pre>
  
  <p>For the vast majority of the time, it works fine, takes about 5 seconds and then ends. However, every now and again the ffmpeg.exe process 'hangs' using 100% CPU and will stay there until manually 'killed'.</p>
  
  <p>ffmpeg.exe doesn't seem to be doing anything, the .mp4 it has created is incomplete and not getting any bigger, the log file is not changing and the modification times on all the files are not changing. I do not know why it is using 100% CPU.</p>
  
  <p><strong>I can take the same image and mp3 and run it through again and it will work fine.</strong></p>
  
  <p>I have the <code>-report</code> switch on and there doesn't appear to be anything in the log file which indicates why it has failed and not terminated. Here are the last lines of the (934 line) log file, it seems to have stopped after frame 10 for some reason:</p>
  
  <pre><code>[libx264 @ 0000000001E37D10] frame=   6 QP=18.00 NAL=2 Slice:P Poc:12  I:0    P:0    SKIP:3600 size=11 bytes
  [libx264 @ 0000000001E37D10] frame=   7 QP=18.00 NAL=2 Slice:P Poc:14  I:0    P:0    SKIP:3600 size=11 bytes`
  [libx264 @ 0000000001E37D10] frame=   8 QP=18.00 NAL=2 Slice:P Poc:16  I:0    P:0    SKIP:3600 size=11 bytes
  [libx264 @ 0000000001E37D10] frame=   9 QP=18.00 NAL=2 Slice:P Poc:18  I:0    P:0    SKIP:3600 size=11 bytes
  [libx264 @ 0000000001E37D10] frame=  10 QP=18.00 NAL=2 Slice:P Poc:20  I:0    P:0    SKIP:3600 size=11 bytes`
  </code></pre>
  
  <p>I've tried inspecting a hung ffmpeg.exe using Process Explorer, but as it is a background process, I can't seem to be able to find anything meaningful, but maybe I am missing something here - is there a way to bring the background process to the foreground?</p>
  
  <p>Any ideas would be much appreciated :-)</p>