Repository navigation
Description
Adding an Image or Image Slide Show source with an extremely large PNG image file (eg: 20480 x 11520px) temporarily consumes a large amount of RAM and causes OBS to become non-responsive, until a later stage rejects the image for being too large.
The non-responsiveness then triggers audio-video de-synchronisation for the remainder of the broadcast with an active RTMP (and probably other) source, as OBS' stream output continues to send audio but not new video frames.
Platform
Operating system and version: Windows 10 Pro 64-bit (Build 1903)
OBS Studio version: 25.0.8, 64-bit, installed from obsproject.com
Expected Behavior
Excessively large images should be rejected early, when parsing the image metadata, without loading the entire image as a bitmap into RAM. An ideal upper limit would be something like the larger of 2x the size of the output frame size, or 4K.
Current Behavior
Based on observed memory usage patterns, it appears that OBS still decompresses the entire PNG image into a buffer, then allocates 2 or 3 copies of this buffer (RAM usage for 1 copy of the image would be about 900MiB, but we saw more than 2.6GiB), before deciding that the image is way too large, and replacing it with a translucent frame.
The amount of time OBS locks up for varies depending on the complexity of the image. Using an image with a solid colour and basic text decompresses very quickly, and releases memory quickly. Using an image consisting entirely of random noise takes much longer to decompress.
The log file reports:
17:22:58.055: User switched to scene 'Scene 2'
17:23:05.782: device_texture_create (D3D11): Failed to create 2D texture (80070057)
The error appears to be thrown from
obs-studio/libobs-d3d11/d3d11-texture2d.cpp
Lines 126 to 129 in bad7b55
| hr = device->device->CreateTexture2D(&td, data ? srd.data() : NULL, | |
| texture.Assign()); | |
| if (FAILED(hr)) | |
| throw HRError("Failed to create 2D texture", hr); |
E_INVALIDARG (0x80070057) | An invalid parameter was passed to the returning function.
This suggests that the loading process goes very far along without any checks, and D3D is simply rejecting it out of hand.
During the "loading" time, even if the image source is removed or the scene is changed again, the image is still loading in the background and consuming RAM and CPU, blocking scene changes and further source manipulation.
Steps to Reproduce
-
In your favourite image editor, create a new image of 20480 x 11520px
-
Add some content to this image, such that it can be seen on a black background (eg: draw some text and coloured lines).
To see memory usage for longest, use your image editor's
Hurl Noisefunction with maximum randomness of colour values. -
Save this image as a PNG file. In my tests, simple content came out at about 1.7MiB, whereas random noise came out at 459MiB.
-
Start OBS, and start Task Manager to track the process' memory usage.
-
In a new OBS scene, add a new
ImageorImage Slideshowsource. -
Fit the source to the frame (right-click ->
Transform->Fit to screen), and then lock it by clicking the padlock 🔒 . -
Edit the properties of the
ImageorImage Slideshowand set theImage Fileto the large PNG created in step 3.
For Image sources, enabling Unload image when not showing allows you to more easily measure the amount of time it takes for images to load, and causes OBS to retry loading the image after a scene change, without needing to manually change the image source.
Additional information
Switching between a scene with a large, random image source takes about 10 seconds.
Switching between two scenes with image sources, with Unload image when not showing enabled, and one of the image sources are large, takes about 21 seconds to change.
This issue is easy to unintentionally trigger, and occurred in production for a live event I was involved with. For example, if an image intended for an overlay was created at 1920x1080 millimetres (=22677x12756 px at 300 PPI), instead of 1920x1080 pixels.
Even Windows "open file" dialog renders the thumbnails of such images correctly, so there's no way for the operator to know they're about to break OBS, especially if the file was supplied by a third party.
Activity
[-]Loading large PNG images temporarily consumes large amounts of RAM[/-][+]Loading large PNG images temporarily consumes large amounts of RAM and causes OBS to be non-responsive[/+]devjack commentedon Sep 7, 2020
I would also second this - it occurred during an event I was running recently. Third party graphics provided last minute caused the issue as they skipped a pre-production QA process. Having checks prior to loading would be extremely valuable in ensuring the stability of OBS during live events.
micolous commentedon Sep 8, 2020
I've been trying to understand the failure modes of this issue better.
It looks like
gs_image_file_init_internaloutright rejects some very large images much faster, in particular, the 1920x1080mm (22677x12756px) one:Looking at
gs_image_file_init_internal, for non-GIF files this calls out togs_create_texture_file_data, and then later checks the result (which is where our later two error comes from):obs-studio/libobs/graphics/image-file.c
Lines 202 to 214 in c938ea7
gs_create_texture_file_dataappears to have two platform-specific implementations, and I'm presuming on Windows it uses ffmpeg. The first error message comes fromffmpeg_image_decode:obs-studio/libobs/graphics/graphics-ffmpeg.c
Lines 227 to 231 in 6a79657
Unwinding the stack a little, this would indicate
ffmpeg_image_initsuccessfully completed, and we tried to allocate some memory for the full image size here:obs-studio/libobs/graphics/graphics-ffmpeg.c
Line 273 in 6a79657
Using the
ffprobeutility, I can seeffmpegrejects this image very early:This appears to be thrown from
av_image_check_size2, which limits the image to< 2^31bytes total:https://github.com/FFmpeg/FFmpeg/blob/9faae05ddf27369838fbd500468484af31f1219c/libavutil/imgutils.c#L300-L303
However, using
ffprobeagainst the 20480x11520px random image works fine (although it uses about 1.8GB of RAM for about 6 seconds):Another limit here is in
D3D11_TEXTURE2D_DESC, which has a cap of 16384x16384 pixels on all textures, which is wheredevice_texture_create (D3D11): Failed to create 2D texture (80070057)came from.I created some other test images, and observed different results:
16384x16384px (=D3D limit): rejected by
ffmpeg(too early):[IMGUTILS @ 0x7ffff0b92de0] Picture size 16384x16384 is invalid16383x11520px (<D3D limit): allowed by
ffmpeg, peaks at around 1.7GB RAM usage, and 0.7GB VRAM usage. OBS crashes reliably: it looks like it lands in the bowels of D3D/nvidia driver code: https://gist.github.com/micolous/5d6ba43726035157098841a9051a9a33Both of those I'd expect OBS to reject somewhere in
ffmpeg_image_init.micolous commentedon Sep 8, 2020
tl;dr on above, there are multiple limits:
PNG has an image dimension limit of
(2^32)-1pixels, according to the spec. I haven't been able to make an image that big yet to check for crashes there.ffmpeg has an (approximately)
2^31byte image buffer limit.If it goes over,
av_image_check_size2says no (and the image won't display at all in OBS), but you still have OBS allocating awidth * height * 4byte buffer ings_create_texture_file_datatemporarily. If thatbmallocfails, OBS will crash with "out of memory".I think there's additional format conversion happening inside of OBS which I haven't really dug in to. Those temporarily allocate more memory, which could also cause OBS to crash with "out of memory".
D3D has a limit of 16384x16384 pixels on textures.
If it's larger than that, you'll get
device_texture_create (D3D11): Failed to create 2D texture (80070057). OBS may become non-responsive and spike RAM usage for several seconds (from the earlier steps), and you may get A/V desynchronisation once it unlocks, which matches the behaviour we observed in our event.However, large images which are smaller than this limit can result in a crash, deep within in D3D. The scene can also be saved by OBS, causing it to be permanently broken without renaming PNG files or hacking scene configuration files manually.
We got very lucky when this issue hit us on a 20480x11520px image:
This could be mitigated in OBS with some simple checks in
ffmpeg_image_init.PS: it also looks like any
bmalloc()failure will result in a crash:obs-studio/libobs/util/bmem.c
Lines 98 to 111 in c938ea7
...and there's no way for OBS code handle an out-of-memory condition gracefully.
RytoEX commentedon Sep 8, 2020
Minor clarification:
The texture size limit is actually determined by the D3D level used on the rendering device created by OBS. 16384 is the maximum dimension for textures using 11_0. The maximum value for 10_1 or 10_0 is 8192.
https://docs.microsoft.com/en-us/windows/win32/direct3d11/overviews-direct3d-11-devices-downlevel-intro
kkartaltepe commentedon Apr 1, 2022
Leaving this open but marking it as not a bug generally. I dont think we will ever attempt to make OBS not crash when memory allocations fail, so those cases are all working as intended. Large video memory allocations failing and causing drivers to crash is also not fixable by us.
Finally large images causing long hangs and delays are unlikely to change, the image source is intended to stall rendering while it loads right now. Possibly a change to make it load async, but there are more issues to resolve in such an implementation.
micolous commentedon Apr 1, 2022
Sure, that's reasonable, but OBS can avoid getting to that unsafe position. As detailed in my earlier comments, the size validation checks OBS does are far too late to prevent this class of issue. That is a bug.
By checking the image metadata before sending it off to the graphics stack, OBS could check if the image is larger than some arbitrary "very large" amount (say, 8192x4096px), pop up a warning:
Have an option in the settings somewhere if someone wants to skip this prompt, potentially shooting themselves in the foot. 😄
As you've noticed, there's multiple crash reports that are definitely caused by loading large images.
The incident that prompted this issue report started as a regular occurrence in live events: an innocent, last minute change. Unfortunately, the author of the graphics made an unintentional error that nearly took the whole event offline – and nobody involved had any warning. We got very lucky that it merely locked up the mixer for a minute or so, but it caused a huge panic for everyone involved.
Processing asynchronously would be nice to have (but complicated), but the bare minimum OBS could do is warn about these sorts of landmines (and that part is easier).
Fenrirthviti commentedon Apr 1, 2022
We already have similar sanity checks in place for the actual canvas size, I don't think it's unreasonable to include them for sources.
Just to confirm, these limits are universal across all systems? Or is there variance that adds complexity to that kind of programmatic check?
RytoEX commentedon Apr 1, 2022
I mentioned this previously, but D3D texture size limits vary. Feature Level 10_0 and 10_1 are limited to 8192x8192 for 2D textures, while Feature Level 11_0 through 12_2 are limited to 16384x16384. If I recall correctly, we still currently support Feature Level 10_0 in the codebase, though we generally advertise that DX 10.1 is the minimum supported version. I'm not clear on if our minimum supported feature level is 10_0 or 10_1, but in either case, we still support 8192x8192 2D textures as possible maximum.
OpenGL texture size limits seem to vary between 1024, 2048, 4096, 8192, and 16384, depending on GL_MAX_TEXTURE_SIZE. It seems that 8192 and 16384 are most common these days. I'll defer to @kkartaltepe on the subject though.
kkartaltepe commentedon Apr 2, 2022
I think last we checked all hardware that supports opengl 3.2/3.3 (on mesa) supported 8k textures, but 16k support is rare for older hardware.
Fenrirthviti commentedon Oct 14, 2024
Closing as stale. If this is still an issue please open a new issue with updated reproduction steps on the latest version of OBS.