title: ffmpeg CLI set -r 30 if input => 30 fps, else -r to take input fps if < 30 fps
body: <p>I posted my <a href="https://stackoverflow.com/questions/59261211/limit-output-framerate-to-maximum-30">original question here</a>. Tried <a href="https://stackoverflow.com/questions/43334291/ffmpeg-reduce-fps-if-over-threshold-but-do-not-increase-if-under-threshold">suggested solution</a>. But it does not solve my question.</p>
  
  <p>Here's what I did. Download <a href="https://www.youtube.com/watch?v=t86sKsR4pnk" rel="nofollow noreferrer">this video</a> from Youtube as a test. Using ffprobe gives: </p>
  
  <pre><code>Stream #0:0: Video: h264 (High), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 59.94 fps, 59.94 tbr, 1k tbn, 119.88 tbc (default)
  </code></pre>
  
  <p>The ffmpeg command I used:</p>
  
  <pre><code>ffmpeg -i Iron_Man_1080p_60fps.mp4 -vf "select='eq(n,0)+if(gt(t-prev_selected_t,1/30.01),1,0)'" -vsync 0 -c:v libx265 -crf 28 -c:a aac -b:a 64k Iron_Man_1080p_60fps_CONVERTED.mp4
  </code></pre>
  
  <p>ffprobe my output file <code>Iron_Man_1080p_60fps_CONVERTED.mp4</code>:</p>
  
  <pre><code>Stream #0:0(und): Video: hevc (Main) (hev1 / 0x31766568), yuv420p(tv, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 454 kb/s, 20.49 fps, 59.94 tbr, 19001 tbn, 59.94 tbc (default)
  </code></pre>
  
  <p>As you can see, the fps dropped from 59.94 fps to 20.49 fps.</p>
  
  <p>I'm not sure why the suggested solution does not work. </p>
  
  <pre><code>ffmpeg -i 120.mp4 -vf "select='eq(n,0)+if(gt(t-prev_selected_t,1/30.01),1,0)'" -vsync 0 out.mp4
  </code></pre>
  
  <p>Perhaps -vf does not set a fixed framerate?</p>
  
  <p>Could someone provide an alternative solution using the -r flag please?</p>
  
  <p>Here's re-stating question:</p>
  
  <ul>
  <li>Set -r 30 if input fps => 30 fps</li>
  <li>Set -r input_fps if input fps &lt; 30 fps</li>
  </ul>
  
  <p>Thank you!</p>