Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FFmpeg OOM triggers on video export (mp4, webm, maybe more) #799

Open
Oman395 opened this issue Jan 10, 2024 · 5 comments
Open

FFmpeg OOM triggers on video export (mp4, webm, maybe more) #799

Oman395 opened this issue Jan 10, 2024 · 5 comments
Labels
bug Something isn't working plugin:video-creator

Comments

@Oman395
Copy link

Oman395 commented Jan 10, 2024

Title pretty much describes it-- FFmpeg begins making the video, then stops at ~45%. The logs show errors originating from FFmpeg, indicating an OOM event-- looks like it can't handle larger file sizes? I'm not quite sure why this would be an issue though, because this is triggering when exporting a video at 1080x1080@30, with 120 frames, which really shouldn't be that big... and worse, once this happens, if you try to press "cancel", the entire page freezes, and must be closed forcefully.

The graph is here, here's a video of the issue happening, you can find a firefox profiler recording here, and here are the logs:

Some cookies are misusing the recommended “SameSite“ attribute 7
Loading failed for the <script> with source “https://www.desmos.com/assets/build/calculator_geometry-09a7f2ce29359d09401d4b6496ec8c0f5bba742f.js”. geometry:299:94
The warning above (Loading failed for the <script> with source...) is intentional and does not indicate a bug. script.js:3390:13
DesModder is present! (Version 0.12.6) script.js:3394:13
downloadable font: Glyph bbox was incorrect (glyph ids 5 6 8 9 11 12 23 37 38 45 46 48 49 50 53 54 56 60 64 72 73 74 75 76 77 79 80 84 86 88 89 90 92 93 98 99 102 103 106 107 110 124 126 128) (font-family: "dcg-icons-2023-11-14" style:normal weight:400 stretch:100 src index:0) source: https://www.desmos.com/assets/font/dcg-icons-2023-11-14.woff2
ffmpeg version 9e96b1c Copyright (c) 2000-2020 the FFmpeg developers script.js:40159:22
  built with emcc (Emscripten gcc/clang-like replacement) 2.0.8 (d059fd603d0b45b584f634dc2365bc9e9a6ec1dd) script.js:40159:22
  configuration: --target-os=none --arch=x86_32 --enable-cross-compile --disable-x86asm --disable-inline-asm --disable-stripping --disable-programs --disable-doc --disable-debug --disable-runtime-cpudetect --disable-autodetect --extra-cflags='-O3 --closure 1 -I/src/build/include -s USE_PTHREADS=1' --extra-cxxflags='-O3 --closure 1 -I/src/build/include -s USE_PTHREADS=1' --extra-ldflags='-O3 --closure 1 -I/src/build/include -s USE_PTHREADS=1 -L/src/build/lib' --pkg-config-flags=--static --nm=llvm-nm --ar=emar --ranlib=emranlib --cc=emcc --cxx=em++ --objcc=emcc --dep-cc=emcc --enable-gpl --enable-nonfree --enable-zlib --enable-libx264 --enable-libx265 --enable-libvpx --enable-libwavpack --enable-libmp3lame --enable-libfdk-aac --enable-libtheora --enable-libvorbis --enable-libfreetype --enable-libopus --enable-libwebp --enable-libass --enable-libfribidi script.js:40159:22
  libavutil      56. 51.100 / 56. 51.100 script.js:40159:22
  libavcodec     58. 91.100 / 58. 91.100 script.js:40159:22
  libavformat    58. 45.100 / 58. 45.100 script.js:40159:22
  libavdevice    58. 10.100 / 58. 10.100 script.js:40159:22
  libavfilter     7. 85.100 /  7. 85.100 script.js:40159:22
  libswscale      5.  7.100 /  5.  7.100 script.js:40159:22
  libswresample   3.  7.100 /  3.  7.100 script.js:40159:22
  libpostproc    55.  7.100 / 55.  7.100 script.js:40159:22
