Answers.Body: <p>Just drop the output label <code>&quot;[grab]&quot;</code> so you don't have to <code>-map</code> it.</p>
  <pre><code>$ ffmpeg-4.4-amd64-static/ffmpeg -y -i input.mp4 -filter_complex &quot;[v:0]crop=iw:ih&quot; -frames:v 1 -f image2 out.png
  </code></pre>
  <p>On newer versions of FFmpeg, you'll get a <strong>warning</strong> that tells you that you have to put a number pattern in your output filename. You can ignore this warning, since you're using the <code>-frames:v 1</code> option to write only a single frame to that file.</p>
  <p>However, if you drop the <code>-frame</code> parameter, you'll get an error, because FFmpeg tries to write to the same file again (as indicated by the frame counter at the end):</p>
  <pre><code>$ ffmpeg-6.0-amd64-static/ffmpeg -y -i input.mp4 -filter_complex &quot;[v:0]crop=iw:ih&quot; -frames:v 1 -update 1 -f image2 out3.png
  [...]
  [image2 @ 0x5f5b280] The specified filename 'out3.png' does not contain an image sequence pattern or a pattern is invalid.
  [image2 @ 0x5f5b280] Use a pattern such as %03d for an image sequence or use the -update option (with -frames:v 1 if needed) to write a single image.
  [image2 @ 0x5f5b280] Cannot write more than one file with the same name. Are you missing the -update option or a sequence pattern?
  av_interleaved_write_frame(): Invalid argument
  [out#0/image2 @ 0x5f5b140] Error muxing a packet
  frame=    2 fps=0.0 q=-0.0 Lsize=N/A time=00:00:00.40 bitrate=N/A speed= 1.1x
  video:2023kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
  Conversion failed!
  </code></pre>
  <p><strong>Despite the error, the first frame is still written to disk</strong>, and that's what you wanted anyways.</p>
  <p>To avoid these warnings and errors, pass the <code>-update 1</code> option which tells the <code>image2</code> muxer that it's okay to overwrite the same image file over and over again. Since you're writing a single file only with the <code>frames:v 1</code> option, the <code>-update 1</code> option is unnecessary, but doesn't hurt.</p>
  <p>Of course, if you're using number patterns in your filename, you won't encounter this overwrite issue at all, e.g.: <code>out_%03d.png</code>.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-08-18T09:34:48.247Z
Answers.LastActivityDate: 2023-08-21T12:29:21.433Z
Answers.LastEditDate: 2023-08-21T12:29:21.433Z
Answers.UserDisplayName: Gergely Lukacsy
Answers.Body: <p>As the 2nd warning says, use <code>-frames</code> along with <code>-update</code>.</p>
  <p><code>ffmpeg -y -i input.mp4 -filter_complex &quot;[0]crop=iw:ih[grab]&quot; -map [grab] -frames:v 1 -update true &quot;out.png&quot;</code></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-08-21T02:53:13.853Z
Answers.Text: Thanks for your help. I tried to upvote but am not reputationable enough.
Answers.UserDisplayName: Joey Perroni
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-08-18T04:29:07.537Z
Answers.LastActivityDate: 2023-08-18T04:29:07.537Z
Answers.UserDisplayName: Gyan
Body: <p>I feel like this should be so simple but I just can't find any way to do it. I simply want to grab the opening frame of a video file and output it as a PNG within a filter-complex command.</p>
  <p>I can do this using the following command in isolation although I get a warning:</p>
  <p><code>ffmpeg -y -i infile -frames:v 1 output.png</code></p>
  <blockquote>
  <p>[image2 @ 0000020bbf053640] The specified filename 'output.png' does not contain an image sequence pattern or a pattern is invalid.</p>
  </blockquote>
  <blockquote>
  <p>[image2 @ 0000020bbf053640] Use a pattern such as %03d for an image sequence or use the -update option (with -frames:v 1 if needed) to write a single image.</p>
  </blockquote>
  <p>How do I incorporate the same outcome in a filter-complex function?</p>
  <p>I have used the following crop command:</p>
  <p><code>ffmpeg -y -i input.mp4 -filter_complex &quot;[0]crop=iw:ih[grab]&quot; -map [grab] &quot;out.png&quot;</code></p>
  <p>and although I do get the required output, I get warning/error which I'd rather not get:</p>
  <blockquote>
  <p>[image2 @ 000002a9089c1280] The specified filename 'out.png' does not contain an image sequence pattern or a pattern is invalid.</p>
  </blockquote>
  <blockquote>
  <p>[image2 @ 000002a9089c1280] Use a pattern such as %03d for an image sequence or use the -update option (with -frames:v 1 if needed) to write a single image.</p>
  </blockquote>
  <blockquote>
  <p>[image2 @ 000002a9089c1280] Cannot write more than one file with the same name. Are you missing the -update option or a sequence pattern?
  av_interleaved_write_frame(): Invalid argument</p>
  </blockquote>
  <blockquote>
  <p>Error muxing a packet for output file #0</p>
  </blockquote>
  
Tags: <ffmpeg>
Title: Extracting a screenshot from a video using ffmpeg
UserDisplayName: Joey Perroni
ThreadText: # Extracting a screenshot from a video using ffmpeg
  
  (Asked by: username_0 on 2023-08-17)
  
  I feel like this should be so simple but I just can't find any way to do it. I simply want to grab the opening frame of a video file and output it as a PNG within a filter-complex command.
  
  I can do this using the following command in isolation although I get a warning:
  
  `ffmpeg -y -i infile -frames:v 1 output.png`
  
  > [image2 @ 0000020bbf053640] The specified filename 'output.png' does not contain an image sequence pattern or a pattern is invalid.
  
  > [image2 @ 0000020bbf053640] Use a pattern such as %03d for an image sequence or use the -update option (with -frames:v 1 if needed) to write a single image.
  
  How do I incorporate the same outcome in a filter-complex function?
  
  I have used the following crop command:
  
  `ffmpeg -y -i input.mp4 -filter_complex "[0]crop=iw:ih[grab]" -map [grab] "out.png"`
  
  and although I do get the required output, I get warning/error which I'd rather not get:
  
  > [image2 @ 000002a9089c1280] The specified filename 'out.png' does not contain an image sequence pattern or a pattern is invalid.
  
  > [image2 @ 000002a9089c1280] Use a pattern such as %03d for an image sequence or use the -update option (with -frames:v 1 if needed) to write a single image.
  
  > [image2 @ 000002a9089c1280] Cannot write more than one file with the same name. Are you missing the -update option or a sequence pattern?
  > av\_interleaved\_write\_frame(): Invalid argument
  
  > Error muxing a packet for output file #0
  
  **Tags:** ffmpeg
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2023-08-18. Score: 0 | Accepted answer
  
  Just drop the output label `"[grab]"` so you don't have to `-map` it.
  
  ```
  $ ffmpeg-4.4-amd64-static/ffmpeg -y -i input.mp4 -filter_complex "[v:0]crop=iw:ih" -frames:v 1 -f image2 out.png
  
  ```
  
  On newer versions of FFmpeg, you'll get a **warning** that tells you that you have to put a number pattern in your output filename. You can ignore this warning, since you're using the `-frames:v 1` option to write only a single frame to that file.
  
  However, if you drop the `-frame` parameter, you'll get an error, because FFmpeg tries to write to the same file again (as indicated by the frame counter at the end):
  
  ```
  $ ffmpeg-6.0-amd64-static/ffmpeg -y -i input.mp4 -filter_complex "[v:0]crop=iw:ih" -frames:v 1 -update 1 -f image2 out3.png
  [...]
  [image2 @ 0x5f5b280] The specified filename 'out3.png' does not contain an image sequence pattern or a pattern is invalid.
  [image2 @ 0x5f5b280] Use a pattern such as %03d for an image sequence or use the -update option (with -frames:v 1 if needed) to write a single image.
  [image2 @ 0x5f5b280] Cannot write more than one file with the same name. Are you missing the -update option or a sequence pattern?
  av_interleaved_write_frame(): Invalid argument
  [out#0/image2 @ 0x5f5b140] Error muxing a packet
  frame=    2 fps=0.0 q=-0.0 Lsize=N/A time=00:00:00.40 bitrate=N/A speed= 1.1x
  video:2023kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
  Conversion failed!
  
  ```
  
  **Despite the error, the first frame is still written to disk**, and that's what you wanted anyways.
  
  To avoid these warnings and errors, pass the `-update 1` option which tells the `image2` muxer that it's okay to overwrite the same image file over and over again. Since you're writing a single file only with the `frames:v 1` option, the `-update 1` option is unnecessary, but doesn't hurt.
  
  Of course, if you're using number patterns in your filename, you won't encounter this overwrite issue at all, e.g.: `out_%03d.png`.
  
  
  ---
  
  ### Answer by username_2 on 2023-08-18. Score: 1
  
  As the 2nd warning says, use `-frames` along with `-update`.
  
  `ffmpeg -y -i input.mp4 -filter_complex "[0]crop=iw:ih[grab]" -map [grab] -frames:v 1 -update true "out.png"`
  
  > **Comments:**
  > **username_0**: Thanks for your help. I tried to upvote but am not reputationable enough.  
  
  ---
  
  