charmbracelet / vhs

Your CLI home video recorder 📼
MIT License
15.25k stars 260 forks source link

ffmpeg error: Thread message queue blocking #51

Closed DannyBen closed 2 years ago

DannyBen commented 2 years ago

When I started trying a script that is a little longer than the "Hello world" scripts, I am getting an ffmpeg failure.

This script:

Output demo.gif

Type "git --help |most"
Enter
Sleep 300ms

Down@300ms 14
Type "q"
Enter
Sleep 5s

fails with this stdout/stderr:

File: demo.tape
Output .gif demo.gif
Type git --help |most
Enter 1
Sleep 300ms
Down 300ms 14
Type q
Enter 1
Sleep 5s
Creating GIF...
ffmpeg version 4.2.7-0ubuntu0.1 Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
  configuration: --prefix=/usr --extra-version=0ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
Input #0, image2, from '/tmp/vhs2543560270/frame-text-%05d.png':
  Duration: 00:00:20.04, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: png, rgba(pc), 1027x425, 25 fps, 25 tbr, 25 tbn, 25 tbc
Input #1, image2, from '/tmp/vhs2543560270/frame-cursor-%05d.png':
  Duration: 00:00:20.04, start: 0.000000, bitrate: N/A
    Stream #1:0: Video: png, rgba(pc), 1027x425, 25 fps, 25 tbr, 25 tbn, 25 tbc
Stream mapping:
  Stream #0:0 (png) -> overlay:main
  Stream #1:0 (png) -> overlay:overlay
  paletteuse -> Stream #0:0 (gif)
Press [q] to stop, [?] for help
[image2 @ 0x55bd9520da80] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)
[image2 @ 0x55bd9521e4c0] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)
Output #0, gif, to 'demo.gif':
  Metadata:
    encoder         : Lavf58.29.100
    Stream #0:0: Video: gif, pal8, 1200x600, q=2-31, 200 kb/s, 50 fps, 100 tbn, 50 tbc (default)
    Metadata:
      encoder         : Lavc58.54.100 gif
frame=    0 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   0x    
frame=    0 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   0x    
frame=    0 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   0x    
frame=    0 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   0x    
frame=    0 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   0x    
frame=    0 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   0x    
frame=    0 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   0x    
frame=    0 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   0x    
frame=    0 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   0x    
frame=    0 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   0x    
frame=    0 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   0x    

Note that the same script works if you remove the last Sleep, and also this very same script occasionally works for me. The little information I could find hints that it might be something to do with an attempt to render real time where it is not necessary.

Also, reducing framerate to 20 helps, but then it only delays the error which occurs again when continuing to create a longer script.

maaslalani commented 2 years ago

@DannyBen what machine, distribution, and specs are you running on? Also, when running VHS do you have other applications open. I'm wondering if an OOM is being caused.

DannyBen commented 2 years ago

I am running on a vagrant box virtual machine, running Ubuntu with 2gb memory allocated on Intel i7. Nothing is running when vhs is running. I do not expect it to require that much memory...

maaslalani commented 2 years ago

I believe it does require a bit more memory, VHS runs an xterm.js terminal to render the terminal and captures frames every few milliseconds and then has to process all those frames.

If you want VHS to use less memory, you can make the frame sizes smaller by reducing the terminal size (also reduce the font size, to keep a similar ratio), or like you have seen reduce the number of frames captured by reducing the running time of the GIF or reducing the framerate.

Set Width 600
Set Height 300
Set FontSize 14

We will definitely try to make much more performance optimizations in the future so VHS can run smoothly with less memory but for now it is a little intensive since it requires launching a terminal and rendering a massive amount of frames to compile the video.

maaslalani commented 2 years ago

@DannyBen Another thing you can try is outputting the frames without using ffmpeg.

Output frames/
DannyBen commented 2 years ago

Thanks, but for me all this nullifies the advantages of VHS over the "regular" terminal recorders. I will unfortunately have to wait for an optimized version, if it ever arrives.

maaslalani commented 2 years ago

Totally understood! Performance optimization is quite important to us (See https://github.com/charmbracelet/vhs/pull/21), so hopefully we will improve this sooner rather than later! Thanks for leaving your feedback ❤️