1

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

2 Answers 2

0

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.

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"

1
  • Thanks for your help. I tried to upvote but am not reputationable enough. Commented Aug 21, 2023 at 2:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.