Use openh264 for broadcast

This commit is contained in:
John Nguyen 2024-01-26 20:09:53 +11:00
parent d298d0c97b
commit c0c8b05be2
6 changed files with 32 additions and 9 deletions

View file

@ -20,7 +20,7 @@ RUN set -eux; \
# Install pip and ninja
python3-pip python-gi-dev ninja-build \
# Install build deps
autopoint autoconf automake autotools-dev libtool gettext bison flex gtk-doc-tools \
autopoint autoconf automake autotools-dev libtool gettext bison flex gtk-doc-tools nasm wget \
# Install libraries
librtmp-dev \
libvo-aacenc-dev \
@ -39,6 +39,15 @@ RUN set -eux; \
apt-get clean -y; \
rm -rf /var/lib/apt/lists/* /var/cache/apt/*
#
# build openh264
RUN set -eux; \
cd /tmp; wget https://github.com/cisco/openh264/archive/refs/tags/v2.4.0.tar.gz && tar xvf v2.4.0.tar.gz; \
cd openh264-2.4.0; \
meson builddir; \
ninja -C builddir; \
ninja -C builddir install;
#
# build gstreamer
RUN set -eux; \
@ -48,7 +57,9 @@ RUN set -eux; \
meson --prefix /opt/gstreamer \
-Dgpl=enabled \
-Dugly=enabled \
-Dbad=enabled \
-Dgst-plugins-ugly:x264=enabled \
-Dgst-plugins-bad:openh264=enabled \
build; \
ninja -C build; \
meson install -C build;
@ -274,12 +285,13 @@ ENV NEKO_BIND=:8080
#
# set gstreamer envs
ENV PATH="/opt/gstreamer/bin:${PATH}"
ENV LD_LIBRARY_PATH="/opt/gstreamer/lib/x86_64-linux-gnu${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}"
ENV PKG_CONFIG_PATH="/opt/gstreamer/lib/x86_64-linux-gnu/pkgconfig${PKG_CONFIG_PATH:+:${PKG_CONFIG_PATH}}"
ENV LD_LIBRARY_PATH="/opt/gstreamer/lib/x86_64-linux-gnu:/usr/local/lib/x86_64-linux-gnu${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}"
ENV PKG_CONFIG_PATH="/opt/gstreamer/lib/x86_64-linux-gnu/pkgconfig:/usr/local/lib/x86_64-linux-gnu/pkgconfig${PKG_CONFIG_PATH:+:${PKG_CONFIG_PATH}}"
#
# copy gstreamer from previous stage
COPY --from=gstreamer /opt/gstreamer /opt/gstreamer
COPY --from=gstreamer /usr/local/lib/x86_64-linux-gnu /usr/local/lib/x86_64-linux-gnu
#
# copy static files from previous stages

View file

@ -33,6 +33,6 @@ RUN go mod download
COPY server/ .
RUN ./build
FROM cave-firefox:latest
FROM cave-firefox:202401261754
COPY --from=server /src/bin/neko /usr/bin/neko

7
build-docker.sh Executable file
View file

@ -0,0 +1,7 @@
#!/usr/bin/sh
VERSION=202401261754
docker build -t neko-cave/base-nvidia:$VERSION -f ./.docker/base/Dockerfile.nvidia .
docker build --build-arg="BASE_IMAGE=neko-cave/base-nvidia:$VERSION" -t cave-firefox:$VERSION -f ./.docker/firefox/Dockerfile.nvidia ./.docker/firefox/

View file

@ -29,5 +29,5 @@ services:
NEKO_ICELITE: 1
NEKO_BROADCAST_URL: rtmp://ome.thuan.au:1935/app/stream-neko
NEKO_NAT1TO1: 192.168.0.34
NEKO_HWENC: NVENC
# NEKO_HWENC: NVENC
NEKO_VIDEO_CODEC: h264

View file

@ -41,7 +41,11 @@ func New(desktop types.DesktopManager, config *config.Capture) *CaptureManagerCt
if config.VideoMaxFPS > 0 && config.VideoMaxFPS < fps {
fps = config.VideoMaxFPS
}
return NewVideoPipeline(config.VideoCodec, config.Display, config.VideoPipeline, fps, config.VideoBitrate, config.VideoHWEnc)
pipelineStr, err := NewVideoPipeline(config.VideoCodec, config.Display, config.VideoPipeline, fps, config.VideoBitrate, config.VideoHWEnc)
logger.Info().Msgf("pipelineStr: %s", pipelineStr)
return pipelineStr, err
}, "video"),
}
}

View file

@ -47,9 +47,9 @@ func NewBroadcastPipeline(device string, display string, pipelineSrc string, url
// replace display
pipelineStr = strings.Replace(pipelineStr, "{display}", display, -1)
} else {
birate := 5000
pipelineStr = fmt.Sprintf("flvmux name=mux ! rtmpsink location='%s live=1 subscribe=stream-neko buffer=1200000' %s audio/x-raw,channels=2 ! audioconvert ! voaacenc ! mux. %s video/x-raw,format=NV12 ! nvh264enc name=encoder rc-lookahead=20 preset=2 gop-size=120 temporal-aq=true bitrate=%d vbv-buffer-size=%d rc-mode=cbr bframes=0 ! h264parse config-interval=-1 ! mux.", url, audio, video, birate, birate)
// pipelineStr = fmt.Sprintf("flvmux name=mux ! rtmpsink location='%s live=1 subscribe=stream-neko buffer=1200000' %s audio/x-raw,channels=2 ! audioconvert ! voaacenc ! mux. %s video/x-raw,format=NV12 ! openh264enc name=encoder bitrate=%d vbv-buffer-size=%d ! h264parse config-interval=-1 ! mux.", url, audio, video, birate, birate)
bitrate := 4000
// pipelineStr = fmt.Sprintf("flvmux name=mux ! rtmpsink location='%s live=1 subscribe=stream-neko buffer=1200000' %s audio/x-raw,channels=2 ! audioconvert ! voaacenc ! mux. %s video/x-raw,format=NV12 ! nvh264enc name=encoder rc-lookahead=20 preset=2 gop-size=120 temporal-aq=true bitrate=%d vbv-buffer-size=%d rc-mode=cbr bframes=0 ! h264parse config-interval=-1 ! mux.", url, audio, video, bitrate, bitrate)
pipelineStr = fmt.Sprintf("flvmux name=mux ! rtmpsink location='%s live=1 subscribe=stream-neko' %s audio/x-raw,channels=2 ! audioconvert ! voaacenc ! mux. %s video/x-raw ! videoconvert ! queue ! openh264enc multi-thread=2 complexity=medium bitrate=%d max-bitrate=%d ! h264parse config-interval=-1 ! mux.", url, audio, video, bitrate*1000, (bitrate+1024)*1000)
}
return pipelineStr, nil