2
I receive some Urls as parameter via MQTT, after extracting them I can execute the command for FFMPEG to record them with os.system. But it works for only one process, and I need to run N simultaneously.
I come from Java and I can’t imagine how to do it 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()
Does that help you? https://answall.com/q/290167/5878
– Woss
I will study for him, I did not understand how to pass the Urls (after all I will not always receive a fixed size) but it is a start. Thanks :)
– FearX
The biggest difference from what is in my answer to that other question suggested is that the method
call
of the subprocess waits for the subprocess called to end. Popen without other parameters starts the process in a S.O. parallel process and continues the execution of the Python code. In the suggested query, the author tries to leave things in parallel using "multiprocessing" and "threads" on the Python side, but it’s really not necessary.– jsbueno