Answers.Body: <p>In your command,</p>
  <pre><code>-filter:v &quot;select=not(mod(n\,16))&quot;
  </code></pre>
  <p>does select only each 16th frame, as you have discovered. However, your output format is MOV, which is configured as constant frame rate. So, ffmpeg will duplicate frames if the timestamp gaps between frames from the filter output are greater than <code>1/fps</code> where fps is the nominal frame rate of the stream, and drop frames if they are closer.</p>
  <p>Add <code>-vsync 0</code> to tell ffmpeg to not duplicate or drop frames.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-29T16:25:35.323Z
Answers.Text: Thank you for your answer. That does seem to work, but now I have the problem of fixing the timestamps so that the frames are displayed one after the other at the original framerate. I would have thought the -r option would do this, but the modified video is the same length timewise, even though it has fewer frames. Is there a fix for this? Thanks.
Answers.UserDisplayName: dragoncat16
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-29T17:28:12.873Z
Answers.Text: I think I need to use setpts=STARTPTS+N/(FR*TB) after the select and then it seems I don't even need the -vsync 0 option. The odd thing is it seems to have trouble with the frame rate so I just put the number instead.
Answers.UserDisplayName: dragoncat16
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-29T12:06:13.450Z
Answers.LastActivityDate: 2020-11-29T12:06:13.450Z
Answers.UserDisplayName: Gyan
Body: <p>I am trying to use the select filter to choose frames to be included in the output file, but the resulting output file actually has more frames than the input file, which is completely baffling.</p>
  <p>Following the example in the documentation to keep every 16th frame, I am using the following command:</p>
  <pre><code>ffmpeg -i input.MOV -filter:v &quot;select=not(mod(n\,16))&quot; output.MOV
  </code></pre>
  <p>output.MOV has more frames than input.MOV and nothing has been removed.</p>
  <p>Interestingly, when I use the command:</p>
  <pre><code>ffmpeg -i input.MOV -filter:v &quot;select=not(mod(n\,16))&quot;,showinfo output.MOV
  </code></pre>
  <p>it lists the frames that should be in the output (i.e. the ones that should be selected by the expression), but the actual output file contains more frames than that and seems to completely ignore the select filter (it seems to be the same no matter what select command I use, unless I use select=0).</p>
  <p>Am I doing something incorrectly? I basically just want an example command that works the way I expect it to, so I can better learn how ffmpeg works.</p>
  <p>Thanks.</p>
  <p>Edit: select is not the only filter that ffmpeg seems to ignore when producing the output file, but if this problem is solved, the fix will probably work for other filters as well.</p>
  
Tags: <ffmpeg>
Title: Using select in ffmpeg to choose frames
UserDisplayName: dragoncat16
ThreadText: # Using select in ffmpeg to choose frames
  
  (Asked by: username_0 on 2020-11-29)
  
  I am trying to use the select filter to choose frames to be included in the output file, but the resulting output file actually has more frames than the input file, which is completely baffling.
  
  Following the example in the documentation to keep every 16th frame, I am using the following command:
  
  ```
  ffmpeg -i input.MOV -filter:v "select=not(mod(n\,16))" output.MOV
  
  ```
  
  output.MOV has more frames than input.MOV and nothing has been removed.
  
  Interestingly, when I use the command:
  
  ```
  ffmpeg -i input.MOV -filter:v "select=not(mod(n\,16))",showinfo output.MOV
  
  ```
  
  it lists the frames that should be in the output (i.e. the ones that should be selected by the expression), but the actual output file contains more frames than that and seems to completely ignore the select filter (it seems to be the same no matter what select command I use, unless I use select=0).
  
  Am I doing something incorrectly? I basically just want an example command that works the way I expect it to, so I can better learn how ffmpeg works.
  
  Thanks.
  
  Edit: select is not the only filter that ffmpeg seems to ignore when producing the output file, but if this problem is solved, the fix will probably work for other filters as well.
  
  **Tags:** ffmpeg
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-11-29. Score: 2 | Accepted answer
  
  In your command,
  
  ```
  -filter:v "select=not(mod(n\,16))"
  
  ```
  
  does select only each 16th frame, as you have discovered. However, your output format is MOV, which is configured as constant frame rate. So, ffmpeg will duplicate frames if the timestamp gaps between frames from the filter output are greater than `1/fps` where fps is the nominal frame rate of the stream, and drop frames if they are closer.
  
  Add `-vsync 0` to tell ffmpeg to not duplicate or drop frames.
  
  > **Comments:**
  > **username_0**: Thank you for your answer. That does seem to work, but now I have the problem of fixing the timestamps so that the frames are displayed one after the other at the original framerate. I would have thought the -r option would do this, but the modified video is the same length timewise, even though it has fewer frames. Is there a fix for this? Thanks.  
  > **username_0**: I think I need to use setpts=STARTPTS+N/(FR*TB) after the select and then it seems I don't even need the -vsync 0 option. The odd thing is it seems to have trouble with the frame rate so I just put the number instead.  
  
  ---
  
  