GyanD / codexffmpeg

Support for https://www.gyan.dev/ffmpeg
1.31k stars 102 forks source link

ffmpeg & ffprobe: large JPEG error (Picture size 14106x19746 is invalid) #114

Closed DNS closed 4 months ago

DNS commented 4 months ago

Picture.zip

ffprobe.exe -v error -show_format -show_streams picture-1.jpg
[mjpeg @ 0000014427d24180] [IMGUTILS @ 0000001c023ff070] Picture size 14106x19746 is invalid
...
ffmpeg -y -i picture-2.jpg -vf scale=320:-1 out2.jpg
...
[mjpeg @ 0000021061b7e780] [IMGUTILS @ 0000006e7bffeb90] Picture size 14063x20429 is invalid
...

Other files with smaller dimension (eg: 13428x17901) works fine.

GyanD commented 4 months ago

ffmpeg needs to hold the entire image in a single logical contiguous memory buffer, whose size has a limit. Large images can cross that limit and hence aren't supported. That said, I think there is a bug where in some circumstances images below that limit can still be flagged. This may be opened as a ticket at trac.ffmpeg.org but it would be low-priority as ffmpeg's core concern is video and videos are not that large.

Try imagemagick. See https://legacy.imagemagick.org/Usage/files/#massive first.

DNS commented 4 months ago

I use 32GB RAM & no page file. Imagemagick fails too. It produces 0KB jpg files (converting to jxl). When converting it can use 11-21GB of RAM.

Btw, using Adobe Photoshop for resizing on those large files works fine.

GyanD commented 4 months ago

This is not connected to the total memory available. It is a constraint of the system calls used to reserve memory.

Photoshop is an old popular professional tool for photo editing. They will have encountered this limitation early and worked around it by using tiles or similar to store the image in RAM. I'm surprised IM hasn't. Try asking in their forum.