diff --git a/bash/stream.sh b/bash/stream.sh index b24d370..bc12249 100644 --- a/bash/stream.sh +++ b/bash/stream.sh @@ -1,3 +1,3 @@ #!/bin/bash device_name=`cat /home/pi/device_name` -/usr/bin/ffmpeg -rtsp_transport tcp -re -i rtsp://admin:123456@192.168.0.123:554/mpeg4 -c copy -preset fast -r 20 -s 1280x720 -flvflags no_duration_filesize -f rtsp -rtsp_transport tcp rtsp://47.108.186.87:554/live/$device_name \ No newline at end of file +/usr/bin/ffmpeg -rtsp_transport tcp -re -i rtsp://admin:123456@192.168.0.123:554/mpeg4 -c copy -preset fast -r 20 -crf 35 -s 1280x720 -flvflags no_duration_filesize -f rtsp -rtsp_transport tcp rtsp://47.108.186.87:554/live/$device_name \ No newline at end of file diff --git a/test.py b/test.py new file mode 100644 index 0000000..ed4d050 --- /dev/null +++ b/test.py @@ -0,0 +1,68 @@ +import json +import time + +import uvicorn +from fastapi import FastAPI +import paho.mqtt.client as mqtt + +app = FastAPI() + +broker = 'mqtt.lihaink.cn' +port = 1883 +subscribe_topic = 'info_dev_4' +username = 'lihai_lot_land_1' +password = 'lihai_lot_land_1' + + +class MQTTClient: + def __init__(self, broker, port, topic, username, password): + self.broker = broker + self.port = port + self.topic = topic + self.username = username + self.password = password + # 千万不要指定client_id 不然死翘翘 + self.client = mqtt.Client() + self.client.username_pw_set(self.username, self.password) + self.client.on_connect = self.on_connect + + def on_connect(self, client, userdata, flags, rc): + if rc == 0: + self.client.subscribe(self.topic) + + def push(self): + self.client.publish("lihai_lot_walnutpi_dev_4", payload=json.dumps({"msg": "push_stream"}, ensure_ascii=False), + qos=0) + + def close(self): + self.client.publish("lihai_lot_walnutpi_dev_4", payload=json.dumps({"msg": "close_stream"}, ensure_ascii=False), + qos=0) + + def start(self): + self.client.connect(self.broker, self.port) + + +@app.get("/push_stream") +def push_stream(): + try: + MQTT.start() + MQTT.push() + except Exception as e: + print(e) + pass + + +@app.get("/close_stream") +def close_stream(): + try: + MQTT.start() + MQTT.close() + except Exception as e: + print(e) + pass + + +if __name__ == '__main__': + MQTT = MQTTClient(broker, port, subscribe_topic, username, password) + + uvicorn.run(app, host="127.0.0.1", port=8000)