How to get Python screen-sharing separate application window to show on Django web server?

Viewed 210

I am trying to share the desktop video of a windows virtual machine to show onto a linux Django web server. When I run the Python scripts, the screen sharing would show as a separate application window.

How do I get the Python separate window to show onto the Django web server instead?

receiver.py (running on linux machine)

from vidstream import StreamingServer
import threading

receiver = StreamingServer('ipaddr', 8080)

t = threading.Thread(target=receiver.start_server)
t.start()

while input("") != 'STOP':
    continue

receiver.stop_server()

sender.py (running on windows virtual machine)

from vidstream import ScreenShareClient
import threading

sender = ScreenShareClient('ipaddr', 8080)

t = threading.Thread(target=sender.start_stream)
t.start()

while input("") != 'STOP':
    continue

sender.stop_stream()

urls.py

from django.urls import path
from . import views 

# URL configuration
urlpatterns = [
    path('index/', views.getIndex), 
    path('', views.button),
    path('receiver/', views.receiver),
]

views.py

from django.shortcuts import render

import requests
import sys
from subprocess import run,PIPE

from django.http import HttpResponse, StreamingHttpResponse

def button(request):
    return render(request, 'receiver.html')

def receiver(request):
    inp=request.POST.get()
    out=run([sys.executable, "//home//cts//ctdjango//receiver.py"],shell=False,stdout=PIPE)
    print(out)
    return render(request, 'receiver.html', {'data':out.stdout})

receiver.html

<html>
<head>
    <title>Cybertest Receiver</title>
</head>
<body>
    <form action="/djangosite/templates/receiver.html" method="POST">
        {% csrf_token %}
        {% if data %}
        <p>Output data: {{ data }}</p> 
        {% else %}
        <p>No data output</p>
        {% endif %}
        <br><br>
        <button type=“submit“>Run script</button>
    </form>
</body>
</html>
1 Answers

I think the approach is not correct: to be able to play a video inside a browser you need to provide a proper streaming format supported by the browser.

I suggest m3u8 format, with this format you will also be able to see it using software like VLC Media Player.

Proposed approach:

Your webserver will simply need serve two kind of files:

  • an index file (.m3u8)
  • pieces of video (called segment files) recorded from the screen capture

An example using python and gstreamer can be found here: Stream live video to browser using GStreamer

It is a starting point, what you want to achieve is reachable but you have to properly connect together some pieces and is not trivial.

Related