Open ARJhe opened 4 years ago
# initialize repo git init # create ignore file echo > .gitignore # to buffer zone git commit -m "add ignore" .gitignore # create new project on github # indicate remote stock git remote add origin https://github.com/ARJhe/django_rtsp_ipc.git # push to remote git push -u origin master
pip3 install django==3.0.2
django-admin startproject ipc_server django-admin startapp streaming
django-admin startproject ipc_server
django-admin startapp streaming
[ipc_server] > settings.py
INSTALLED_APPS = [ 'streaming.apps.StreamingConfig', ...
create html file and directory under streaming [streaming] > [templates] > [streaming] > index.html
[streaming] > [templates] > [streaming] > index.html
<!DOCTYPE html> <html> <head> <title>Live Cam</title> </head> <body> <script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script> <video id="video1" autoplay controls="controls"></video> <script> if (Hls.isSupported()) { var video1 = document.getElementById('video1'); var hls1 = new Hls(); // bind them together hls1.attachMedia(video1); hls1.on(Hls.Events.MEDIA_ATTACHED, function () { console.log("video and hls.js are now bound together !"); // load variable from views.py hls1.loadSource("{{stream_path}}"); hls1.on(Hls.Events.MANIFEST_PARSED, function (event, data) { console.log("manifest loaded, found " + data.levels.length + " quality level"); }); }); } </script> </body> </html>
under streaming directory create directory and put stream data in it. [streaming] > [static] > [live] > [stream](put data here)
[streaming] > [static] > [live] > [stream](put data here)
set index.html view and set variable for hls to fetch data [streaming] > views.py
[streaming] > views.py
from django.shortcuts import render
stream_path = "http://127.0.0.1:8000/static/live/stream/mystream.m3u8"
def home(request): return render(request, 'streaming/index.html', {'stream_path': stream_path})
- set streaming home url (create urls.py under streaming) `[streaming] > urls.py` ```py from django.urls import path from . import views urlpatterns = [ path('', views.home, name='streaming_home'), ]
[ipc_server] > urls.py
from django.urls import path, include urlpatterns = [ path('admin/', admin.site.urls), # add url from streaming directory path('', include('streaming.urls')) ]
https://docs.google.com/document/d/1R33BIMTD8pe0UXWRTzOcZkvgQLHPP-QHZ_kupLWczVQ/edit?usp=sharing
Initial Env Settings
git
env setting
pip3 install django==3.0.2
Django
django-admin startproject ipc_server
django-admin startapp streaming
[ipc_server] > settings.py
create html file and directory under streaming
[streaming] > [templates] > [streaming] > index.html
under streaming directory create directory and put stream data in it.
[streaming] > [static] > [live] > [stream](put data here)
set index.html view and set variable for hls to fetch data
[streaming] > views.py
stream_path = "http://127.0.0.1:8000/static/live/stream/mystream.m3u8"
def home(request): return render(request, 'streaming/index.html', {'stream_path': stream_path})
[ipc_server] > urls.py