we_full.sh 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/bin/bash
  2. # usage: we_full.sh <scene dir or scene.json/scene.pkg> <out dir> [count] [interval seconds]
  3. # runs on the GPU display :98 (DXVK); WE_DISPLAY=:97 WE_WINED3D=1 is the old Xvfb + wined3d (llvmpipe) path
  4. # full window captures (1920x1058 at +4+30 on :97) of real WE 2.8.42 under Wine, see README.md
  5. ulimit -c 0
  6. S=${WE_LIVE_DIR:-$HOME/.local/share/we_live}
  7. D=${WE_DISPLAY:-:98}
  8. [ "$D" = ":98" ] && { bash "$(dirname "$0")/we_display.sh" >/dev/null || exit 1; }
  9. # WE_WINE_DIR=<other Wine build root> with its own WE_PREFIX (README); default is system Wine and $S/wineprefix
  10. WINE=${WE_WINE_DIR:+$WE_WINE_DIR/bin/wine}; [ -x /usr/lib/wine/wine64 ] && SYS_WINE=/usr/lib/wine/wine64 || SYS_WINE=$(command -v wine); WINE=${WINE:-$SYS_WINE}
  11. WINESERVER=${WE_WINE_DIR:+$WE_WINE_DIR/bin/wineserver}; [ -x /usr/lib/wine/wineserver ] && SYS_WINESERVER=/usr/lib/wine/wineserver || SYS_WINESERVER=$(command -v wineserver); WINESERVER=${WINESERVER:-$SYS_WINESERVER}
  12. export WINEPREFIX=${WE_PREFIX:-$S/wineprefix} DISPLAY=$D WINEDEBUG=${WE_WINEDEBUG:--all} DXVK_LOG_PATH=$S
  13. # Wine must only see the isolated :98, not the desktop session (wayland-0, D-Bus) in the shared runtime dir
  14. unset WAYLAND_DISPLAY WAYLAND_SOCKET DBUS_SESSION_BUS_ADDRESS; export XDG_RUNTIME_DIR=$S/run
  15. # keep Wine off the desktop's audio server (a shared /run/user/<uid>/pulse would play the wallpaper's sounds on real speakers and feed real system audio to the visualizers)
  16. export PULSE_SERVER=unix:$S/run/no-pulse PIPEWIRE_REMOTE=$S/run/no-pipewire ALSA_CONFIG_PATH=/dev/null
  17. # WE_AUDIO_REC=<file.wav>: record WE's audio from a private null sink (audio_sink.sh)
  18. if [ -n "$WE_AUDIO_REC" ]; then
  19. bash "$(dirname "$0")/audio_sink.sh" start || exit 1
  20. eval "$(bash "$(dirname "$0")/audio_sink.sh" env)"
  21. fi
  22. [ -n "$WE_WINED3D" ] && export WINEDLLOVERRIDES="d3d11,d3d10core,dxgi=b"
  23. [ "$D" != ":97" ] || pgrep -f "Xvfb :97" >/dev/null || { Xvfb :97 -screen 0 1920x1080x24 -nolisten tcp >/dev/null 2>&1 & sleep 1; }
  24. $WINESERVER -k 2>/dev/null; timeout 4 tail -f /dev/null
  25. cd $S/we28
  26. F=$1; [ -d "$F" ] && F=$F/scene.json
  27. WIN=$(echo "Z:$F" | tr '/' '\\')
  28. if [ -n "$WE_AUDIO_REC" ]; then
  29. bash "$(dirname "$0")/audio_sink.sh" record "$WE_AUDIO_REC" 600 & REC=$!
  30. # WE plays ~1.5 s after launch, wait for the recorder
  31. for i in $(seq 50); do pactl list short source-outputs 2>/dev/null | grep -q . && break; sleep 0.1; done
  32. sleep 0.5
  33. fi
  34. nohup $WINE wallpaper64.exe -control openWallpaper -file "$WIN" -monitor 0 -playInWindow -silent > $S/we_run_last.log 2>&1 &
  35. timeout 25 tail -f /dev/null
  36. mkdir -p "$2"
  37. python3 - "$2" "${3:-10}" "${4:-1}" "$D" <<'PY'
  38. import sys, time, mss
  39. from PIL import Image
  40. from Xlib import display
  41. d=display.Display(sys.argv[4]); root=d.screen().root
  42. def walk(w):
  43. for c in w.query_tree().children:
  44. yield c; yield from walk(c)
  45. for w in walk(root):
  46. try: n=w.get_wm_name()
  47. except Exception: n=None
  48. if n=='Wallpaper UI': w.unmap()
  49. # the hidden UI leaves its border/shadow strips (8px override-redirect windows) and a small bar on top
  50. for w in root.query_tree().children:
  51. g=w.get_geometry()
  52. if w.get_attributes().map_state==2 and min(g.width,g.height)<=20 and (g.width,g.height)!=(1,1): w.unmap()
  53. d.sync(); time.sleep(2)
  54. t0=time.time()
  55. with mss.MSS(display=sys.argv[4]) as m:
  56. for i in range(int(sys.argv[2])):
  57. s=m.grab({'left':0,'top':0,'width':1920,'height':1080})
  58. Image.frombytes('RGB',s.size,s.rgb).save('%s/f%03d_%.1f.png'%(sys.argv[1],i,time.time()-t0))
  59. time.sleep(float(sys.argv[3]))
  60. PY
  61. $WINESERVER -k 2>/dev/null
  62. if [ -n "$REC" ]; then
  63. pkill -INT -P $REC timeout
  64. wait $REC || true
  65. fi