webcam-loopback-manipulation-screensharing-and-stuff git · main
vcam: v4l2 loopback with overlays, filters, OpenCV and RVM matting
C 51.3% C++ 40.7% Markdown 6.9% Makefile 1%git clone https://git.christianimmanuel.de/linux-system/webcam-loopback-manipulation-screensharing-and-stuff.gitwget https://git.christianimmanuel.de/linux-system/webcam-loopback-manipulation-screensharing-and-stuff/archive/webcam-loopback-manipulation-screensharing-and-stuff.tar.gz..
EXPRESSIONS.md | 208 ++++++++++++++++++++++++++++++++ INSTALL.md | 146 +++++++++++++++++++++++ LICENSE | 339 +++++++++++++++++++++++++++++++++++++++++++++++++++++ Makefile | 12 +- NOTICE | 70 +++++++++++ README.md | 155 +++++++++++------------- include/vcam.h | 20 ++++ scripts/vcam-ctl | 158 +++++++++++++------------ scripts/vcam-setup | 54 +++++---- scripts/vcam-tune | 4 + 10 files changed, 982 insertions(+), 184 deletions(-) diff --git a/EXPRESSIONS.md b/EXPRESSIONS.md new file mode 100644 index 0000000..9d35220 --- /dev/null +++ b/EXPRESSIONS.md @@ -0,0 +1,208 @@ +# The mathwarp Expression Cookbook + +`mathwarp` turns the webcam into a programmable canvas. You write math, +and every pixel obeys it — in real time, recompiled the instant you hit +Enter. Two independent expression sets drive it: + +- **warp** — `filter expr <dx> <dy>` — moves each pixel by `(dx, dy)` +- **color** — `filter color <r> <g> <b>` — recolors each pixel (0–255 per channel) + +Use either alone, or both together. Add the filter first: + +```sh +vcam-ctl filter add mathwarp 1.0 # the 1.0 is a global warp-amplitude knob +``` + +Then paste any recipe below. Every expression here is **verified to +compile**. There are no spaces inside an expression (spaces separate the +dx/dy or r/g/b arguments). + +--- + +## The language + +**Variables available everywhere** + +| var | meaning | +|-----|---------| +| `x` `y` | pixel coordinates (0,0 = top-left) | +| `w` `h` | frame width / height | +| `t` | time in seconds (this is what makes things move) | +| `r` | distance from the center | +| `a` | angle from the center, in radians (−π … π) | + +**Extra variables in color expressions only** + +| var | meaning | +|-----|---------| +| `cr` `cg` `cb` | this pixel's source Red / Green / Blue (0–255) | + +**Functions:** `sin` `cos` `abs` `sqrt` `floor` +**Operators:** `+ - * / %` · comparisons `> < >= <= == !=` · ternary `cond?a:b` · parentheses · unary `-` + +A comparison returns `1.0` or `0.0`, so you can multiply by it (`sin(t)*(r<200)`) +or branch with the ternary (`r<200?sin(t)*20:0`). Division and modulo by +zero are guarded and yield 0 — expressions can never crash. + +--- + +## WARP recipes — `filter expr <dx> <dy>` + +### Gravity & vortex + +```sh +# Black hole — everything is sucked toward the center, harder up close +vcam-ctl filter expr (x-w/2)*(-0.3)*sqrt(w*w/4/(r*r+1)) (y-h/2)*(-0.3)*sqrt(w*w/4/(r*r+1)) + +# Twist tornado — a rotational shear that grows with radius +vcam-ctl filter expr sin(a*2+r/20-t*3)*r*0.06 cos(a*2+r/20-t*3)*r*0.04 + +# Breathing vortex — a whirlpool that inhales and exhales +vcam-ctl filter expr sin(a*3+t*2)*(sin(t)*20+20)*sin(r/50) cos(a*3+t*2)*(sin(t)*20+20)*sin(r/50) + +# Pinch pulse — the whole image clenches to a point and releases +vcam-ctl filter expr (x-w/2)*sin(t*3)*0.12 (y-h/2)*sin(t*3)*0.12 +``` + +### Waves & ripples + +```sh +# Ripple pond — concentric waves flowing out from the center +vcam-ctl filter expr sin(sqrt((x-w/2)*(x-w/2)+(y-h/2)*(y-h/2))/8-t*4)*12 0 + +# Shockwave burst — a ring of distortion that only exists within radius 200 +vcam-ctl filter expr cos(r/12-t*6)*(r<200?20:0) sin(r/12-t*6)*(r<200?20:0) + +# Wobble grid — two interfering sine fields, liquid glass +vcam-ctl filter expr sin(y/15+t*3)*8+cos(x/25-t)*5 cos(x/15+t*3)*8+sin(y/25-t)*5 + +# Pulsing rings with angular petals — a living flower +vcam-ctl filter expr sin(r/10-t*5)*cos(a*3)*15 sin(r/10-t*5)*sin(a*3)*15 +``` + +### Geometric & tiled + +```sh +# Checkerslide — alternating 50px tiles drift in opposite directions +vcam-ctl filter expr (floor(x/50)%2==0?1:-1)*sin(t*2)*20 (floor(y/50)%2==0?1:-1)*cos(t*2)*20 + +# Quadrant spin — each screen quarter shears independently +vcam-ctl filter expr (x>w/2?1:-1)*(y>h/2?1:-1)*sin(t*4)*15 (x>w/2?-1:1)*sin(t*4)*15 + +# Kaleidofold — 8-fold angular ripples modulated by radius +vcam-ctl filter expr sin(a*8+t)*20*sin(r/40) cos(a*8+t)*20*sin(r/40) + +# DNA helix — horizontal sine displacement scrolling down the frame +vcam-ctl filter expr sin(y/20+t*2)*30 0 +``` + +### Chaos & motion + +```sh +# Earthquake — a violent horizontal shudder, opposite on each half +vcam-ctl filter expr sin(t*30+y*0.3)*(x>w/2?8:-8) cos(t*25+x*0.2)*6 + +# Melting wax — the image sags and drips downward +vcam-ctl filter expr sin(x/30+t)*6 abs(sin(x/20-t*2))*sin(y/40)*25 + +# Radial strobe — snaps inward on the beat, then frees itself +vcam-ctl filter expr (x-w/2)*(sin(t*8)>0?0.15:0) (y-h/2)*(sin(t*8)>0?0.15:0) +``` + +--- + +## COLOR recipes — `filter color <r> <g> <b>` + +Turn recolor off any time with `vcam-ctl filter color off`. + +### Channel play + +```sh +# Channel rotate — R←G, G←B, B←R (alien palette) +vcam-ctl filter color cg cb cr + +# Invert — photographic negative +vcam-ctl filter color 255-cr 255-cg 255-cb + +# Matrix green — collapse to luminance, keep only green +vcam-ctl filter color 0 (cr+cg+cb)/3 0 + +# Duotone teal-orange — the cinematic blockbuster grade +vcam-ctl filter color cr*0.5+cb*0.3 cg*0.6+cr*0.2 cb*0.8 +``` + +### Posterize & threshold + +```sh +# Posterize — crush each channel to 4 levels, poster-print look +vcam-ctl filter color floor(cr/64)*64 floor(cg/64)*64 floor(cb/64)*64 + +# Solarize — invert only the bright half of each channel (Sabattier effect) +vcam-ctl filter color cr>128?255-cr:cr cg>128?255-cg:cg cb>128?255-cb:cb + +# Neon glow — push saturated reds and blues to full blast +vcam-ctl filter color cr>100?255:cr cg cb>100?255:cb + +# Heatmap — hot areas glow, cold areas go blue +vcam-ctl filter color cr+cg+cb>380?255:cr (cr+cg+cb)/3 cr+cg+cb<200?150:cb +``` + +### Time & space driven + +```sh +# Rainbow by x — a spectrum sweeps across the frame, scrolling forever +vcam-ctl filter color sin(x/40+t)*127+128 sin(x/40+t+2)*127+128 sin(x/40+t+4)*127+128 + +# Strobe flash — the whole frame blinks white on the beat +vcam-ctl filter color sin(t*10)>0?255:cr cg cb + +# Chroma pulse — red and blue breathe out of phase +vcam-ctl filter color cr*(sin(t*3)*0.5+0.5) cg cb*(cos(t*3)*0.5+0.5) + +# Radial tint — warm in the center, cool at the edges +vcam-ctl filter color cr*(r/400) cg cb*(1-r/400) + +# Scanline color — every 4th row burns red, CRT-style +vcam-ctl filter color y%4==0?255:cr cg cb +``` + +--- + +## Combining warp + color + +The two run in sequence (warp first, then color reads the warped pixel), +so they stack into something greater than either. A few showpieces: + +```sh +# ── Psychedelic wormhole ── +vcam-ctl filter expr sin(a*3+t*2)*(sin(t)*20+20)*sin(r/50) cos(a*3+t*2)*(sin(t)*20+20)*sin(r/50) +vcam-ctl filter color sin(r/30+t)*127+128 sin(r/30+t+2)*127+128 sin(r/30+t+4)*127+128 + +# ── Earthquake TV ── (violent shake + channel-split glitch color) +vcam-ctl filter expr sin(t*30+y*0.3)*(x>w/2?8:-8) cos(t*25+x*0.2)*6 +vcam-ctl filter color cg cr cb + +# ── Liquid chrome ── (glassy wobble + solarized metal) +vcam-ctl filter expr sin(y/15+t*3)*8+cos(x/25-t)*5 cos(x/15+t*3)*8+sin(y/25-t)*5 +vcam-ctl filter color cr>128?255-cr:cr cg>128?255-cg:cg cb>128?255-cb:cb + +# ── Black-hole rainbow ── (gravitational pull + spectrum by radius) +vcam-ctl filter expr (x-w/2)*(-0.3)*sqrt(w*w/4/(r*r+1)) (y-h/2)*(-0.3)*sqrt(w*w/4/(r*r+1)) +vcam-ctl filter color cr*(r/400) sin(r/40+t)*127+128 cb*(1-r/400) +``` + +--- + +## Tips + +- The **global amplitude knob** (`filter add mathwarp <amp>`, or + `filter set <index> <amp>` live) scales *all* warp displacement — so you + can build a wild expression and then fade it in from 0, or ride it in + `vcam-tune` while the formula stays fixed. +- Warp is evaluated on a coarse grid and smoothly upsampled (cheap); color + is evaluated per-pixel (a little heavier). Both comfortably hold 720p30. +- Keep displacement roughly under ±40 px or the image tears at the edges — + which is itself a look, if you want it. +- `t` never resets, so slow terms like `t*0.2` drift gently while fast ones + like `t*30` strobe. Mixing timescales in one expression is where the + magic is. diff --git a/INSTALL.md b/INSTALL.md new file mode 100644 index 0000000..cd86133 --- /dev/null +++ b/INSTALL.md @@ -0,0 +1,146 @@ +# Installing vcam + +vcam is a Linux program. It needs a C toolchain, the FFmpeg + libpng +development headers, and the `v4l2loopback` kernel module for its virtual +camera output. Screen-capture overlays additionally use `wf-recorder` on +Wayland. + +- [Dependencies](#dependencies) +- [Build & install](#build--install) +- [One-time device setup (the Chromium fix)](#one-time-device-setup-the-chromium-fix) +- [Verify](#verify) +- [Uninstall](#uninstall) +- [Install-time troubleshooting](#install-time-troubleshooting) + +--- + +## Dependencies + +On Debian / Ubuntu (package names differ on other distros): + +```bash +sudo apt install \ + libv4l-dev libavcodec-dev libavformat-dev libavutil-dev \ + libswscale-dev libavdevice-dev libpng-dev \ + v4l2loopback-dkms pkg-config build-essential \ + wf-recorder slurp ncat +``` + +What each group is for: + +- **libav\* / libpng** — the pipeline links these to decode the webcam's + MJPEG, scale frames, and load PNG/JPEG overlays. +- **v4l2loopback-dkms** — provides the virtual camera device that browsers + and video-call apps read from. +- **wf-recorder, slurp** — Wayland screen capture for the `--screen` + overlay (`slurp` lets you select a region interactively). +- **ncat** — `vcam-ctl` uses it to talk to the running vcam over a Unix + socket. + +Runtime helpers vcam will use if present but that aren't hard build +deps: `swaymsg` (monitor layout), `v4l2-ctl` (device inspection in +`vcam-setup`), `grim`, `xdg-open`. See [NOTICE](NOTICE) for the full list +and their licenses. + +`vcam-ctl` and `vcam-setup` are POSIX `sh`. `vcam-tune` requires **bash** +(it uses single-keypress input that has no POSIX equivalent). + +--- + +## Build & install + +```bash +git clone <repo-url> vcam && cd vcam +make +sudo make install # default → /usr/local/bin +``` + +The build is warning-clean under `-Wall -Wextra -Wpedantic`. `make` +produces two binaries: `vcam` and the `test_screen` diagnostic. + +Choose a different destination if you prefer: + +```bash +make install PREFIX=$HOME/.local # ~/.local/bin (no sudo) +make install PREFIX=/usr # system-wide +make install DESTDIR=/tmp/pkg PREFIX=/usr # staged, for packaging +``` + +`install` also drops LICENSE, NOTICE, README.md, and EXPRESSIONS.md into +`PREFIX/share/doc/vcam`. Make sure your chosen `bin` directory is on +`PATH`. + +--- + +## One-time device setup (the Chromium fix) + +Chromium-family browsers pick the first `/dev/video*` they see. If that's +your real webcam and vcam is already streaming from it, the browser gets +`EBUSY` → `NotReadableError` and the page errors out before you can even +pick a different device. Firefox doesn't have this problem. + +`vcam-setup --install` writes `/etc/modprobe.d/vcam.conf` so the +v4l2loopback module claims `/dev/video0` *before* USB cameras enumerate. +Your real cam then sits at `/dev/video1+`, and the loopback is what +Chromium auto-picks. The `exclusive_caps=1` parameter it sets is also +mandatory for Firefox to see the device. + +```bash +sudo vcam-setup --install +``` + +Then reboot, or do the manual module reload it prints: + +```bash +sudo modprobe -r uvcvideo +sudo modprobe -r v4l2loopback +sudo modprobe v4l2loopback +sudo modprobe uvcvideo +``` + +--- + +## Verify + +```bash +vcam-setup +# → "OK — loopback at /dev/video0 comes before real cam at /dev/video1" + +vcam # start it (defaults: input /dev/video1, output /dev/video0) +ffplay /dev/video0 # in another terminal, watch the output +``` + +In your video-call app, pick **vcam** as the camera. + +Not sure what your webcam supports? Ask it: + +```bash +vcam --list-formats +``` + +--- + +## Uninstall + +```bash +sudo make uninstall # uses the same PREFIX/DESTDIR you installed with +``` + +To also undo the device setup, remove `/etc/modprobe.d/vcam.conf` and +reload the modules (or reboot). + +--- + +## Install-time troubleshooting + +| Symptom | Likely cause | Fix | +|---|---|---| +| `Cannot open /dev/video0` | v4l2loopback not loaded | `sudo vcam-setup --install`, then reboot or manual reload | +| `NotReadableError` in Chromium | Loopback isn't at /dev/video0 | `sudo vcam-setup --install` | +| Firefox shows no camera | v4l2loopback without `exclusive_caps=1` | vcam-setup writes it correctly | +| `vcam-ctl: ncat: command not found` | ncat not installed | `sudo apt install ncat` | +| Screen overlay is black | Compositor doesn't support wlr-screencopy | Use Sway, Hyprland, river, niri, or wayfire | +| `pkg-config: command not found` during build | build tools missing | `sudo apt install pkg-config build-essential` | + +For usage and runtime issues (filters, recording, screen capture), see +the Troubleshooting section in [README.md](README.md). diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d159169 --- /dev/null +++ b/LICENSE @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/Makefile b/Makefile index a72215c..bdbfe45 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0-only +# vcam — Copyright (C) 2026 the vcam authors. GPL-2.0, see LICENSE. CC := gcc CFLAGS := -std=c11 -O2 -Wall -Wextra -Wpedantic \ -D_POSIX_C_SOURCE=200809L \ @@ -16,6 +18,7 @@ LDFLAGS := $(shell pkg-config --libs libavcodec libavformat libavutil libswscale # make install DESTDIR=/tmp/stage (staged install for packaging) PREFIX ?= /usr/local BINDIR ?= $(PREFIX)/bin +DOCDIR ?= $(PREFIX)/share/doc/vcam SRCS := src/main.c src/frame.c src/capture.c src/output.c \ src/overlay.c src/registry.c src/ipc.c src/filter.c \ @@ -44,8 +47,14 @@ install: $(BIN) install -m 755 scripts/vcam-ctl $(DESTDIR)$(BINDIR)/ install -m 755 scripts/vcam-setup $(DESTDIR)$(BINDIR)/ install -m 755 scripts/vcam-tune $(DESTDIR)$(BINDIR)/ + install -d $(DESTDIR)$(DOCDIR) + install -m 644 LICENSE $(DESTDIR)$(DOCDIR)/ + install -m 644 NOTICE $(DESTDIR)$(DOCDIR)/ + install -m 644 README.md $(DESTDIR)$(DOCDIR)/ + install -m 644 INSTALL.md $(DESTDIR)$(DOCDIR)/ + install -m 644 EXPRESSIONS.md $(DESTDIR)$(DOCDIR)/ @echo - @echo "Installed to $(DESTDIR)$(BINDIR)/" + @echo "Installed to $(DESTDIR)$(BINDIR)/ (docs in $(DESTDIR)$(DOCDIR)/)" @echo "Make sure that's on your PATH." uninstall: @@ -53,6 +62,7 @@ uninstall: rm -f $(DESTDIR)$(BINDIR)/vcam-ctl rm -f $(DESTDIR)$(BINDIR)/vcam-setup rm -f $(DESTDIR)$(BINDIR)/vcam-tune + rm -rf $(DESTDIR)$(DOCDIR) clean: rm -f $(OBJS) $(BIN) $(TEST) diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000..f5c581f --- /dev/null +++ b/NOTICE @@ -0,0 +1,70 @@ +vcam — Linux virtual webcam pipeline +Copyright (C) 2026 the vcam authors + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License, version 2, as published +by the Free Software Foundation. See the LICENSE file for the full text. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +more details. + + +Third-party components +====================== + +vcam links against and/or invokes the following components at runtime. Their +licenses are compatible with GPL-2.0; none of them impose additional +restrictions on vcam's own source. + + FFmpeg (libavcodec, libavformat, libavutil, libswscale, libavdevice) + Licensed under the GNU LGPL-2.1-or-later, with some components under + GPL-2.0-or-later depending on the build configuration. FFmpeg is used + here for MJPEG decoding (linked libraries) and, for the optional + recording feature, by invoking the `ffmpeg` binary as a separate + process. https://ffmpeg.org/legal.html + + NOTE ON DISTRIBUTION: if you distribute a build of vcam together with + an FFmpeg that was compiled with --enable-gpl and/or --enable-nonfree + (for example, one including libx264 or libfdk-aac), the combined work + must satisfy the terms of GPL-2.0 for the linked GPL parts, and + --enable-nonfree builds are not redistributable at all. vcam itself is + plain GPL-2.0 and links only the default LGPL FFmpeg libraries; the + recording feature shells out to whatever `ffmpeg` is found on PATH. + + libpng + Licensed under the PNG Reference Library License (permissive, + GPL-compatible). Used for loading PNG image overlays. + http://www.libpng.org/pub/png/src/libpng-LICENSE.txt + + arecord / ALSA (invoked as a separate process for audio capture) + ALSA utilities are licensed under GPL-2.0; libasound under LGPL-2.1. + vcam invokes the `arecord` binary as a child process during + recording. https://www.alsa-project.org + + wf-recorder (invoked as a separate process for screen capture) + Licensed under the MIT license (permissive, GPL-compatible). vcam + spawns `wf-recorder` as a child process to capture a Wayland screen + region for the `--screen` overlay; frames are piped back to vcam. + https://github.com/ammen99/wf-recorder + + Other runtime helpers (invoked as separate processes, not linked) + vcam and its scripts may also call these external programs when + present. None are linked into vcam; each is installed separately and + keeps its own license: + - grim, slurp — MIT (Wayland screenshot / region select) + - swaymsg — MIT (queries monitor layout in vcam-ctl) + - v4l2-ctl — GPL-2.0 (device inspection in vcam-setup) + - ncat — Nmap Public Source License (vcam-ctl's IPC client) + - xdg-open — MIT (opens output files in the diagnostics path) + + v4l2loopback (kernel module, used at runtime, not linked) + The output device is provided by the v4l2loopback kernel module, + licensed GPL-2.0. It is a runtime dependency installed separately and + is not part of vcam's source or binary. + + +The fonts embedded in filter.c (the 8x8 ASCII-art glyph ramp and the VHS +timecode digits) are original bitmap data created for this project and are +covered by vcam's GPL-2.0 license along with the rest of the source. diff --git a/README.md b/README.md index 6a624ea..a10da09 100644 --- a/README.md +++ b/README.md @@ -28,9 +28,9 @@ Zoom — anything that consumes a V4L2 capture device. | Command | What it does | |---|---| | `vcam` | Main process — runs the capture → filter → composite → output pipeline. | -| `vcam-ctl` | Send commands to a running vcam (overlays, filters, screen capture). | -| `vcam-setup` | One-time install of `/etc/modprobe.d/vcam.conf` for browser compatibility. | -| `vcam-tune` | Interactively dial filter parameters with arrow keys. | +| `vcam-ctl` | Send commands to a running vcam (overlays, filters, screen capture). POSIX `sh`. | +| `vcam-setup` | One-time install of `/etc/modprobe.d/vcam.conf` for browser compatibility. POSIX `sh`. | +| `vcam-tune` | Interactively dial filter parameters with arrow keys. Requires `bash` (single-keypress input). | Every tool has `--help`. Run any of them with no arguments or `-h` for full usage. @@ -38,8 +38,11 @@ Every tool has `--help`. Run any of them with no arguments or `-h` for full usag ## Quick start +Full details — dependencies, build options, the one-time device setup — +are in **[INSTALL.md](INSTALL.md)**. The short version: + ```bash -# 1. Dependencies (Debian / Ubuntu — package names differ on other distros) +# 1. Dependencies (Debian / Ubuntu) sudo apt install \ libv4l-dev libavcodec-dev libavformat-dev libavutil-dev \ libswscale-dev libavdevice-dev libpng-dev \ @@ -47,53 +50,20 @@ sudo apt install \ wf-recorder slurp ncat # 2. Build & install -git clone <repo-url> vcam && cd vcam -make -make -sudo make install # default → /usr/local/bin -# or pick your own destination: -# make install PREFIX=$HOME/.local # ~/.local/bin (no sudo) -# make install PREFIX=/usr # system-wide -# make install DESTDIR=/tmp/pkg PREFIX=/usr # staged for packaging -# Uninstall: -# sudo make uninstall # uses the same PREFIX/DESTDIR +make && sudo make install # 3. ONE-TIME: make v4l2loopback land at /dev/video0 (Chromium needs this) -sudo vcam-setup --install - -# Then reboot, or do the manual module reload it prints: -sudo modprobe -r uvcvideo -sudo modprobe -r v4l2loopback -sudo modprobe v4l2loopback -sudo modprobe uvcvideo - -# 4. Verify -vcam-setup -# → "OK — loopback at /dev/video0 comes before real cam at /dev/video1" +sudo vcam-setup --install # then reboot, or reload modules as it prints -# 5. Start it (defaults: input /dev/video1, output /dev/video0) +# 4. Run it, and test the output vcam - -# 6. Test the output ffplay /dev/video0 ``` -In your video-call app, pick "vcam" as the camera. - ---- - -## Why two device numbers? (the Chromium fix) - -Chromium-family browsers pick the first `/dev/video*` they see. If that's -your real webcam and vcam is already streaming from it, the browser gets -`EBUSY` → `NotReadableError` and the page errors out before the user can -even pick a different device. Firefox doesn't have this problem. - -`vcam-setup --install` writes `/etc/modprobe.d/vcam.conf` so the -v4l2loopback module claims `/dev/video0` *before* USB cameras enumerate. -Your real cam then sits at `/dev/video1+` and the loopback is what -Chromium auto-picks. The `exclusive_caps=1` parameter it sets is also -mandatory for Firefox. +In your video-call app, pick **vcam** as the camera. If the browser can't +see it, that's almost always the device-number issue — +[INSTALL.md](INSTALL.md#one-time-device-setup-the-chromium-fix) explains +why and how `vcam-setup` fixes it. --- @@ -105,11 +75,11 @@ vcam [OPTIONS] Pipeline: -i <device> Input webcam (default /dev/video1) -o <device> Output loopback (default /dev/video0) - -W <px> Output width (default: camera native) - -H <px> Output height (default: camera native) + --res WxH Output resolution (e.g. --res 1280x720; default: camera native) -f <fps> Frame rate + --list-formats List the resolutions the input device supports, then exit --no-input Skip the webcam (screen overlay becomes the source). - Requires -W and -H. + Combine with --res. Startup overlays: --img <id> <x> <y> [<w> [<h>]] <file> PNG or JPEG @@ -121,18 +91,25 @@ Startup filters (chain order = listed order): --filter <name> [<param>] ``` -If you pass only `<w>`, height is computed from the source aspect ratio; -same for `<h>` alone (use `0 <h>` to skip width). +Not sure what your camera supports? Ask it: + +```bash +vcam --list-formats # prints every format / resolution / fps it offers +``` + +If you pass only `<w>` to an overlay, height is computed from the source +aspect ratio; same for `<h>` alone (use `0 <h>` to skip width). ### Examples ```bash vcam # plain forward -vcam -W 1280 -H 720 -f 30 # force 720p30 +vcam --list-formats # what can my camera do? +vcam --res 1280x720 -f 30 # force 720p30 vcam --img logo 1100 10 160 /assets/logo.png # top-right logo vcam --vid intro 50 50 320 180 /clips/intro.mp4 vcam --filter modern 0.8 --filter vignette 0.6 # cinematic -vcam --no-input -W 1920 -H 1080 \ +vcam --no-input --res 1920x1080 \ --screen scr 0 0 1920 1080 1920x1080+0+0 # pure screencast ``` @@ -430,41 +407,29 @@ blend), plus `emboss dither tiles zoompulse oilslick`. | `symmetry` | mode | face-symmetry mirrors — 0 left→right, 1 right→left, 2 quad kaleidoscope | | `timebubble` | delay, radius | a glowing bubble drifts around; inside it you see seconds into the past | -### mathwarp — warp the image with your own formulas +### mathwarp — warp *and recolor* the image with your own formulas + +`mathwarp` has two independent expression sets. **Warp** moves pixels; +**color** repaints them. Use either or both. ```bash vcam-ctl filter add mathwarp 1.0 -# toom in out stepped + +# WARP: displace each pixel by (dx, dy) vcam-ctl filter expr '(x-w/2)*(sin(t*5)>0?0.08:0)' '(y-h/2)*(sin(t*5)>0?0.08:0)' -# squares mash animated -vcam-ctl filter expr '(floor(x/40)%2==floor(y/40)%2?1:-1)*sin(t*3)*25' '(floor(x/40)%2==floor(y/40)%2?-1:1)*cos(t*2.5)*25' -vcam-ctl filter expr '(x-w/2)*((floor(x/40)+floor(y/40))%2==0?(1+sin(t*0.3)*0.3):(1-sin(t*0.3)*0.3))-x+w/2' '(y-h/2)*((floor(x/40)+floor(y/40))%2==0?(1+sin(t*0.3)*0.3):(1-sin(t*0.3)*0.3))-y+h/2' - -# waves circle -vcam-ctl filter expr '(x-w/2)*(sin(r*0.2-t*5)*0.08)' '(y-h/2)*(sin(r*0.2-t*5)*0.08)' -# bubble -vcam-ctl filter expr '(sqrt((x-(w/2+sin(t*0.7)*w*0.35))*(x-(w/2+sin(t*0.7)*w*0.35))+(y-(h/2+cos(t*0.9)*h*0.35))*(y-(h/2+cos(t*0.9)*h*0.35)))<50)?(x-(w/2+sin(t*0.7)*w*0.35))*0.4:0' '(sqrt((x-(w/2+sin(t*0.7)*w*0.35))*(x-(w/2+sin(t*0.7)*w*0.35))+(y-(h/2+cos(t*0.9)*h*0.35))*(y-(h/2+cos(t*0.9)*h*0.35)))<50)?(y-(h/2+cos(t*0.9)*h*0.35))*0.4:0' -vcam-ctl filter expr '(x-w/2)*(1/(r*0.03+1)) - (y-h/2)*(1/(r*0.01+0.5))*2*sin(t)' '(y-h/2)*(1/(r*0.03+1)) + (x-w/2)*(1/(r*0.01+0.5))*2*cos(t)' - -# gltichbar -vcam-ctl filter expr '(floor(y/5)%2==0?sin(t*20)*5:0)+(abs(y-h/2-sin(t*1.2)*h*0.4)<10?80:0)' '(floor(x/5)%2==0?cos(t*20)*5:0)+(abs(x-w/2-cos(t*1.2)*w*0.4)<10?80:0)' -# pulsate -vcam-ctl filter expr '(x-w/2)*(abs(sin(t*3))*0.15)' '(y-h/2)*(abs(sin(t*3))*0.15)' -# slight drunk -vcam-ctl filter expr 'sin(sqrt((x-w/2)*(x-w/2)+(y-h/2)*(y-h/2))*0.05-t*3)*2+sin(sqrt((x-(w/2+sin(t)*200))*(x-(w/2+sin(t)*200))+(y-(h/2+cos(t)*200))*(y-(h/2+cos(t)*200)))*0.05+t*3)*2' 'cos(sqrt((x-w/2)*(x-w/2)+(y-h/2)*(y-h/2))*0.05-t*3)*2+cos(sqrt((x-(w/2+sin(t)*200))*(x-(w/2+sin(t)*200))+(y-(h/2+cos(t)*200))*(y-(h/2+cos(t)*200)))*0.05+t*3)*2' -vcam-ctl filter expr '(sin(a+t*2)*cos(a*2+t*1.7)+cos(a*3-t))*r*0.02' '(cos(a+t*2)*sin(a*2+t*1.7)+sin(a*3-t))*r*0.02' -vcam-ctl filter expr 'abs((x-w/2)*cos(t*0.5)-(y-h/2)*sin(t*0.5))*0.3' 'abs((x-w/2)*sin(t*0.5)+(y-h/2)*cos(t*0.5))*0.3' -# good for kalaidoscope -vcam-ctl filter expr '(sin(t)>0.1 ? (x-w/2)*abs(sin(t))*0.2 : (x-w/2)*(-abs(sin(t))*0.5) ) + (sin(t)<-0.1? (w-x) : 0)' '(sin(t)>0.1 ? (y-h/2)*abs(sin(t))*0.2 : (y-h/2)*(-abs(sin(t))*0.5) ) + (sin(t)<-0.1? (h-y) : 0)' + +# COLOR: repaint each pixel; r/g/b return 0..255 +vcam-ctl filter color 'cg' 'cb' 'cr' # rotate the RGB channels +vcam-ctl filter color off # back to normal colors ``` -Each pixel is displaced by `(dx, dy)` computed from your two -expressions (no spaces inside an expression). Compiled on the fly by -a built-in parser, evaluated on a coarse grid + bilinear upsampling — -comfortably 720p30. +Both are compiled on the fly by a built-in parser. Warp is evaluated on +a coarse grid + bilinear upsampling; color is evaluated per pixel — both +comfortably hold 720p30. -* Variables: `x y` (pixel), `w h` (frame size), `t` (seconds), +* Variables (everywhere): `x y` (pixel), `w h` (frame size), `t` (seconds), `r a` (radius / angle from center) +* Color expressions also get `cr cg cb` — this pixel's source R/G/B (0–255) * Functions: `sin cos abs sqrt floor` * Operators: `+ - * / %`, comparisons `> < >= <= == !=`, ternary `cond ? a : b`, parentheses, unary minus @@ -472,10 +437,16 @@ comfortably 720p30. ```bash # brick-shatter: alternating 40px bands slide opposite ways vcam-ctl filter expr '(floor(y/40)%2==0?1:-1)*sin(t*3)*15' '0' -# radial shockwaves -vcam-ctl filter expr 'sin(r/15-t*4)*10' 'cos(r/15-t*4)*10' +# photographic negative +vcam-ctl filter color '255-cr' '255-cg' '255-cb' +# a spectrum that scrolls across the frame forever +vcam-ctl filter color 'sin(x/40+t)*127+128' 'sin(x/40+t+2)*127+128' 'sin(x/40+t+4)*127+128' ``` +**→ See [EXPRESSIONS.md](EXPRESSIONS.md) for a full cookbook** — black +holes, tornados, thermal maps, psychedelic wormholes, and dozens more +verified recipes for warp, color, and the two combined. + The `mathwarp` primary parameter is a global amplitude multiplier, so you can fade your formula in and out live from `vcam-tune`. @@ -726,16 +697,32 @@ times out, your compositor probably doesn't support `wlr-screencopy` ## Troubleshooting +Installation and device-setup problems (loopback not found, browser can't +see the camera, missing build tools) are covered in +**[INSTALL.md](INSTALL.md#install-time-troubleshooting)**. Runtime issues: + | Symptom | Likely cause | Fix | |---|---|---| -| `Cannot open /dev/video0` | v4l2loopback not loaded | `sudo vcam-setup --install`, then reboot or manual reload | -| `NotReadableError` in Chromium | Loopback isn't at /dev/video0 | `sudo vcam-setup --install` | -| Firefox shows no camera | v4l2loopback without `exclusive_caps=1` | vcam-setup writes it correctly | | Screen overlay is black | (was) wf-recorder hung on Overwrite prompt | rebuild — pre-loaded `y\n` is in stdin now | | Screen overlay still black | Compositor doesn't support wlr-screencopy | Use Sway, Hyprland, river, niri, wayfire | | Screen image scrolls diagonally | (was) stride misalignment | rebuild — dims snap to 16/2 now | | Video overlay is a green block | (was) pre-decode `pix_fmt` was NONE | rebuild — sws is lazy now | | Video plays jerky/jumps back | (was) spin limit too tight | rebuild — limit raised, `vid_eof_sent` flag added | -| `vcam-ctl: ncat: command not found` | ncat not installed | `sudo apt install ncat` | | `shell-init: getcwd error retrieving current directory` | Your *shell* sits in a deleted directory — **not a vcam bug** | `cd ~` in that terminal | | High CPU at 1080p | `blur` / `painterly` / `voronoi` are O(W·H·r²) | smaller param, drop to 720p, or pick cheaper filters | + +--- + +## License + +vcam is free software under the **GNU General Public License, version 2** +(GPL-2.0-only). See [LICENSE](LICENSE) for the full text and [NOTICE](NOTICE) +for third-party components. + +The dependencies are all GPL-2.0-compatible: FFmpeg (LGPL-2.1+, some parts +GPL), libpng (permissive), and the ALSA/v4l2loopback runtime tools. One +caveat worth knowing if you *redistribute builds*: if you bundle an FFmpeg +compiled with `--enable-nonfree` (e.g. with `libfdk-aac`), that combined +binary is not redistributable. vcam itself links only the standard LGPL +FFmpeg libraries and shells out to whatever `ffmpeg` is on your PATH for +recording, so this only matters if you package FFmpeg together with vcam. diff --git a/include/vcam.h b/include/vcam.h index cdd1608..14a74d7 100644 --- a/include/vcam.h +++ b/include/vcam.h @@ -1,3 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0-only + * vcam — Linux virtual webcam pipeline + * Copyright (C) 2026 the vcam authors + * + * This program is free software under the terms of the GNU General + * Public License version 2. See the LICENSE file for the full text. + */ + #pragma once #include <stdint.h> @@ -239,6 +247,14 @@ void filter_chain_apply (FilterChain *fc, Frame *f); /* takes lock */ bool mathwarp_set_expr(const char *dx_expr, const char *dy_expr, char *err, size_t errlen); +/* Recolor expressions for FX_MATHWARP. Each returns a channel value + * (0..255) and may read the warped source color via cr/cg/cb, plus + * all the usual vars (x y w h t r a). Once set, mathwarp recolors + * every pixel until mathwarp_clear_color() is called. */ +bool mathwarp_set_color(const char *r_expr, const char *g_expr, + const char *b_expr, char *err, size_t errlen); +void mathwarp_clear_color(void); + FilterType filter_type_from_name(const char *name); const char *filter_type_to_name (FilterType t); float filter_default_param (FilterType t); @@ -305,6 +321,10 @@ V4L2Capture *capture_open (const char *dev, int *w, int *h, int *fps); bool capture_read (V4L2Capture *cap, Frame *out); void capture_close(V4L2Capture *cap); +/* Enumerate and print every usable (format, resolution, fps) the + * device supports. Returns false if the device can't be opened. */ +bool capture_list_formats(const char *dev); + /* ────────────────────────────────────────────── * V4L2 loopback output * ────────────────────────────────────────────── */ diff --git a/scripts/vcam-ctl b/scripts/vcam-ctl index 2460190..04dbc6b 100755 --- a/scripts/vcam-ctl +++ b/scripts/vcam-ctl @@ -1,4 +1,6 @@ -#!/usr/bin/env bash +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-only +# vcam — Copyright (C) 2026 the vcam authors. GPL-2.0, see LICENSE. # # vcam-ctl – complete runtime control for a running vcam process. # @@ -100,14 +102,14 @@ SOCK="${VCAM_SOCK:-/tmp/vcam.sock}" show_help() { sed -n '/^# vcam-ctl/,/^$/p' "$0" | sed 's/^# \?//'; } # ── basic usage / help ─────────────────────────────────────── -if [[ $# -eq 0 || "$1" == "-h" || "$1" == "--help" ]]; then +if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then show_help exit 0 fi # ── check vcam is alive ────────────────────────────────────── require_running() { - if [[ ! -S "$SOCK" ]]; then + if [ ! -S "$SOCK" ]; then echo "Error: vcam is not running (socket $SOCK not found)" >&2 exit 1 fi @@ -145,14 +147,14 @@ detect_monitors() { fi # Bare-metal fallback: /sys/class/drm — only gives resolution. for status_file in /sys/class/drm/card*/status; do - [[ -r "$status_file" ]] || continue - [[ "$status_file" =~ /card[0-9]+-[^/]+/status$ ]] || continue - if [[ "$(cat "$status_file")" == "connected" ]]; then + [ -r "$status_file" ] || continue + echo "$status_file" | grep -qE '/card[0-9]+-[^/]+/status$' || continue + if [ "$(cat "$status_file")" = "connected" ]; then local dir="${status_file%/status}" local name mode name=$(basename "$dir" | sed 's/^card[0-9]*-//') mode=$(head -1 "$dir/modes" 2>/dev/null) - if [[ -n "$mode" && "$mode" =~ ^[0-9]+x[0-9]+$ ]]; then + if [ -n "$mode" ] && echo "$mode" | grep -qE '^[0-9]+x[0-9]+$'; then echo "$name $mode 0 0" fi fi @@ -166,14 +168,14 @@ resolve_monitor() { local selector="$1" local lines lines=$(detect_monitors) - [[ -z "$lines" ]] && { return 1; } + [ -z "$lines" ] && { return 1; } local count count=$(echo "$lines" | wc -l) # Specific selector - if [[ -n "$selector" ]]; then - if [[ "$selector" =~ ^[0-9]+$ ]]; then + if [ -n "$selector" ]; then + if echo "$selector" | grep -qE '^[0-9]+$'; then echo "$lines" | sed -n "${selector}p" else echo "$lines" | awk -v n="$selector" '$1 == n { print; exit }' @@ -182,7 +184,7 @@ resolve_monitor() { fi # Single monitor: just use it - if [[ $count -eq 1 ]]; then + if [ $count -eq 1 ]; then echo "$lines" return 0 fi @@ -190,7 +192,7 @@ resolve_monitor() { # Multiple monitors: interactive prompt # Only require stdin to be a TTY — stdout is captured by $(...) so # -t 1 would always fail when called via command substitution. - if [[ ! -t 0 ]]; then + if [ ! -t 0 ]; then echo "$lines" | head -1 return 0 fi @@ -199,14 +201,19 @@ resolve_monitor() { local i=0 while IFS= read -r line; do i=$((i+1)) - read -r name mode x y <<< "$line" + name=$(echo "$line" | awk '{print $1}') + mode=$(echo "$line" | awk '{print $2}') + x=$(echo "$line" | awk '{print $3}') + y=$(echo "$line" | awk '{print $4}') printf " %d) %-12s %s at (%d,%d)\n" "$i" "$name" "$mode" "$x" "$y" >&2 - done <<< "$lines" + done <<EOF +$lines +EOF printf "Select monitor (1-%d, default 1): " "$count" >&2 local choice read -r choice - [[ -z "$choice" ]] && choice=1 - if ! [[ "$choice" =~ ^[0-9]+$ ]] || (( choice < 1 || choice > count )); then + [ -z "$choice" ] && choice=1 + if ! echo "$choice" | grep -qE '^[0-9]+$' || [ "$choice" -lt 1 ] || [ "$choice" -gt "$count" ]; then echo "Invalid selection" >&2; return 1 fi echo "$lines" | sed -n "${choice}p" @@ -215,7 +222,7 @@ resolve_monitor() { # ────────────────────────────────────────────────────────────── # screen subcommand — fully merged from old vcam-screen # ────────────────────────────────────────────────────────────── -if [[ "$1" == "screen" ]]; then +if [ "$1" = "screen" ]; then shift require_running @@ -226,7 +233,7 @@ if [[ "$1" == "screen" ]]; then MONITOR="" ACTION="add" # add | list | remove | remove-all | monitors - while [[ $# -gt 0 ]]; do + while [ $# -gt 0 ]; do case "$1" in --help) show_help; exit 0 ;; -i) ID="$2"; shift 2 ;; @@ -241,7 +248,7 @@ if [[ "$1" == "screen" ]]; then --list) ACTION="list"; shift ;; --remove) ACTION="remove" - if [[ $# -ge 2 && "$2" != -* ]]; then ID="$2"; shift 2 + if [ $# -ge 2 ] && [ "$2" != -* ]; then ID="$2"; shift 2 else ID="screen"; shift; fi ;; --remove-all) ACTION="remove-all"; shift ;; *) echo "Unknown screen option: $1 (try --help)" >&2; exit 1 ;; @@ -249,39 +256,44 @@ if [[ "$1" == "screen" ]]; then done # ── list / remove / monitors paths ── - if [[ "$ACTION" == "monitors" ]]; then + if [ "$ACTION" = "monitors" ]; then lines=$(detect_monitors) - if [[ -z "$lines" ]]; then + if [ -z "$lines" ]; then echo "No monitors detected." >&2; exit 1 fi i=0 while IFS= read -r line; do i=$((i+1)) - read -r name mode x y <<< "$line" + name=$(echo "$line" | awk '{print $1}') + mode=$(echo "$line" | awk '{print $2}') + x=$(echo "$line" | awk '{print $3}') + y=$(echo "$line" | awk '{print $4}') printf " %d) %-12s %s at (%d,%d)\n" "$i" "$name" "$mode" "$x" "$y" - done <<< "$lines" + done <<EOF +$lines +EOF exit 0 fi - if [[ "$ACTION" == "list" ]]; then + if [ "$ACTION" = "list" ]; then ipc_send list | grep '\[screen\]' || echo "no screen overlays" exit 0 fi - if [[ "$ACTION" == "remove" ]]; then + if [ "$ACTION" = "remove" ]; then ipc_send "remove $ID" exit 0 fi - if [[ "$ACTION" == "remove-all" ]]; then + if [ "$ACTION" = "remove-all" ]; then ipc_send list | grep -oE '\[screen\] id=[^ ]+' | \ awk -F= '{print $2}' | while read -r oid; do - [[ -n "$oid" ]] && { echo "removing $oid"; ipc_send "remove $oid"; } + [ -n "$oid" ] && { echo "removing $oid"; ipc_send "remove $oid"; } done exit 0 fi # ── add path ── # Auto-pick a free ID if user didn't provide one - if [[ -z "$ID" ]]; then + if [ -z "$ID" ]; then EXISTING=$(ipc_send list 2>/dev/null | grep -oE 'id=[^ ]+' | awk -F= '{print $2}') if ! echo "$EXISTING" | grep -qx "screen"; then ID="screen" @@ -293,27 +305,28 @@ if [[ "$1" == "screen" ]]; then fi # Detect display server - if [[ -n "${WAYLAND_DISPLAY:-}" ]]; then DS="wayland" - elif [[ -n "${DISPLAY:-}" ]]; then DS="x11" + if [ -n "${WAYLAND_DISPLAY:-}" ]; then DS="wayland" + elif [ -n "${DISPLAY:-}" ]; then DS="x11" else echo "Error: neither WAYLAND_DISPLAY nor DISPLAY is set" >&2; exit 1 fi # Obtain geometry GEOMETRY="" - if [[ $FULL -eq 1 ]]; then + if [ $FULL -eq 1 ]; then SEL=$(resolve_monitor "$MONITOR") - if [[ -z "$SEL" ]]; then + if [ -z "$SEL" ]; then echo "Could not resolve monitor selection." >&2 echo "Run 'vcam-ctl screen --monitors' to list connected monitors." >&2 exit 1 fi - read -r MNAME MMODE MX MY <<< "$SEL" + set -- $SEL + MNAME="$1" MMODE="$2" MX="$3" MY="$4" GEOMETRY="${MMODE}+${MX}+${MY}" echo "Full screen on $MNAME: $GEOMETRY" else echo "Select a screen region..." >&2 - if [[ "$DS" == "wayland" ]]; then + if [ "$DS" = "wayland" ]; then command -v slurp >/dev/null || { echo "slurp not installed" >&2; exit 1; } SLURP_RAW=$(slurp 2>/dev/null) || { echo "Cancelled." >&2; exit 1; } SX=$(echo "$SLURP_RAW" | cut -d',' -f1) @@ -332,15 +345,15 @@ if [[ "$1" == "screen" ]]; then echo "Selected: $GEOMETRY" >&2 fi - if [[ $REPLACE -eq 1 ]]; then + if [ $REPLACE -eq 1 ]; then echo "Removing existing overlay '$ID'..." >&2 ipc_send "remove $ID" >/dev/null || true fi ARGS="add screen $ID $DST_X $DST_Y" - if [[ $DST_W -gt 0 && $DST_H -gt 0 ]]; then ARGS="$ARGS $DST_W $DST_H" - elif [[ $DST_W -gt 0 ]]; then ARGS="$ARGS $DST_W" - elif [[ $DST_H -gt 0 ]]; then ARGS="$ARGS 0 $DST_H" + if [ $DST_W -gt 0 ] && [ $DST_H -gt 0 ]; then ARGS="$ARGS $DST_W $DST_H" + elif [ $DST_W -gt 0 ]; then ARGS="$ARGS $DST_W" + elif [ $DST_H -gt 0 ]; then ARGS="$ARGS 0 $DST_H" fi ARGS="$ARGS $GEOMETRY" @@ -378,12 +391,12 @@ fi # # Default ID is "cam". To run multiple webcam overlays, add them with # the lower-level: vcam-ctl add webcam myid <x> <y> [<w>] <device> -if [[ "$1" == "webcam" ]]; then +if [ "$1" = "webcam" ]; then shift require_running POS="${1:-tr}"; WIDTH="${2:-320}"; ID="${3:-cam}" - if [[ "$POS" == "off" || "$POS" == "remove" ]]; then + if [ "$POS" = "off" ] || [ "$POS" = "remove" ]; then ipc_send "remove $ID" exit 0 fi @@ -395,7 +408,7 @@ if [[ "$1" == "webcam" ]]; then OUT_SIZE=$(v4l2-ctl -d "$OUT" --get-fmt-video 2>/dev/null \ | awk -F'/' '/Width\/Height/{print $2}' | tr -d ' ') fi - [[ "$OUT_SIZE" =~ ^[0-9]+x[0-9]+$ ]] || OUT_SIZE="1280x720" + echo "$OUT_SIZE" | grep -qE '^[0-9]+x[0-9]+$' || OUT_SIZE="1280x720" OUT_W="${OUT_SIZE%x*}"; OUT_H="${OUT_SIZE#*x}" # Webcam is 16:9 (height computed from width) @@ -450,9 +463,9 @@ REC_INFO="/tmp/vcam-record.info" REC_LOG="/tmp/vcam-record.log" rec_is_active() { - [[ -f "$REC_PID" ]] || return 1 + [ -f "$REC_PID" ] || return 1 local pid; pid=$(cat "$REC_PID" 2>/dev/null) || return 1 - [[ -z "$pid" ]] && return 1 + [ -z "$pid" ] && return 1 kill -0 "$pid" 2>/dev/null } @@ -470,16 +483,16 @@ rec_list_mics() { local sources sources=$(pactl list sources short 2>/dev/null \ | awk '{print $2}' | grep -v '\.monitor$' || true) - if [[ -n "$sources" ]]; then + if [ -n "$sources" ]; then have_any=1 echo "PipeWire/PulseAudio sources (RECOMMENDED — robust buffering):" echo "" printf " %-18s %s\n" "--mic" "source" printf " %-18s %s\n" "------------------" "---------------------------------" printf " %-18s %s\n" "pulse" "(default source)" - while IFS= read -r src; do + printf '%s\n' "$sources" | while IFS= read -r src; do printf " %-18s %s\n" "pulse:$src" "$src" - done <<<"$sources" + done echo "" fi fi @@ -488,24 +501,23 @@ rec_list_mics() { if command -v arecord >/dev/null 2>&1; then local lines lines=$(arecord -l 2>/dev/null | grep -E '^card [0-9]+' || true) - if [[ -n "$lines" ]]; then + if [ -n "$lines" ]; then have_any=1 echo "Raw ALSA capture devices:" echo "" printf " %-18s %s\n" "--mic" "device" printf " %-18s %s\n" "------------------" "---------------------------------" - while IFS= read -r line; do - local card dev name + printf '%s\n' "$lines" | while IFS= read -r line; do card=$(echo "$line" | sed -E 's/^card ([0-9]+):.*/\1/') dev=$(echo "$line" | sed -E 's/.*device ([0-9]+):.*/\1/') name=$(echo "$line" | sed -E 's/.*\[([^]]*)\][[:space:]]*$/\1/') printf " %-18s %s\n" "plughw:${card},${dev}" "$name (card $card, device $dev)" - done <<<"$lines" + done echo "" fi fi - if [[ $have_any -eq 0 ]]; then + if [ $have_any -eq 0 ]; then echo "No capture devices found." return 1 fi @@ -522,11 +534,11 @@ rec_list_mics() { rec_default_output() { local dir="${XDG_VIDEOS_DIR:-$HOME/Videos}" - [[ -d "$dir" ]] || dir="$HOME" + [ -d "$dir" ] || dir="$HOME" echo "$dir/vcam-$(date +%Y-%m-%d_%H-%M-%S).mkv" } -if [[ "$1" == "record" ]]; then +if [ "$1" = "record" ]; then shift ACTION="${1:-help}" shift || true @@ -538,7 +550,7 @@ if [[ "$1" == "record" ]]; then if rec_is_active; then echo "Already recording (pid $(cat $REC_PID))." >&2 echo "Use 'vcam-ctl record stop' first, or pass --replace." >&2 - if [[ " $* " != *" --replace "* && " $* " != *" -r "* ]]; then + if [ " $* " != *" --replace "* ] && [ " $* " != *" -r "* ]; then exit 1 fi ipc_send "record stop" >/dev/null 2>&1 || true @@ -549,7 +561,7 @@ if [[ "$1" == "record" ]]; then OUT=""; MIC=""; NO_AUDIO=0; CRF=23 VCODEC="libx264"; VPRESET="ultrafast"; AOFFSET="0.2" - while [[ $# -gt 0 ]]; do + while [ $# -gt 0 ]; do case "$1" in -o|--output) OUT="$2"; shift 2 ;; -m|--mic) MIC="$2"; shift 2 ;; @@ -574,7 +586,7 @@ if [[ "$1" == "record" ]]; then # ffmpeg's direct ALSA reads. # 2. ALSA "default" # 3. First hardware capture device as plughw:N,M - if [[ $NO_AUDIO -eq 0 && -z "$MIC" ]]; then + if [ $NO_AUDIO -eq 0 ] && [ -z "$MIC" ]; then if command -v pactl >/dev/null 2>&1 && pactl info >/dev/null 2>&1; then MIC="pulse" elif arecord -L 2>/dev/null | grep -q '^default$'; then @@ -584,11 +596,11 @@ if [[ "$1" == "record" ]]; then | grep -E '^card [0-9]+' \ | head -1 \ | sed -E 's/^card ([0-9]+).* device ([0-9]+).*/plughw:\1,\2/') - if [[ -n "$FIRST_HW" && "$FIRST_HW" =~ ^plughw: ]]; then + if [ -n "$FIRST_HW" ] && echo "$FIRST_HW" | grep -qE '^plughw:'; then MIC="$FIRST_HW" fi fi - if [[ -n "$MIC" ]]; then + if [ -n "$MIC" ]; then echo "[record] auto-selected mic: $MIC" \ "(override with --mic, or skip with --no-audio)" else @@ -596,7 +608,7 @@ if [[ "$1" == "record" ]]; then fi fi # Normalize plain "N,M" → "plughw:N,M" - if [[ -n "$MIC" && "$MIC" =~ ^[0-9]+,[0-9]+$ ]]; then + if [ -n "$MIC" ] && echo "$MIC" | grep -qE '^[0-9]+,[0-9]+$'; then MIC="plughw:$MIC" echo "[record] interpreting mic as $MIC" fi @@ -608,14 +620,14 @@ if [[ "$1" == "record" ]]; then # consumers regardless of who attached first. require_running REQ="record start file=$OUT crf=$CRF vcodec=$VCODEC preset=$VPRESET aoffset=$AOFFSET" - if [[ $NO_AUDIO -eq 0 && -n "$MIC" ]]; then + if [ $NO_AUDIO -eq 0 ] && [ -n "$MIC" ]; then REQ="$REQ mic=$MIC" fi RESP=$(ipc_send "$REQ") if ! echo "$RESP" | grep -qE '^OK recording'; then echo "Failed to start recording. Response from vcam:" >&2 echo "$RESP" >&2 - if [[ -s /tmp/vcam-record.log ]]; then + if [ -s /tmp/vcam-record.log ]; then echo "" >&2 echo "ffmpeg log (last 20 lines, full at /tmp/vcam-record.log):" >&2 tail -n 20 /tmp/vcam-record.log >&2 @@ -639,7 +651,7 @@ if [[ "$1" == "record" ]]; then if echo "$CHECK" | grep -q "recording"; then break # alive and well fi - if [[ $ATTEMPT -eq 1 ]] && grep -q "audio device.*busy\|Device or resource busy" /tmp/vcam-record.log 2>/dev/null; then + if [ $ATTEMPT -eq 1 ] && grep -q "audio device.*busy\|Device or resource busy" /tmp/vcam-record.log 2>/dev/null; then echo "[record] mic still held by the previous recording — retrying in 2s..." sleep 2 ATTEMPT=2 @@ -649,7 +661,7 @@ if [[ "$1" == "record" ]]; then fi fi echo "✗ ffmpeg exited immediately after start." >&2 - if [[ -s /tmp/vcam-record.log ]]; then + if [ -s /tmp/vcam-record.log ]; then echo "" >&2 echo "ffmpeg log (last 20 lines, full at /tmp/vcam-record.log):" >&2 tail -n 20 /tmp/vcam-record.log >&2 @@ -676,7 +688,7 @@ if [[ "$1" == "record" ]]; then echo "● Recording started" echo " file: $OUT" echo " pid: ${PID:-?} (ffmpeg, child of vcam)" - [[ -n "$MIC" ]] && echo " mic: $MIC" + [ -n "$MIC" ] && echo " mic: $MIC" echo " transport: pipe (vcam → ffmpeg stdin, no /dev/video0 read)" ;; @@ -685,24 +697,24 @@ if [[ "$1" == "record" ]]; then # Ask vcam to close its end of the pipe; ffmpeg finalises # the file in the background. require_running 2>/dev/null && ipc_send "record stop" >/dev/null 2>&1 || true - if [[ -f "$REC_INFO" ]]; then + if [ -f "$REC_INFO" ]; then OUT=$(grep '^file=' "$REC_INFO" 2>/dev/null | cut -d= -f2-) fi rm -f "$REC_PID" "$REC_STATUS" "$REC_INFO" echo "■ Recording stopped" - if [[ -n "${OUT:-}" ]]; then + if [ -n "${OUT:-}" ]; then # Give ffmpeg a moment to finish the container, then # verify the file actually exists. If it doesn't, the # recording failed at some point — surface the log. for _ in 1 2 3 4 5 6 7 8 9 10; do - [[ -s "$OUT" ]] && break + [ -s "$OUT" ] && break sleep 0.2 done - if [[ -s "$OUT" ]]; then + if [ -s "$OUT" ]; then echo " saved: $OUT" else echo " ✗ expected output $OUT was not created!" >&2 - if [[ -s /tmp/vcam-record.log ]]; then + if [ -s /tmp/vcam-record.log ]; then echo "" >&2 echo "ffmpeg log (last 20 lines, full at /tmp/vcam-record.log):" >&2 tail -n 20 /tmp/vcam-record.log >&2 @@ -753,11 +765,11 @@ if [[ "$1" == "record" ]]; then fi echo "state=$(cat $REC_STATUS 2>/dev/null || echo recording)" echo "pid=$(cat $REC_PID)" - [[ -f "$REC_INFO" ]] && cat "$REC_INFO" + [ -f "$REC_INFO" ] && cat "$REC_INFO" # Duration on the fly - if [[ -f "$REC_INFO" ]]; then + if [ -f "$REC_INFO" ]; then START=$(grep '^started=' "$REC_INFO" | cut -d= -f2) - if [[ -n "$START" ]]; then + if [ -n "$START" ]; then NOW=$(date +%s) DUR=$((NOW - START)) printf "duration=%02d:%02d:%02d\n" \ @@ -779,7 +791,7 @@ if [[ "$1" == "record" ]]; then NOW=$(date +%s) DUR=$((NOW - ${START:-NOW})) LBL=$(printf "%02d:%02d:%02d" $((DUR/3600)) $(((DUR%3600)/60)) $((DUR%60))) - if [[ "$STATE" == "paused" ]]; then + if [ "$STATE" = "paused" ]; then printf '{"text":"⏸ REC %s","class":"paused","color":"#ffaa00"}\n' "$LBL" else printf '{"text":"● REC %s","class":"recording","color":"#ff5555"}\n' "$LBL" diff --git a/scripts/vcam-setup b/scripts/vcam-setup index db32a11..9a54782 100755 --- a/scripts/vcam-setup +++ b/scripts/vcam-setup @@ -1,4 +1,6 @@ -#!/usr/bin/env bash +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-only +# vcam — Copyright (C) 2026 the vcam authors. GPL-2.0, see LICENSE. # vcam-setup – diagnose and configure v4l2loopback for Chromium compatibility # # Chromium-based browsers pick the FIRST /dev/video* node by default. @@ -17,7 +19,7 @@ set -eu # ── help ───────────────────────────────────────────────────── -if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then +if [ "${1:-}" = "-h" ] || [ "${1:-}" = "--help" ]; then sed -n '/^# vcam-setup/,/^$/p' "$0" | sed 's/^# \?//' echo "Usage:" echo " vcam-setup show current state and diagnosis" @@ -28,13 +30,13 @@ fi INIT_SYSTEM="" detect_init() { - if [[ -d /run/systemd/system ]]; then + if [ -d /run/systemd/system ]; then INIT_SYSTEM="systemd" - elif command -v rc-status &>/dev/null && rc-status &>/dev/null; then + elif command -v rc-status >/dev/null 2>&1 && rc-status >/dev/null 2>&1; then INIT_SYSTEM="openrc" - elif command -v sv &>/dev/null && [[ -d /etc/service || -d /var/service ]]; then + elif command -v sv >/dev/null 2>&1 && [ -d /etc/service ] || [ -d /var/service ]; then INIT_SYSTEM="runit" - elif [[ -d /etc/rc.d || -d /etc/init.d ]]; then + elif [ -d /etc/rc.d ] || [ -d /etc/init.d ]; then INIT_SYSTEM="sysv-or-bsd" else INIT_SYSTEM="unknown" @@ -44,9 +46,9 @@ detect_init() { list_devices() { echo "── Current /dev/video* devices ─────────────────────────" for dev in /dev/video*; do - [[ -e $dev ]] || continue + [ -e $dev ] || continue local name="" driver="" - if command -v v4l2-ctl &>/dev/null; then + if command -v v4l2-ctl >/dev/null 2>&1; then name=$(v4l2-ctl -d "$dev" --info 2>/dev/null | \ awk -F': ' '/Card type/ {print $2; exit}') driver=$(v4l2-ctl -d "$dev" --info 2>/dev/null | \ @@ -62,16 +64,16 @@ list_devices detect_init LOOPBACK_DEV="" -REAL_CAMS=() +REAL_CAMS="" for dev in /dev/video*; do - [[ -e $dev ]] || continue - if command -v v4l2-ctl &>/dev/null; then + [ -e $dev ] || continue + if command -v v4l2-ctl >/dev/null 2>&1; then driver=$(v4l2-ctl -d "$dev" --info 2>/dev/null | \ awk -F': ' '/Driver name/ {print $2; exit}') - if [[ "$driver" == "v4l2 loopback" ]]; then + if [ "$driver" = "v4l2 loopback" ]; then LOOPBACK_DEV="$dev" - elif [[ -n "$driver" ]]; then - REAL_CAMS+=("$dev") + elif [ -n "$driver" ]; then + REAL_CAMS="$REAL_CAMS $dev" fi fi done @@ -79,28 +81,28 @@ done # ── analysis ───────────────────────────────────────────────── echo "── Analysis ────────────────────────────────────────────" echo " Init system : $INIT_SYSTEM" -if [[ -z "$LOOPBACK_DEV" ]]; then +if [ -z "$LOOPBACK_DEV" ]; then echo " Loopback : NOT FOUND" else echo " Loopback : $LOOPBACK_DEV" fi -if [[ ${#REAL_CAMS[@]} -eq 0 ]]; then +if [ -z "$(echo $REAL_CAMS | tr -d " ")" ]; then echo " Real cam : NOT FOUND" else - echo " Real cam(s) : ${REAL_CAMS[*]}" + echo " Real cam(s) : $REAL_CAMS" fi echo "" -if [[ -n "$LOOPBACK_DEV" && ${#REAL_CAMS[@]} -gt 0 ]]; then +if [ -n "$LOOPBACK_DEV" ] && [ -n "$(echo $REAL_CAMS | tr -d " ")" ]; then loopback_nr=${LOOPBACK_DEV#/dev/video} # Find the lowest-numbered real cam lowest_real=999 - for rc in "${REAL_CAMS[@]}"; do + for rc in $REAL_CAMS; do n=${rc#/dev/video} - (( n < lowest_real )) && lowest_real=$n + [ "$n" -lt "$lowest_real" ] && lowest_real=$n done echo "── Chromium compatibility ──────────────────────────────" - if (( loopback_nr < lowest_real )); then + if [ "$loopback_nr" -lt "$lowest_real" ]; then echo " OK — loopback at $LOOPBACK_DEV comes before real cam at /dev/video$lowest_real" echo " Chromium should pick the loopback by default." else @@ -113,8 +115,8 @@ if [[ -n "$LOOPBACK_DEV" && ${#REAL_CAMS[@]} -gt 0 ]]; then fi # ── install ────────────────────────────────────────────────── -if [[ "${1:-}" == "--install" ]]; then - if [[ $EUID -ne 0 ]]; then +if [ "${1:-}" = "--install" ]; then + if [ $EUID -ne 0 ]; then echo "Error: --install requires root." >&2 exit 1 fi @@ -138,7 +140,7 @@ MODPROBE # Also write systemd's modules-load.d if the directory exists, since # it's harmless on other systems and helpful where systemd is present. - if [[ -d /etc/modules-load.d ]]; then + if [ -d /etc/modules-load.d ]; then echo "v4l2loopback" > /etc/modules-load.d/vcam.conf echo "Wrote /etc/modules-load.d/vcam.conf (systemd-style autoload)" fi @@ -207,8 +209,8 @@ MSG exit 0 fi -if [[ "${1:-}" == "--uninstall" ]]; then - if [[ $EUID -ne 0 ]]; then +if [ "${1:-}" = "--uninstall" ]; then + if [ $EUID -ne 0 ]; then echo "Error: --uninstall requires root." >&2 exit 1 fi diff --git a/scripts/vcam-tune b/scripts/vcam-tune index aa045d8..f3b635c 100755 --- a/scripts/vcam-tune +++ b/scripts/vcam-tune @@ -1,4 +1,8 @@ #!/usr/bin/env bash +# SPDX-License-Identifier: GPL-2.0-only +# vcam — Copyright (C) 2026 the vcam authors. GPL-2.0, see LICENSE. +# NOTE: this script requires bash (not POSIX sh) — it uses read -rsn1 for +# single-keypress interactive input, which has no POSIX equivalent. # # vcam-tune – interactively adjust filter parameters with the keyboard. #