feat: 添加硬件编码器支持和修复 janus.js 错误

- 添加 HWENCODER 环境变量支持,支持 vaapi、nvenc、amf、v4l2m2m、mediacodec、videotoolbox 等硬件编码器
- 修复 janus.js 相关错误,添加 adapter.js 支持
- 更新 Docker 构建配置以支持硬件编码
- 优化 ustreamer 配置,支持硬件编码回退机制
This commit is contained in:
mofeng-git 2025-08-22 21:25:13 +08:00
parent bdd97c5ea3
commit 04b13b1215
6 changed files with 3425 additions and 9 deletions

View File

@ -43,6 +43,30 @@ RUN sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/' /etc/apt/sources.lis
libasound2 \
nano \
unzip \
libavcodec59 \
libavformat59 \
libavutil57 \
libswscale6 \
libavfilter8 \
libavdevice59 \
&& if [ ${TARGETARCH} != arm ] && [ ${TARGETARCH} != arm64 ]; then \
apt-get install -y --no-install-recommends \
ffmpeg \
vainfo \
libva2 \
libva-drm2 \
libva-x11-2 \
libdrm2 \
mesa-va-drivers \
mesa-vdpau-drivers \
intel-media-va-driver \
i965-va-driver; \
fi \
&& if [ ${TARGETARCH} = arm ] || [ ${TARGETARCH} = arm64 ]; then \
apt-get install -y --no-install-recommends \
v4l-utils \
libv4l-0; \
fi \
&& cp /tmp/lib/* /lib/*-linux-*/ \
&& pip install --no-cache-dir --root-user-action=ignore --disable-pip-version-check /tmp/wheel/*.whl \
&& pip install --no-cache-dir --root-user-action=ignore --disable-pip-version-check pyfatfs \

View File

@ -48,7 +48,28 @@ RUN sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/' /etc/apt/sources.lis
libspeexdsp-dev \
libusb-1.0-0-dev \
libldap2-dev \
libsasl2-dev \
libsasl2-dev \
ffmpeg \
libavcodec-dev \
libavformat-dev \
libavutil-dev \
libswscale-dev \
libavfilter-dev \
libavdevice-dev \
vainfo \
libva-dev \
libva-drm2 \
libva-x11-2 \
libdrm-dev \
mesa-va-drivers \
mesa-vdpau-drivers \
v4l-utils \
libv4l-dev \
&& if [ ${TARGETARCH} != arm ] && [ ${TARGETARCH} != arm64 ]; then \
apt-get install -y --no-install-recommends \
intel-media-va-driver \
i965-va-driver; \
fi \
&& apt clean \
&& rm -rf /var/lib/apt/lists/*
@ -76,8 +97,6 @@ RUN --security=insecure pip config set global.index-url https://pypi.tuna.tsingh
python-ldap python-pam pyrad pyudev pyusb luma.oled pyserial-asyncio
# 编译 python vedev库
# && wget https://raw.githubusercontent.com/torvalds/linux/refs/heads/master/include/uapi/linux/input.h \
# && wget https://raw.githubusercontent.com/torvalds/linux/refs/heads/master/include/uapi/linux/input-event-codes.h \
RUN git clone --depth=1 https://github.com/gvalkov/python-evdev.git /tmp/python-evdev \
&& cd /tmp/python-evdev \
&& python3 setup.py bdist_wheel --dist-dir /tmp/wheel/
@ -115,8 +134,7 @@ RUN git clone --depth=1 https://gitlab.freedesktop.org/libnice/libnice /tmp/libn
# 编译 ustreamer
RUN sed --in-place --expression 's|^#include "refcount.h"$|#include "../refcount.h"|g' /usr/include/janus/plugins/plugin.h \
&& git clone --depth=1 https://github.com/mofeng-git/ustreamer /tmp/ustreamer \
&& sed -i '68s/-Wl,-Bstatic//' /tmp/ustreamer/src/Makefile \
&& make -j WITH_PYTHON=1 WITH_JANUS=1 WITH_LIBX264=1 -C /tmp/ustreamer \
&& make -j WITH_PYTHON=1 WITH_JANUS=1 WITH_FFMPEG=1 -C /tmp/ustreamer \
&& /tmp/ustreamer/ustreamer -v \
&& cp /tmp/ustreamer/python/dist/*.whl /tmp/wheel/
@ -124,7 +142,7 @@ RUN sed --in-place --expression 's|^#include "refcount.h"$|#include "../refcount
RUN mkdir /tmp/lib \
&& cd /lib/*-linux-*/ \
&& cp libevent_core-*.so.* libbsd.so.* libevent_pthreads-*.so.* libspeexdsp.so.* \
libevent-*.so.* libjpeg.so.* libx264.so.* libyuv.so.* libnice.so.* \
libevent-*.so.* libjpeg.so.* libyuv.so.* libnice.so.* \
/tmp/lib/ \
&& find /usr/lib -name "libsrtp2.so.*" -exec cp {} /tmp/lib/ \; \
&& find /usr/lib -name "libwebsockets.so.*" -exec cp {} /tmp/lib/ \;

View File

@ -215,6 +215,12 @@ EOF
fi
fi
if [ ! -z "$HWENCODER" ]; then
if sed -i "s/--h264-hwenc=disabled/--h264-hwenc=$HWENCODER/g" /etc/kvmd/override.yaml; then
log_info "硬件编码器已设置为 $HWENCODER"
fi
fi
touch /etc/kvmd/.init_flag
log_info "初始化配置完成"

View File

@ -48,7 +48,7 @@ kvmd:
- "--device=/dev/video0"
- "--persistent"
- "--format=mjpeg"
- "--encoder=LIBX264-VIDEO"
- "--encoder=FFMPEG-VIDEO"
- "--resolution={resolution}"
- "--desired-fps={desired_fps}"
- "--drop-same-frames=30"
@ -67,6 +67,8 @@ kvmd:
- "--h264-bitrate={h264_bitrate}"
- "--h264-gop={h264_gop}"
- "--h264-preset=ultrafast"
- "--h264-hwenc=disabled"
- "--h264-hwenc-fallback"
- "--slowdown"
gpio:
drivers:

3364
testenv/js/adapter.js Normal file

File diff suppressed because it is too large Load Diff

View File

@ -24,8 +24,10 @@
OTHER DEALINGS IN THE SOFTWARE.
*/
import "./adapter.js";
// eslint-disable-next-line no-unused-vars
var Janus = (function (factory) {
export var Janus = (function (factory) {
if (typeof define === 'function' && define.amd) {
define(factory);
} else if (typeof module === 'object' && module.exports) {
@ -1893,7 +1895,7 @@ var Janus = (function (factory) {
return;
}
let pc_config = {
iceServers: iceServers,
iceServers: (typeof iceServers === "function" ? iceServers() : iceServers),
iceTransportPolicy: iceTransportPolicy,
bundlePolicy: bundlePolicy
};