Slave working

This commit is contained in:
jimmy 2022-07-18 18:47:01 +12:00
parent 054f92aa18
commit e2c41f0360
2 changed files with 21 additions and 22 deletions

View File

@ -1,19 +1,16 @@
# importing vlc module # importing vlc module
from email import message
from pydoc import cli
from statistics import median
import vlc
from time import sleep from time import sleep
import paho.mqtt.client as mqtt import paho.mqtt.client as mqtt
from video import Video from video import Video
import multiprocessing import multiprocessing
import sys
class App: class App:
def __init__(self, client): def __init__(self, client, x, y):
self.client = client self.client = client
self.video = Video(4000, 1000) self.video = Video(x, y)
def on_connect(self, client, userdata, flags, rc): def on_connect(self, client, userdata, flags, rc):
print("Connected with result code "+str(rc)) print("Connected with result code "+str(rc))
@ -24,19 +21,24 @@ class App:
print(msg.topic+" "+str(msg.payload)) print(msg.topic+" "+str(msg.payload))
if msg.payload == b'start': if msg.payload == b'start':
print("Start") print("Start")
self.video.setVideo("slave/sample-mp4-file.mp4") self.x = multiprocessing.Process(target = self.video.start, args=("slave/sample-mp4-file.mp4",))
self.x = multiprocessing.Process(target = self.video.start)
self.x.start() self.x.start()
elif msg.payload == b'stop': elif msg.payload == b'stop':
print("Stop") print("Stop")
self.x.terminate() self.x.terminate()
client = mqtt.Client() def main():
app = App(client)
client.on_connect = app.on_connect
client.on_message = app.on_message
client.connect("10.173.54.35", 1883, 60) client = mqtt.Client()
app = App(client, int(sys.argv[1]), int(sys.argv[2]))
client.on_connect = app.on_connect
client.on_message = app.on_message
client.loop_forever() client.connect("10.173.54.35", 1883, 60)
client.loop_forever()
if __name__ == "__main__":
main()

View File

@ -8,12 +8,9 @@ class Video:
self.x = x self.x = x
self.y = y self.y = y
def setVideo(self, path): def start(self, path):
self.path = path
def start(self):
self.cap = cv2.VideoCapture(self.path) self.cap = cv2.VideoCapture(path)
# Check if camera opened successfully # Check if camera opened successfully
if (self.cap.isOpened()== False): if (self.cap.isOpened()== False):
print("Error opening video file") print("Error opening video file")
@ -55,13 +52,13 @@ class Video:
if __name__ == "__main__": if __name__ == "__main__":
video = Video(0, 0) video = Video(0, 0)
video.setVideo("sample-mp4-file.mp4") x = multiprocessing.Process(target = video.start, args=("slave/sample-mp4-file.mp4",))
x = multiprocessing.Process(target = video.start)
x.start() x.start()
time.sleep(2) time.sleep(2)
x.terminate() x.terminate()
time.sleep(1) time.sleep(1)
x = multiprocessing.Process(target = video.start) video = Video(4000, 0)
x = multiprocessing.Process(target = video.start, args=("slave/sample-mp4-file.mp4",))
x.start() x.start()
time.sleep(1) time.sleep(1)
x.terminate() x.terminate()