Input #0, image2, from '*.png': script.js:40159:22
  Duration: 00:00:04.80, start: 0.000000, bitrate: N/A script.js:40159:22
    Stream #0:0: Video: png, rgba(pc), 1724x1724, 25 fps, 25 tbr, 25 tbn, 25 tbc script.js:40159:22
Stream mapping: script.js:40159:22
  Stream #0:0 -> #0:0 (png (native) -> h264 (libx264)) script.js:40159:22
[libx264 @ 0x1a729c0] using cpu capabilities: none! script.js:40159:22
[libx264 @ 0x1a729c0] profile High, level 5.0, 4:2:0, 8-bit script.js:40159:22
[libx264 @ 0x1a729c0] 264 - core 160 - H.264/MPEG-4 AVC codec - Copyleft 2003-2020 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00 script.js:40159:22
Output #0, mp4, to 'out.mp4': script.js:40159:22
  Metadata: script.js:40159:22
    encoder         : Lavf58.45.100 script.js:40159:22
    Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 1724x1724, q=-1--1, 30 fps, 15360 tbn, 30 tbc script.js:40159:22
    Metadata: script.js:40159:22
      encoder         : Lavc58.91.100 libx264 script.js:40159:22
    Side data: script.js:40159:22
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A script.js:40159:22
Pthread aborting at u@blob:https://www.desmos.com/2979d5df-6f41-4128-b02a-ee24ec7735ef:25:81
ra@blob:https://www.desmos.com/2979d5df-6f41-4128-b02a-ee24ec7735ef:199:203
@blob:https://www.desmos.com/a6649532-b510-430c-951c-c3b33d806914:wasm-function[2003]:0x14406d
@blob:https://www.desmos.com/a6649532-b510-430c-951c-c3b33d806914:wasm-function[340]:0x16b73
@blob:https://www.desmos.com/a6649532-b510-430c-951c-c3b33d806914:wasm-function[6247]:0x542417
@blob:https://www.desmos.com/a6649532-b510-430c-951c-c3b33d806914:wasm-function[2607]:0x1de9f7
@blob:https://www.desmos.com/a6649532-b510-430c-951c-c3b33d806914:wasm-function[343]:0x17bdd
@blob:https://www.desmos.com/a6649532-b510-430c-951c-c3b33d806914:wasm-function[3007]:0x24f8d0
@blob:https://www.desmos.com/a6649532-b510-430c-951c-c3b33d806914:wasm-function[10516]:0x8aded5
@blob:https://www.desmos.com/a6649532-b510-430c-951c-c3b33d806914:wasm-function[10179]:0x84f393
@blob:https://www.desmos.com/a6649532-b510-430c-951c-c3b33d806914:wasm-function[3996]:0x34a69f
@blob:https://www.desmos.com/a6649532-b510-430c-951c-c3b33d806914:wasm-function[6082]:0x51e4e1
@blob:https://www.desmos.com/a6649532-b510-430c-951c-c3b33d806914:wasm-function[2219]:0x17e487
@blob:https://www.desmos.com/a6649532-b510-430c-951c-c3b33d806914:wasm-function[6306]:0x548da8
@blob:https://www.desmos.com/a6649532-b510-430c-951c-c3b33d806914:wasm-function[3231]:0x2804d6
@blob:https://www.desmos.com/a6649532-b510-430c-951c-c3b33d806914:wasm-function[13048]:0xaecedb
@blob:https://www.desmos.com/a6649532-b510-430c-951c-c3b33d806914:wasm-function[13050]:0xaee180
createFFmpegCore/f._main@blob:https://www.desmos.com/2979d5df-6f41-4128-b02a-ee24ec7735ef:217:286
K@blob:https://www.desmos.com/2979d5df-6f41-4128-b02a-ee24ec7735ef:171:142
@blob:https://www.desmos.com/a6649532-b510-430c-951c-c3b33d806914:wasm-function[12919]:0xae1cfe
createFFmpegCore/f.dynCall@blob:https://www.desmos.com/2979d5df-6f41-4128-b02a-ee24ec7735ef:28:148
this.onmessage@blob:https://www.desmos.com/1efc5ef9-df24-4af3-9aef-5c85023c2610:1:1757
2979d5df-6f41-4128-b02a-ee24ec7735ef:25:52
OOM 2979d5df-6f41-4128-b02a-ee24ec7735ef:25:97
worker.js onmessage() captured an uncaught exception: RuntimeError: abort(OOM). Build with -s ASSERTIONS=1 for more info. 1efc5ef9-df24-4af3-9aef-5c85023c2610:1:169
u@blob:https://www.desmos.com/2979d5df-6f41-4128-b02a-ee24ec7735ef:25:109
ra@blob:https://www.desmos.com/2979d5df-6f41-4128-b02a-ee24ec7735ef:199:203
@blob:https://www.desmos.com/a6649532-b510-430c-951c-c3b33d806914:wasm-function[2003]:0x14406d
@blob:https://www.desmos.com/a6649532-b510-430c-951c-c3b33d806914:wasm-function[340]:0x16b73
@blob:https://www.desmos.com/a6649532-b510-430c-951c-c3b33d806914:wasm-function[6247]:0x542417
@blob:https://www.desmos.com/a6649532-b510-430c-951c-c3b33d806914:wasm-function[2607]:0x1de9f7
@blob:https://www.desmos.com/a6649532-b510-430c-951c-c3b33d806914:wasm-function[343]:0x17bdd
@blob:https://www.desmos.com/a6649532-b510-430c-951c-c3b33d806914:wasm-function[3007]:0x24f8d0
@blob:https://www.desmos.com/a6649532-b510-430c-951c-c3b33d806914:wasm-function[10516]:0x8aded5
@blob:https://www.desmos.com/a6649532-b510-430c-951c-c3b33d806914:wasm-function[10179]:0x84f393
@blob:https://www.desmos.com/a6649532-b510-430c-951c-c3b33d806914:wasm-function[3996]:0x34a69f
@blob:https://www.desmos.com/a6649532-b510-430c-951c-c3b33d806914:wasm-function[6082]:0x51e4e1
@blob:https://www.desmos.com/a6649532-b510-430c-951c-c3b33d806914:wasm-function[2219]:0x17e487
@blob:https://www.desmos.com/a6649532-b510-430c-951c-c3b33d806914:wasm-function[6306]:0x548da8
@blob:https://www.desmos.com/a6649532-b510-430c-951c-c3b33d806914:wasm-function[3231]:0x2804d6
@blob:https://www.desmos.com/a6649532-b510-430c-951c-c3b33d806914:wasm-function[13048]:0xaecedb
@blob:https://www.desmos.com/a6649532-b510-430c-951c-c3b33d806914:wasm-function[13050]:0xaee180
createFFmpegCore/f._main@blob:https://www.desmos.com/2979d5df-6f41-4128-b02a-ee24ec7735ef:217:286
K@blob:https://www.desmos.com/2979d5df-6f41-4128-b02a-ee24ec7735ef:171:142
@blob:https://www.desmos.com/a6649532-b510-430c-951c-c3b33d806914:wasm-function[12919]:0xae1cfe
createFFmpegCore/f.dynCall@blob:https://www.desmos.com/2979d5df-6f41-4128-b02a-ee24ec7735ef:28:148
this.onmessage@blob:https://www.desmos.com/1efc5ef9-df24-4af3-9aef-5c85023c2610:1:1757
1efc5ef9-df24-4af3-9aef-5c85023c2610:1:169
pthread sent an error! blob:https://www.desmos.com/2979d5df-6f41-4128-b02a-ee24ec7735ef:25: RuntimeError: abort(OOM). Build with -s ASSERTIONS=1 for more info. script.js:40159:22
[bugsnag] Error: payload exceeded 1MB limit
    report moz-extension://4599a82f-7004-409c-98b9-5a273868ac7c/preload/script.js line 3405 > eval:86
    sendReport moz-extension://4599a82f-7004-409c-98b9-5a273868ac7c/preload/script.js line 3405 > eval:86
    notify moz-extension://4599a82f-7004-409c-98b9-5a273868ac7c/preload/script.js line 3405 > eval:80
    Te moz-extension://4599a82f-7004-409c-98b9-5a273868ac7c/preload/script.js line 3405 > eval:72
    Te moz-extension://4599a82f-7004-409c-98b9-5a273868ac7c/preload/script.js line 3405 > eval:72
    ge moz-extension://4599a82f-7004-409c-98b9-5a273868ac7c/preload/script.js line 3405 > eval:72
    Te moz-extension://4599a82f-7004-409c-98b9-5a273868ac7c/preload/script.js line 3405 > eval:72
    Te moz-extension://4599a82f-7004-409c-98b9-5a273868ac7c/preload/script.js line 3405 > eval:72
    ge moz-extension://4599a82f-7004-409c-98b9-5a273868ac7c/preload/script.js line 3405 > eval:72
    Te moz-extension://4599a82f-7004-409c-98b9-5a273868ac7c/preload/script.js line 3405 > eval:72
    Te moz-extension://4599a82f-7004-409c-98b9-5a273868ac7c/preload/script.js line 3405 > eval:72
    ge moz-extension://4599a82f-7004-409c-98b9-5a273868ac7c/preload/script.js line 3405 > eval:72
    Te moz-extension://4599a82f-7004-409c-98b9-5a273868ac7c/preload/script.js line 3405 > eval:72
    Te moz-extension://4599a82f-7004-409c-98b9-5a273868ac7c/preload/script.js line 3405 > eval:72
    ge moz-extension://4599a82f-7004-409c-98b9-5a273868ac7c/preload/script.js line 3405 > eval:72
    Te moz-extension://4599a82f-7004-409c-98b9-5a273868ac7c/preload/script.js line 3405 > eval:72
    Te moz-extension://4599a82f-7004-409c-98b9-5a273868ac7c/preload/script.js line 3405 > eval:72
    ge moz-extension://4599a82f-7004-409c-98b9-5a273868ac7c/preload/script.js line 3405 > eval:72
    Te moz-extension://4599a82f-7004-409c-98b9-5a273868ac7c/preload/script.js line 3405 > eval:72
    Te moz-extension://4599a82f-7004-409c-98b9-5a273868ac7c/preload/script.js line 3405 > eval:72
    ge moz-extension://4599a82f-7004-409c-98b9-5a273868ac7c/preload/script.js line 3405 > eval:72
    Te moz-extension://4599a82f-7004-409c-98b9-5a273868ac7c/preload/script.js line 3405 > eval:72
    Te moz-extension://4599a82f-7004-409c-98b9-5a273868ac7c/preload/script.js line 3405 > eval:72
    ge moz-extension://4599a82f-7004-409c-98b9-5a273868ac7c/preload/script.js line 3405 > eval:72
    Te moz-extension://4599a82f-7004-409c-98b9-5a273868ac7c/preload/script.js line 3405 > eval:72
    Te moz-extension://4599a82f-7004-409c-98b9-5a273868ac7c/preload/script.js line 3405 > eval:72
    ge moz-extension://4599a82f-7004-409c-98b9-5a273868ac7c/preload/script.js line 3405 > eval:72
    Te moz-extension://4599a82f-7004-409c-98b9-5a273868ac7c/preload/script.js line 3405 > eval:72
    x moz-extension://4599a82f-7004-409c-98b9-5a273868ac7c/preload/script.js line 3405 > eval:72
    notify moz-extension://4599a82f-7004-409c-98b9-5a273868ac7c/preload/script.js line 3405 > eval:80
    notify moz-extension://4599a82f-7004-409c-98b9-5a273868ac7c/preload/script.js line 3405 > eval:80
    H moz-extension://4599a82f-7004-409c-98b9-5a273868ac7c/preload/script.js line 3405 > eval:88
