Answers.Body: <p>This is actually pretty trivial:</p>
  <pre><code>ffmpeg -i test.mp4 -r 1 -an -c:v mjpeg 'test%03d.jpeg'
  </code></pre>
  <p>This will extract 1 frame per second. Now we want to adjust the numbers to be frame numbers rather than just a sequence, we know that they all have leading zeros, and are 3 digits long (see <code>%03d</code>). Therefore we can do:</p>
  <pre><code>for f in test*.jpeg; do num=${f:4:3}; let newnum=$((10#$num))*60; newname=&quot;${f/$num/$newnum}&quot;; mv $f $newname;  done
  </code></pre>
  <p>This assumes that the original frame rate was 60, we just multiply every number by that value. If your case has a different original frame rate, change that.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-11-04T09:45:18.873Z
Answers.LastActivityDate: 2024-11-04T09:45:18.873Z
Answers.UserDisplayName: v010dya
Body: <p>Basically I want to extract all frames from the video where the images will be resized to be 720p. All of this I know how to do. But for testing I want to extract every Nth frame. So every 30th image from a 30FPS video or every 10th image, etc. How can I do that?</p>
  <p>Also the extracted image filenames should correspond to the frame numbers so not sure if the first frame is 0 or 1?</p>
  
Tags: <ffmpeg>
Title: How to extract frames from a video using ffmpeg?
UserDisplayName: Leon
ThreadText: # How to extract frames from a video using ffmpeg?
  
  (Asked by: username_0 on 2024-06-01)
  
  Basically I want to extract all frames from the video where the images will be resized to be 720p. All of this I know how to do. But for testing I want to extract every Nth frame. So every 30th image from a 30FPS video or every 10th image, etc. How can I do that?
  
  Also the extracted image filenames should correspond to the frame numbers so not sure if the first frame is 0 or 1?
  
  **Tags:** ffmpeg
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2024-11-04. Score: 0
  
  This is actually pretty trivial:
  
  ```
  ffmpeg -i test.mp4 -r 1 -an -c:v mjpeg 'test%03d.jpeg'
  
  ```
  
  This will extract 1 frame per second. Now we want to adjust the numbers to be frame numbers rather than just a sequence, we know that they all have leading zeros, and are 3 digits long (see `%03d`). Therefore we can do:
  
  ```
  for f in test*.jpeg; do num=${f:4:3}; let newnum=$((10#$num))*60; newname="${f/$num/$newnum}"; mv $f $newname;  done
  
  ```
  
  This assumes that the original frame rate was 60, we just multiply every number by that value. If your case has a different original frame rate, change that.
  
  
  ---
  
  