diff --git a/slave/main.py b/slave/main.py index b3a78be..77d5244 100644 --- a/slave/main.py +++ b/slave/main.py @@ -1,19 +1,16 @@ # importing vlc module -from email import message -from pydoc import cli -from statistics import median -import vlc from time import sleep import paho.mqtt.client as mqtt from video import Video import multiprocessing +import sys class App: - def __init__(self, client): + def __init__(self, client, x, y): self.client = client - self.video = Video(4000, 1000) + self.video = Video(x, y) def on_connect(self, client, userdata, flags, rc): print("Connected with result code "+str(rc)) @@ -24,19 +21,24 @@ class App: print(msg.topic+" "+str(msg.payload)) if msg.payload == b'start': print("Start") - self.video.setVideo("slave/sample-mp4-file.mp4") - self.x = multiprocessing.Process(target = self.video.start) + self.x = multiprocessing.Process(target = self.video.start, args=("slave/sample-mp4-file.mp4",)) self.x.start() elif msg.payload == b'stop': print("Stop") self.x.terminate() -client = mqtt.Client() -app = App(client) -client.on_connect = app.on_connect -client.on_message = app.on_message +def main(): -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() \ No newline at end of file + client.connect("10.173.54.35", 1883, 60) + + client.loop_forever() + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/slave/video.py b/slave/video.py index 87eaea8..159c076 100644 --- a/slave/video.py +++ b/slave/video.py @@ -8,12 +8,9 @@ class Video: self.x = x self.y = y - def setVideo(self, path): - self.path = path - - def start(self): + def start(self, path): - self.cap = cv2.VideoCapture(self.path) + self.cap = cv2.VideoCapture(path) # Check if camera opened successfully if (self.cap.isOpened()== False): print("Error opening video file") @@ -55,13 +52,13 @@ class Video: if __name__ == "__main__": video = Video(0, 0) - video.setVideo("sample-mp4-file.mp4") - x = multiprocessing.Process(target = video.start) + x = multiprocessing.Process(target = video.start, args=("slave/sample-mp4-file.mp4",)) x.start() time.sleep(2) x.terminate() 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() time.sleep(1) x.terminate() \ No newline at end of file