script.js line 3405 > eval:86:1673
RuntimeError: abort(OOM). Build with -s ASSERTIONS=1 for more info. 2979d5df-6f41-4128-b02a-ee24ec7735ef:25:109
@Oman395
Copy link
Author

Oman395 commented Jan 10, 2024

Update: looks like this only applies when the resolution is (scaled?)-- I tried the same thing, but native res, and it exported flawlessly-- potentially FFmpeg has an issue with supersampling?

@SlimRunner
Copy link
Contributor

SlimRunner commented Jan 10, 2024

I think this might be a standard out of memory (OOM) problem. I was able to record and save your graph at 1920x1080@30fps with 120 frames of length without issues.

Even if your system has enough "free" memory to allocate all frames and data during processing, the OS can still deny that memory to Firefox and Firefox has no other option, but to throw an exception.

Also, you mentioned that it only works at native resolution, but the "native" resolution has nothing special as far the Video Creator is concerned because Desmos generates frames with the desired resolution as you are capturing. By the time you export, the images used to create the video are correctly sized and need no scaling.

However, if at a lower resolution you still have a crash, that could be an issue that needs further investigation.

@jared-hughes
Copy link
Member

Wow! This is a well-put-together bug report. I especially appreciate the profiler recording. Looks like it starts out with one worker, then switches to another, then there's 7. (Maybe that's ffmpeg.wasm trying to multi-thread).

