Add initial files for ustreamer
This commit is contained in:
parent
583f34d213
commit
04d7fd3520
36
camera-ustreamer/DOCS.md
Normal file
36
camera-ustreamer/DOCS.md
Normal file
@ -0,0 +1,36 @@
|
||||
# Documentation
|
||||
|
||||
## Configuration
|
||||
|
||||
- `mjpg_input`: Specify input arguments for mjpg_streamer.
|
||||
|
||||
## How to use
|
||||
|
||||
Set input arguments through `mjpg_input` configuration option, start the add-on.
|
||||
|
||||
## Accessing camera from Home Assistant
|
||||
|
||||
The camera stream and snapshot can be accessed by e.g. [MJPEG IP Camera](https://www.home-assistant.io/integrations/mjpeg/), with URLs:
|
||||
* MJPEG URL: `http://<addon-hostname>/?action=stream`
|
||||
* Still image URL: `http://<addon-hostname>/?action=snapshot`.
|
||||
|
||||
Addon hostname can be found under [addon settings](https://my.home-assistant.io/redirect/supervisor_addon/?addon=b7aa59c4_camera-mjpg-streamer&repository_url=https%3A%2F%2Fgithub.com%2Ffredrikbaberg%2Fha-3dprinter-addons).
|
||||
|
||||
## Ingress?
|
||||
|
||||
Ingress support is included only to verify that the camera can be accessed. Streaming will most likely only work in the "JavaScript" tab.
|
||||
|
||||
## Testing
|
||||
|
||||
For testing you can set `mjpg_input` to:
|
||||
> input_file.so -f /www_mjpg -e
|
||||
|
||||
This will result in showing a test image.
|
||||
|
||||
## Versions
|
||||
|
||||
Some notes regarding the software and versions.
|
||||
Not all software is installed for all images.
|
||||
|
||||
- mjpg-streamer
|
||||
- Compiled from [https://github.com/jacksonliam/mjpg-streamer](https://github.com/jacksonliam/mjpg-streamer).
|
||||
92
camera-ustreamer/Dockerfile
Normal file
92
camera-ustreamer/Dockerfile
Normal file
@ -0,0 +1,92 @@
|
||||
ARG BUILD_FROM="ghcr.io/home-assistant/amd64-base"
|
||||
ARG JANUS_GATEWAY_VERSION="1.1.3"
|
||||
ARG USTREAMER_VERSION="5.38"
|
||||
|
||||
FROM ${BUILD_FROM} AS builder
|
||||
ARG JANUS_GATEWAY_VERSION
|
||||
ARG USTREAMER_VERSION
|
||||
ENV LANG C.UTF-8
|
||||
|
||||
# Janus
|
||||
RUN apk add -U --virtual .build-deps-janus \
|
||||
build-base \
|
||||
autoconf \
|
||||
automake \
|
||||
libtool \
|
||||
libconfig-dev \
|
||||
glib-dev \
|
||||
libnice-dev \
|
||||
jansson-dev \
|
||||
openssl-dev \
|
||||
zlib-dev \
|
||||
libsrtp-dev \
|
||||
curl-dev \
|
||||
libogg-dev \
|
||||
libwebsockets-dev \
|
||||
libusrsctp-dev
|
||||
RUN wget -qO- https://github.com/meetecho/janus-gateway/archive/v${JANUS_GATEWAY_VERSION}.tar.gz | tar xz -C /tmp
|
||||
WORKDIR /tmp/janus-gateway-${JANUS_GATEWAY_VERSION}
|
||||
RUN sh autogen.sh
|
||||
RUN ./configure --prefix=/opt/janus
|
||||
RUN make
|
||||
RUN make install
|
||||
RUN make configs
|
||||
|
||||
# Ustreamer
|
||||
RUN apk add -U --virtual .build-deps-ustreamer \
|
||||
sed \
|
||||
build-base \
|
||||
libevent-dev \
|
||||
libbsd-dev \
|
||||
libjpeg-turbo-dev \
|
||||
musl-dev \
|
||||
alsa-lib-dev \
|
||||
speexdsp-dev \
|
||||
opus-dev \
|
||||
glib-dev \
|
||||
jansson-dev
|
||||
RUN wget -qO- https://github.com/pikvm/ustreamer/archive/v${USTREAMER_VERSION}.tar.gz | tar xz -C /tmp
|
||||
WORKDIR /tmp/ustreamer-${USTREAMER_VERSION}
|
||||
RUN ln -s /opt/janus/include/janus /usr/include/janus
|
||||
RUN sed --in-place --expression 's|^#include "refcount.h"$|#include "../refcount.h"|g' /usr/include/janus/plugins/plugin.h
|
||||
RUN make WITH_PTHREAD_NP=0 WITH_JANUS=1
|
||||
RUN make install
|
||||
RUN mv janus/libjanus_ustreamer.so /opt/janus/lib/janus/plugins/libjanus_ustreamer.so
|
||||
|
||||
FROM ${BUILD_FROM} AS final
|
||||
ENV LANG C.UTF-8
|
||||
|
||||
RUN apk add -U \
|
||||
alsa-lib \
|
||||
curl \
|
||||
glib \
|
||||
glib \
|
||||
jansson \
|
||||
jansson \
|
||||
libbsd \
|
||||
libconfig \
|
||||
libevent \
|
||||
libjpeg-turbo \
|
||||
libnice \
|
||||
libogg \
|
||||
libsrtp \
|
||||
libtool \
|
||||
libusrsctp \
|
||||
libwebsockets \
|
||||
musl \
|
||||
openssl \
|
||||
opus \
|
||||
speexdsp \
|
||||
zlib \
|
||||
caddy
|
||||
|
||||
COPY --from=builder /opt/janus /opt/janus
|
||||
COPY --from=builder /usr/local/bin/ustreamer /usr/local/bin/ustreamer
|
||||
|
||||
COPY rootfs/ /
|
||||
|
||||
WORKDIR /
|
||||
|
||||
# # Make files executable
|
||||
# # RUN chmod +x /etc/cont-init.d/*.sh
|
||||
# # RUN chmod +x /etc/services.d/*/*
|
||||
5
camera-ustreamer/README.md
Normal file
5
camera-ustreamer/README.md
Normal file
@ -0,0 +1,5 @@
|
||||
# mjpg-streamer
|
||||
|
||||
Provides camera stream through `mjpg-streamer`, to be used by e.g. OctoPrint addon.
|
||||
|
||||
Instructions are provided in the tab "Docs".
|
||||
28
camera-ustreamer/config.yaml
Normal file
28
camera-ustreamer/config.yaml
Normal file
@ -0,0 +1,28 @@
|
||||
name: "Camera-mjpg-streamer"
|
||||
version: "2022.7.0"
|
||||
slug: "camera-mjpg-streamer"
|
||||
description: "Camera streaming addon for Home Assistant, based on mjpg-streamer."
|
||||
url: "https://github.com/fredrikbaberg/ha-3dprinter-addons/tree/main/camera-mjpg-streamer"
|
||||
ingress: true
|
||||
ingress_stream: true
|
||||
panel_icon: mdi:camera
|
||||
panel_title: mjpg-streamer
|
||||
arch:
|
||||
- armv7
|
||||
- amd64
|
||||
- armhf
|
||||
- aarch64
|
||||
- i386
|
||||
stage: experimental
|
||||
init: false
|
||||
video: true
|
||||
usb: true
|
||||
ports:
|
||||
80/tcp: null
|
||||
ports_description:
|
||||
80/tcp: Web-based interface (Not required for Ingress)
|
||||
options:
|
||||
mjpg_input: "input_uvc.so -n"
|
||||
schema:
|
||||
mjpg_input: "str"
|
||||
image: ghcr.io/fredrikbaberg/ha-addon-camera-mjpg-streamer-{arch}
|
||||
4
camera-ustreamer/rootfs/etc/caddy/Caddyfile
Normal file
4
camera-ustreamer/rootfs/etc/caddy/Caddyfile
Normal file
@ -0,0 +1,4 @@
|
||||
localhost
|
||||
|
||||
root * /server
|
||||
file_server
|
||||
9
camera-ustreamer/rootfs/etc/services.d/proxy/finish
Normal file
9
camera-ustreamer/rootfs/etc/services.d/proxy/finish
Normal file
@ -0,0 +1,9 @@
|
||||
#!/usr/bin/execlineb -S0
|
||||
# ==============================================================================
|
||||
# Add-on: mjpg-streamer
|
||||
# Take down the S6 supervision tree when Nginx fails
|
||||
# ==============================================================================
|
||||
if -n { s6-test $# -ne 0 }
|
||||
if -n { s6-test ${1} -eq 256 }
|
||||
|
||||
s6-svscanctl -t /var/run/s6/services
|
||||
11
camera-ustreamer/rootfs/etc/services.d/proxy/run
Normal file
11
camera-ustreamer/rootfs/etc/services.d/proxy/run
Normal file
@ -0,0 +1,11 @@
|
||||
#!/usr/bin/with-contenv bashio
|
||||
# ==============================================================================
|
||||
# Add-on: mjpg-streamer
|
||||
# Runs the Nginx daemon
|
||||
# ==============================================================================
|
||||
|
||||
# Wait for aiortc web server to be available
|
||||
bashio::net.wait_for 80
|
||||
|
||||
bashio::log.info "Starting proxy..."
|
||||
# exec caddy run -config /etc/caddy/Caddyfile
|
||||
9
camera-ustreamer/rootfs/etc/services.d/ustreamer/finish
Normal file
9
camera-ustreamer/rootfs/etc/services.d/ustreamer/finish
Normal file
@ -0,0 +1,9 @@
|
||||
#!/usr/bin/execlineb -S0
|
||||
# ==============================================================================
|
||||
# Add-on: mjpg-streamer
|
||||
# Take down the S6 supervision tree when mjpg-streamer fails
|
||||
# ==============================================================================
|
||||
if -n { s6-test $# -ne 0 }
|
||||
if -n { s6-test ${1} -eq 256 }
|
||||
|
||||
s6-svscanctl -t /var/run/s6/services
|
||||
9
camera-ustreamer/rootfs/etc/services.d/ustreamer/run
Normal file
9
camera-ustreamer/rootfs/etc/services.d/ustreamer/run
Normal file
@ -0,0 +1,9 @@
|
||||
#!/usr/bin/with-contenv bashio
|
||||
# ==============================================================================
|
||||
# Add-on: mjpg-streamer
|
||||
# Runs mjpg-streamer
|
||||
# ==============================================================================
|
||||
|
||||
bashio::log.info "Starting mjpg-streamer.."
|
||||
|
||||
mjpg_streamer -i "$(bashio::config 'mjpg_input')" -o "output_http.so -w /www_mjpg -p 80"
|
||||
@ -0,0 +1,3 @@
|
||||
memsink: {
|
||||
object = "demo::ustreamer::h264"
|
||||
}
|
||||
100
camera-ustreamer/rootfs/server/index.html
Normal file
100
camera-ustreamer/rootfs/server/index.html
Normal file
@ -0,0 +1,100 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>µStreamer H.264 demo</title>
|
||||
<script src="https://webrtc.github.io/adapter/adapter-8.1.0.js"></script>
|
||||
<!-- janus.js is the JavaScript client library of Janus, as specified above in
|
||||
the prerequisites section of the client setup. You might need to change
|
||||
the `src` path, depending on where you serve this file from. -->
|
||||
<script src="janus.js"></script>
|
||||
<style>
|
||||
video {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
object-fit: contain;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<video id="webrtc-output" autoplay playsinline muted></video>
|
||||
<script type="text/javascript">
|
||||
// Initialize Janus library.
|
||||
Janus.init({
|
||||
// Turn on debug logs in the browser console.
|
||||
debug: true,
|
||||
|
||||
// Configure Janus to use standard browser APIs internally.
|
||||
dependencies: Janus.useDefaultDependencies(),
|
||||
});
|
||||
|
||||
// Establish a WebSockets connection to the server.
|
||||
const janus = new Janus({
|
||||
// Specify the URL of the Janus server’s WebSockets endpoint.
|
||||
server: `ws://${window.location.hostname}:8188/`,
|
||||
|
||||
// Callback function if the client connects successfully.
|
||||
success: attachUStreamerPlugin,
|
||||
|
||||
// Callback function if the client fails to connect.
|
||||
error: console.error,
|
||||
});
|
||||
|
||||
let uStreamerPluginHandle = null;
|
||||
|
||||
function attachUStreamerPlugin() {
|
||||
// Instruct the server to attach the µStreamer Janus plugin.
|
||||
janus.attach({
|
||||
// Qualifier of the plugin.
|
||||
plugin: "janus.plugin.ustreamer",
|
||||
|
||||
// Callback function, for when the server attached the plugin
|
||||
// successfully.
|
||||
success: function (pluginHandle) {
|
||||
uStreamerPluginHandle = pluginHandle;
|
||||
// Instruct the µStreamer Janus plugin to initiate streaming.
|
||||
uStreamerPluginHandle.send({ message: { request: "watch", params: {audio: true} } });
|
||||
},
|
||||
|
||||
// Callback function if the server fails to attach the plugin.
|
||||
error: console.error,
|
||||
|
||||
// Callback function for processing messages from the Janus server.
|
||||
onmessage: function (msg, jsepOffer) {
|
||||
// If there is a JSEP offer, respond to it. This starts the WebRTC
|
||||
// connection.
|
||||
if (jsepOffer) {
|
||||
uStreamerPluginHandle.createAnswer({
|
||||
jsep: jsepOffer,
|
||||
// Prevent the client from sending audio and video, as this would
|
||||
// trigger a permission dialog in the browser.
|
||||
media: { audioSend: false, videoSend: false },
|
||||
success: function (jsepAnswer) {
|
||||
uStreamerPluginHandle.send({
|
||||
message: { request: "start" },
|
||||
jsep: jsepAnswer,
|
||||
});
|
||||
},
|
||||
error: console.error,
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
// Callback function, for when a media stream arrives.
|
||||
onremotetrack: function (mediaStreamTrack, mediaId, isAdded) {
|
||||
if (isAdded) {
|
||||
// Attach the received media track to the video element. Cloning the
|
||||
// mediaStreamTrack creates a new object with a distinct, globally
|
||||
// unique stream identifier.
|
||||
const videoElement = document.getElementById("webrtc-output");
|
||||
if (videoElement.srcObject === null) {
|
||||
videoElement.srcObject = new MediaStream();
|
||||
}
|
||||
videoElement.srcObject.addTrack(mediaStreamTrack.clone());
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Reference in New Issue
Block a user