I get some URLs as a parameter via MQTT, after extracting them I run the command for the FFMPEG to write them to the .system. But this works for just one process, and I need to run N simultaneously.
I come from Java and I can not figure out how to do this in Python ...
import paho.mqtt.client as paho
import json
import os
def on_message(client, userdata, message):
content = str(message.payload.decode("utf-8"))
conversor(content)
def on_connect(client, userdata, flags, rc):
client.subscribe("cameras/gravacao")
def on_disconnect():
connect_to_mqtt()
def connect_to_mqtt():
client = paho.Client("id")
client.username_pw_set("", "")
client.on_connect = on_connect
client.on_disconnect = on_disconnect
client.on_message = on_message
client.connect("localhost", 1883, 60)
client.loop_forever()
def conversor(content):
data = json.loads(content)
for n in range(data.get("videos")):
os.system("ffmpeg -i " + data.get("remote_urls")[n]['url'] + "-acodec copy -vcodec copy "
"/home/user/Vídeos/output.mp4")
connect_to_mqtt()