title: FFMPEG : Add a fixed size image on a video, regardless of the video width & height (resolution)
body: <p>This is my code that adds an image to videos, running via PHP:</p>
  
  <pre><code>exec('ffmpeg -i input.mp4 -i logo.png -filter_complex 
  "[0:v][1:v] overlay=10:10"  -pix_fmt yuv420p -c:a copy output.mp4');
  </code></pre>
  
  <p>It works well but the problem is, the image is scaled down or up, up on the video resolution. For example in the following images the logo width is <code>50px</code> but videos resolution are different:</p>
  
  <p><a href="https://i.stack.imgur.com/LrNwI.png" rel="noreferrer"><img src="https://i.stack.imgur.com/LrNwI.png" alt="enter image description here"></a></p>
  
  <p>and this one</p>
  
  <p><a href="https://i.stack.imgur.com/U4Ksl.png" rel="noreferrer"><img src="https://i.stack.imgur.com/U4Ksl.png" alt="enter image description here"></a></p>
  
  <p><b>How can I prevent the image from scaling down/up ?</b></p>
  
  <hr>
  
  <h1>Update</h1>
  
  <p>Thanks to <a href="https://stackoverflow.com/users/5726027/mulvya">Mulvya</a>, he proposed these codes</p>
  
  <pre><code>ffmpeg -i input.mp4 -i logo.png -filter_complex 
  "[1:v][0:v]scale2ref=(W/H)*ih/8:ih/8[wm][base];[base][wm]overlay=10:10"
  -pix_fmt yuv420p -c:a copy output.mp4
  </code></pre>
  
  <p>and</p>
  
  <pre><code>ffmpeg -i input.mp4 -i logo.png -filter_complex 
  "[1:v][0:v]scale2ref=(W/H)*ih/8:ih/8[wm][base];[wm]setsar=1[wmsar];
  [base][wmsar]overlay=10:10"
  -pix_fmt yuv420p -c:a copy output.mp4
  </code></pre>
  
  <p>that works very well, but it doesn't keep the logo aspect ratio.
  I tried this code on two videos with different resolution and this is the result</p>
  
  <p><a href="https://i.stack.imgur.com/ZmAZU.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/ZmAZU.jpg" alt="enter image description here"></a></p>
  
  <p>and this one</p>
  
  <p><a href="https://i.stack.imgur.com/SFq8Y.png" rel="noreferrer"><img src="https://i.stack.imgur.com/SFq8Y.png" alt="enter image description here"></a></p>
  
  <p>Is it possible to improve this solution?</p>