My normal recommendation here is to make sure you have plenty of free RAM, but yeah it sometimes (often) OOMs earlier than you'd expect. As a workaround, you can export as ZIP instead of video, then put the frames together with a local copy of ffmpeg.

I don't know how to start debugging this. Maybe by looking through ffmpeg.wasm issues.

ffmpegwasm/ffmpeg.wasm#136 suggests ffmpeg.exit() so memory is freed between invocations, but I don't think that's the problem here.

@jared-hughes jared-hughes added bug Something isn't working plugin:video-creator labels Jan 11, 2024
@Oman395
Copy link
Author

Oman395 commented Jan 17, 2024

I think this might be a standard out of memory (OOM) problem. I was able to record and save your graph at 1920x1080@30fps with 120 frames of length without issues.

Even if your system has enough "free" memory to allocate all frames and data during processing, the OS can still deny that memory to Firefox and Firefox has no other option, but to throw an exception.

Also, you mentioned that it only works at native resolution, but the "native" resolution has nothing special as far the Video Creator is concerned because Desmos generates frames with the desired resolution as you are capturing. By the time you export, the images used to create the video are correctly sized and need no scaling.

However, if at a lower resolution you still have a crash, that could be an issue that needs further investigation.

Sorry for the late reply, forgot to check my gh .-. when I say native resolution, what I mean is that it saves fine when set to 1724x1259, which is the desmos display size I'm using, but when I set it to 1080x1080, it OOMs every time. I should have plenty of memory, unless 16gb somehow isn't enough for this-- it's definitely possible that Firefox isn't getting enough memory, but I doubt it, given that this is the first time I've OOMed on ff, ever (and I'm running arch, which I've never seen just straight up deny any application enough memory to function properly (unless it was literally out of memory)). I can't remember if the ff profiler capture has the memory usage of my entire system, but I'll probably give it another run to check my OS memory usage (and also check journalctl/dmesg, which I forgot last time).

@jared-hughes
Copy link
Member

It's possible there's a bug somewhere in ffmpeg that's trying to allocate more memory than it needs. I don't see how though. 1080x1080 is a normal-looking resolution. I would rather expect 1724x1259 to have that bug, if the bug did exist, since it's an odd resolution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working plugin:video-creator
Projects
None yet
Development

No branches or pull requests

3 participants