Skip to content

Commit

Permalink
remove node jsmpeg server
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeblackshear committed Jun 12, 2021
1 parent 5afda72 commit 7aaf5bd
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 14 deletions.
5 changes: 0 additions & 5 deletions docker/rootfs/etc/services.d/jsmpeg/finish

This file was deleted.

2 changes: 0 additions & 2 deletions docker/rootfs/etc/services.d/jsmpeg/run

This file was deleted.

71 changes: 66 additions & 5 deletions frigate/birdseye.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
import logging
import multiprocessing as mp
import numpy as np
import subprocess as sp
import logging
import threading

import gevent
import numpy as np
from flask import (
Blueprint,
Flask,
Response,
current_app,
jsonify,
make_response,
request,
)
from flask_sockets import Sockets
from gevent import pywsgi
from geventwebsocket.handler import WebSocketHandler

from frigate.util import SharedMemoryFrameManager

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -56,12 +71,12 @@ def __init__(self, stop_event):
)

def start_ffmpeg(self):
ffmpeg_cmd = "ffmpeg -f rawvideo -pix_fmt yuv420p -video_size 1920x1080 -i pipe: -f mpegts -codec:v mpeg1video -b:v 1000k -bf 0 http:https://localhost:8081/birdseye".split(
ffmpeg_cmd = "ffmpeg -f rawvideo -pix_fmt yuv420p -video_size 1920x1080 -i pipe: -f mpegts -codec:v mpeg1video -b:v 1000k -bf 0 pipe:".split(
" "
)
self.process = sp.Popen(
ffmpeg_cmd,
stdout=sp.DEVNULL,
stdout=sp.PIPE,
# TODO: logging
stderr=sp.DEVNULL,
stdin=sp.PIPE,
Expand All @@ -81,4 +96,50 @@ def run(self):

# separate process for passing jsmpeg packets over websockets
# signals to the frame manager when a client is listening
# class JSMpegSocketServer:
def run_jsmpeg_server():
app = Flask(__name__)
sockets = Sockets(app)

http = Blueprint("http", __name__)
ws = Blueprint("ws", __name__)

# TODO: add something for notification of subscribers
# self.app.frigate_config = frigate_config

app.register_blueprint(http)
sockets.register_blueprint(ws)

clients = list()

@http.route("/birdseye")
def receive_mpegts():
chunk_size = 4096
while True:
chunk = request.stream.read(chunk_size)
if len(chunk) == 0:
break
for client in clients:
try:
client.send(chunk)
except:
logger.debug(
"Removing websocket client due to a closed connection."
)
clients.remove(client)

@ws.route("/birdseye")
def echo_socket(socket):
# TODO: get reference to
# current_app.mqtt_backend.register(socket)
clients.append(socket)

while not socket.closed:
# Sleep to prevent *constant* context-switches.
gevent.sleep(0.1)

server = pywsgi.WSGIServer(("127.0.0.1", 5050), app, handler_class=WebSocketHandler)

try:
server.serve_forever()
except KeyboardInterrupt:
pass
4 changes: 2 additions & 2 deletions web/public/jsmpeg.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<script type="text/javascript" src="jsmpeg.min.js"></script>
<script type="text/javascript">
var canvas = document.getElementById('video-canvas');
var url = 'ws:https://'+document.location.hostname+':5000/live/birdseye';
var player = new JSMpeg.Player(url, {canvas: canvas});
var url = 'ws:https://'+document.location.hostname+':8084/';
var player = new JSMpeg.Player(url, {canvas: canvas, protocols: []});
</script>
</body>
</html>

0 comments on commit 7aaf5bd

Please sign in to comment.