[FFmpeg-user] Converting a video to a set of images from specific frames while cropping each frame differently

Matt Groth mgroth49 at gmail.com
Mon Jun 5 01:35:34 EEST 2023


Hello, 

I hope this is the appropriate place to ask an open-ended question. The approach I am trying to take may be leading me into a dead end because of a bug, but also I may facing an XY problem because my approach itself feels pretty wacky.

My input is a video. My output will be a set of PNG files, each file corresponding to a frame.

I have metadata that describes which frames to include. Also, for each frame I have a bounding box. For each frame that I include, I need to apply a unique crop.

I have code that generates a complex filtergtaph. Currently, I am using an approach that should work in theory. However, the approach feels wacky (I can get over that feeling if someone would tell me it’s ok). The real issue though, is that I run an error.

The filter has the following format:

```
select=
	if(eq(n\,36)\,n+1\,0)
	+if(eq(n\,39)\,n+1\,0)
	:2
	[N36][N39]
;[N36]crop=w=121:h=389:x=1092:y=253
;[N39]crop=w=125:h=385:x=1091:y=255;
```

However, each video has thousands of frames. When running, I get the following error:

```
Number of streams exceeds max_streams parameter (1000), see the documentation if you wish to increase it
```

When I set the -max_streams option before the `-i` argument, it doesn’t help. I know that the -max_streams option is correctly passing through because if I set -max_streams to 0, it throws an error saying I’ve exceeded the max frames (0).

I figured maybe this is one of those cases where the argument needs to be applied to the output. But no matter where, or how many -max_streams 10000` I insert into my shell command, the above error always appears. For example:

```
ffmpeg -y -max_streams 10000 -i $INPUT_MP4 -max_streams 10000 -filter_complex $INPUT_VID_FFMPEG_FILE -threads 2 -frame_pts 1 -fps_mode passthrough $OUTPUT_FILE
```

With this I still get the error.



So, in conclusion I have these points/questions:
1) How do I correctly set `max_streams` so that I can avoid that error? Or if I am already setting `max_streams` correctly, is this a bug I have discovered?
2) Am I facing an XY issue? Is there a more elegant/performant way to apply a separate crop per frame (while excluding some frames altogether) when there are thousands of such frames per video?

By the way, I am doing this task in a performance-critical context. There are hundreds of hours of video, 30 FPS, and this extraction may need to be done many times for the whole dataset. I have access to a computing cluster so I have a large amount of computing power and can parallelize with both CPU and GPU, but even still I need to be as efficient as possible.

Thanks,
Matt


More information about the ffmpeg-user mailing list