dlemstra / Magick.NET

The .NET library for ImageMagick
Apache License 2.0
3.49k stars 415 forks source link

Exception "Invalid minimum required packet size" in Version 14.1 and up #1761

Open TheNetStriker opened 1 day ago

TheNetStriker commented 1 day ago

Magick.NET version

14.2 Magick.NET-Q16-HDRI-AnyCPU

Environment (Operating system, version and so on)

Windows 10

Description

After I've updated from version 14.0 to 14.2 I get the following error after a long period when trying to create a thumbnail from a GoPro video:

ImageMagick.MagickDelegateErrorException : VideoDelegateFailed `[libwebp_anim @ 000001e45c4900c0] Invalid minimum required packet size 2627894982 (max allowed is 2147483583)
video encoding failed: Invalid argument
' @ error/video.c/ReadVIDEOImage/273

  Stack Trace: 
UnitTest1.SaveVideoThumbnailTest() line 411
--- End of stack trace from previous location ---
----- Inner Stack Trace -----
NativeInstance.CheckException(IntPtr exception, IntPtr result) line 54
NativeMagickImage.ReadStream(IMagickSettings`1 settings, ReadWriteStreamDelegate reader, SeekStreamDelegate seeker, TellStreamDelegate teller, Void* data) line 6139
NativeMagickImage.ReadStream(IMagickSettings`1 settings, ReadWriteStreamDelegate reader, SeekStreamDelegate seeker, TellStreamDelegate teller) line 7536
MagickImage.Read(Stream stream, IMagickReadSettings`1 readSettings, Boolean ping) line 7455
MagickImage.Read(Stream stream, IMagickReadSettings`1 readSettings) line 4658
MagickImage.ctor(Stream stream, IMagickReadSettings`1 readSettings) line 192
StaticFunctions.SaveImageThumbnail(idCatalogItem catalogItem, IDImagerDB db, IDImagerThumbsDB dbThumbs, List`1 types, ServiceSettings serviceSettings) line 105

The error also occurs in version 14.1. Only if I downgrade to 14.0 again it works.

Any idea what could cause this problem?

Steps to Reproduce

Here is a code example:

if (Enum.TryParse<MagickFormat>("MP4", true, out MagickFormat magickFormat))
{
    magickReadSettings = new MagickReadSettings { Format = magickFormat };
    MagickImage image = new MagickImage(imageStream, magickReadSettings)
    {
        Format = MagickFormat.Jpeg,
    };
}

The error occurs on the new MagickImage line after a long period. (I measured 33.3 minutes with my unit test)

dlemstra commented 1 day ago

There is no version 4.2, did you mean 14.2? Are you sure that only this library got upgraded and not a library on your system? The ffmpeg executable is used to read your video and I suspect that something changed there?

TheNetStriker commented 17 hours ago

There is no version 4.2, did you mean 14.2? Are you sure that only this library got upgraded and not a library on your system? The ffmpeg executable is used to read your video and I suspect that something changed there?

Sorry I mistyped the version number. Yes I meant the 14.2 version. I've just updated the title and text with the correct version number.

I did only change the library version to reproduce this.

I did some more test's and I guess I found out what is causing this issue. I tracked the ffmpeg command line arguments of both library versions using ProcessMonitor and found out that from version 14.1 the -vframes 1 command line argument of the ffmpeg process is missing. Instead there are just two spaces:

rawvideo -y -vcodec webp

In version 14.0 the -vframes 1 argument is just between those two arguments. This causes the ffmpeg command to run for a long time and then it causes the error.

Any idea why this command line argument was removed?

dlemstra commented 16 hours ago

Thanks for all your research! I suspect that was removed to make it possible to read all the images in your mp4 file. But that should happen automatically when you use a MagickImage. I will need to figure out why this is no longer happening but I suspect I removed this by accident. Setting FrameCount = 1 in the MagickReadSettings should fix your issue for now.