{"id":717,"date":"2022-12-15T17:16:22","date_gmt":"2022-12-15T09:16:22","guid":{"rendered":"http:\/\/wordpress.loc\/?p=717"},"modified":"2022-12-15T17:16:50","modified_gmt":"2022-12-15T09:16:50","slug":"esp32_ch2-14","status":"publish","type":"post","link":"https:\/\/www.nmking.io\/index.php\/2022\/12\/15\/717\/","title":{"rendered":"RTSP ESP32CAM qnap\u76e3\u8996\u5668 \u9304\u5f71\u6e2c\u8a66"},"content":{"rendered":"\n<figure class=\"wp-block-pullquote\"><blockquote><p>\u6700\u8fd1\u6709\u4e00\u4f4dESP32\u611b\u73a9\u7fa4\u7d44\u7684\u7db2\u53cbPO\u4e86\u4e00\u7bc7\u628aESP32\u6539\u76e3\u8996\u5668\u5e38\u7528\u7684RTSP\u5354\u5b9a\uff0c\u9019\u6a23\u5c31\u53ef\u4ee5\u63a5\u4e0a\u6211\u5bb6\u7684QNAP\u505a\u9577\u671f\u76e3\u8996\u9304\u5f71\u4e86\uff0c\u90a3\u5c31\u4f86\u6e2c\u8a66\u770b\u770b\u3002<\/p><\/blockquote><\/figure>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>\u6211\u7684ESP32\u5be6\u505a\u66f8\u7c4d\uff1a<a rel=\"noreferrer noopener\" href=\"https:\/\/www.nmking.io\/index.php\/2022\/11\/10\/esp32_ch1-2\/\" target=\"_blank\">\u6211\u51fa\u66f8\u4e86 ESP32 \u7269\u806f\u7db2\u5c08\u984c<\/a><br>\u535a\u5ba2\u4f86\u7db2\u5740\uff1a<a rel=\"noreferrer noopener\" href=\"https:\/\/www.books.com.tw\/products\/0010901195\" target=\"_blank\">https:\/\/www.books.com.tw\/products\/0010901195<\/a><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"htoc-\">\u5be6\u505a\u8aaa\u660e<\/h2>\n\n\n\n<p>\u4ee5\u5f80\u5229\u7528ESP32CAM\u90fd\u53ea\u662f\u77ed\u6642\u9593\u6e2c\u8a66\u4e00\u4e0b\uff0c\u4e3b\u8981\u662f\u56e0\u70ba\u662fWebserver\uff0c\u8981\u81ea\u5df1\u958b\u700f\u89bd\u5668\u9023\u9032\u53bb\u624d\u80fd\u770b\uff0c\u6700\u8fd1\u6709\u4e00\u4f4dESP32\u611b\u73a9\u7fa4\u7d44\u7684\u7db2\u53cbPO\u4e86\u4e00\u7bc7\u628aESP32\u6539\u76e3\u8996\u5668\u5e38\u7528\u7684RTSP\u5354\u5b9a\uff0c\u9019\u6a23\u5c31\u53ef\u4ee5\u63a5\u4e0a\u6211\u5bb6\u7684QNAP\u505a\u9577\u671f\u76e3\u8996\u9304\u5f71\u4e86\uff0c\u90a3\u5c31\u4f86\u6e2c\u8a66\u770b\u770b\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"htoc-1\">\u5be6\u505a\u65b9\u6cd5<\/h2>\n\n\n\n<p>\u9996\u5148\u9023\u7dda\u5230\u51fd\u5f0f\u5eab\u7db2\u5740\uff1a<a href=\"https:\/\/github.com\/geeksville\/Micro-RTSP\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/github.com\/geeksville\/Micro-RTSP<\/a><\/p>\n\n\n\n<p>\u4e0b\u8f09\u6253\u5305zip\u5f8c\uff0c\u5229\u7528arduino\u5167\u7684\u529f\u80fd\u8868\/\u8349\u7a3f\u78bc\/\u532f\u5165\u51fd\u5f0f\u5eab\/\u52a0\u5165.zip\u6a94\u6848\u65b9\u5f0f\u5b89\u88dd\u672c\u51fd\u5f0f\u5eab\u3002<\/p>\n\n\n\n<p>\u5728github\u4e2d\u7684\u7bc4\u4f8b\u7a0b\u5f0f\u5305\u542bLCD\u7b49\u914d\u4ef6\uff0c\u6211\u90fd\u5148\u522a\u9664\uff0c\u7cbe\u7c21\u5f8c\u7684\u7a0b\u5f0f\u5982\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;WiFi.h>\n#include &lt;WebServer.h>\n#include &lt;WiFiClient.h>\n#include \"OV2640.h\"\n#include \"SimStreamer.h\"\n#include \"OV2640Streamer.h\"\n#include \"CRtspSession.h\"\n\nchar *ssid = \"ssid\";        \/\/ Put your SSID here\nchar *password = \"password\";      \/\/ Put your PASSWORD here\n\nWebServer server(80);\nWiFiServer rtspServer(554);\nOV2640 cam;\nCStreamer *streamer;\n\n\/\/mjpeg\u4e32\u6d41\nvoid handle_jpg_stream(void)\n{\n  WiFiClient client = server.client();\n  String response = \"HTTP\/1.1 200 OK\\r\\n\";\n  response += \"Content-Type: multipart\/x-mixed-replace; boundary=frame\\r\\n\\r\\n\";\n  server.sendContent(response);\n\n  while (1)\n  {\n    cam.run();\n    if (!client.connected())\n      break;\n    response = \"--frame\\r\\n\";\n    response += \"Content-Type: image\/jpeg\\r\\n\\r\\n\";\n    server.sendContent(response);\n\n    client.write((char *)cam.getfb(), cam.getSize());\n    server.sendContent(\"\\r\\n\");\n    if (!client.connected())\n      break;\n  }\n}\n\n\/\/\u975c\u614b\u5f71\u50cf\nvoid handle_jpg(void)\n{\n  WiFiClient client = server.client();\n  cam.run();\n  if (!client.connected())\n  {\n    return;\n  }\n  String response = \"HTTP\/1.1 200 OK\\r\\n\";\n  response += \"Content-disposition: inline; filename=capture.jpg\\r\\n\";\n  response += \"Content-type: image\/jpeg\\r\\n\\r\\n\";\n  server.sendContent(response);\n  client.write((char *)cam.getfb(), cam.getSize());\n}\n\n\/\/\u932f\u8aa4\u8655\u7406\nvoid handleNotFound() {\n  String message = \"Server is running!\\n\\n\";\n  message += \"URI: \";\n  message += server.uri();\n  message += \"\\nMethod: \";\n  message += (server.method() == HTTP_GET) ? \"GET\" : \"POST\";\n  message += \"\\nArguments: \";\n  message += server.args();\n  message += \"\\n\";\n  server.send(200, \"text\/plain\", message);\n}\n\n\/\/WiFi\u9023\u7dda\nvoid WifiConnecte() {\n  \/\/\u958b\u59cbWiFi\u9023\u7dda\n  WiFi.begin(ssid, password);\n  while (WiFi.status() != WL_CONNECTED) {\n    delay(500);\n    Serial.print(\".\");\n  }\n  Serial.println(\"WiFi\u9023\u7dda\u6210\u529f\");\n  Serial.print(\"IP Address:\");\n  Serial.println(WiFi.localIP());\n}\n\nvoid setup()\n{\n  Serial.begin(115200);\n  \/\/\u8a2d\u5b9a\u5f71\u50cf\u5927\u5c0f\uff1aUXGA(1600x1200),SXGA(1280x1024),XGA(1024x768),SVGA(800x600),VGA(640x480),CIF(400x296),QVGA(320x240),HQVGA(240x176),QQVGA(160x120)\n  esp32cam_aithinker_config.frame_size = FRAMESIZE_UXGA;\n  esp32cam_aithinker_config.jpeg_quality = 10;\n  cam.init(esp32cam_aithinker_config);\n  \/\/\u958b\u59cbWiFi\u9023\u7dda\n  WifiConnecte();\n  \n  server.on(\"\/\", HTTP_GET, handle_jpg_stream);\n  server.on(\"\/jpg\", HTTP_GET, handle_jpg);\n  server.onNotFound(handleNotFound);\n  server.begin();\n  rtspServer.begin();\n  streamer = new OV2640Streamer(cam);\/\/\u555f\u52d5\u670d\u52d9\n  Serial.println(\"WiFi connected\");\n  Serial.print(\"Use 'http:\/\/\");\n  Serial.print(WiFi.localIP());\n  Serial.println(\"\/' to watch mjpeg stream\");\n  Serial.print(\"Use 'http:\/\/\");\n  Serial.print(WiFi.localIP());\n  Serial.println(\"\/jpg' to see still jpg\");\n  Serial.print(\"Use RTSP:'\");\n  Serial.print(WiFi.localIP());\n  Serial.println(\"', URL:'\/mjpeg\/1' and port:554 to start rtsp stream\");\n}\n\nvoid loop() {\n  if (WiFi.status() != WL_CONNECTED) {\n    WifiConnecte();\n  }\n  server.handleClient();\n  uint32_t msecPerFrame = 100;\n  static uint32_t lastimage = millis();\n  \/\/ If we have an active client connection, just service that until gone\n  streamer->handleRequests(0); \/\/ we don't use a timeout here,\n  \/\/ instead we send only if we have new enough frames\n  uint32_t now = millis();\n  if (streamer->anySessions()) {\n    if (now > lastimage + msecPerFrame || now &lt; lastimage) { \/\/ handle clock rollover\n      streamer->streamImage(now);\n      lastimage = now;\n\n      \/\/ check if we are overrunning our max frame rate\n      now = millis();\n      if (now > lastimage + msecPerFrame) {\n        printf(\"warning exceeding max frame rate of %d ms\\n\", now - lastimage);\n      }\n    }\n  }\n  WiFiClient rtspClient = rtspServer.accept();\n  if (rtspClient) {\n    Serial.print(\"client: \");\n    Serial.print(rtspClient.remoteIP());\n    Serial.println();\n    streamer->addSession(rtspClient);\n  }\n}\n\n<\/code><\/pre>\n\n\n\n<p>\u7a0b\u5f0f\u71d2\u9304\u5b8c\u7562\u4e4b\u5f8c\uff0c\u5c31\u958b\u901a\u5169\u500b\u529f\u80fd1.web mjpeg\u4e32\u6d41 \u53ca 2.RTSP\u4e32\u6d41\uff0c\u76ee\u524d\u7684\u7a0b\u5f0f\u5169\u8005\u540c\u6642\u53ea\u80fd\u6709\u4e00\u500b\u9023\u5165\uff0c\u4f7f\u7528web\u9023\u4e0a\u5f8c\uff0crtsp\u6703\u81ea\u5df1\u65b7\u6389\uff0c\u7576web\u95dc\u9589\u5f8c\uff0crtsp\u6703\u91cd\u65b0\u555f\u52d5\u3002<\/p>\n\n\n\n<p>\u7a0b\u5f0f\u555f\u52d5\u5f8c\uff0c\u5e8f\u5217\u57e0\u7684\u8a0a\u606f\u5982\u4e0b\uff0c\u6703\u901a\u77e5\u60a8\u7684ESP32\u53d6\u5f97\u7684IP\uff0c\u9084\u6709\u6307\u793a\u8981\u5982\u4f55\u67e5\u770bstream\u53ca\u8a2d\u5b9aRTSP<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1603390022-37163904-g_n.png?resize=843%2C478&#038;ssl=1\" alt=\"\" width=\"843\" height=\"478\"\/><figcaption class=\"wp-element-caption\">\u555f\u52d5\u6210\u529f\u5e8f\u5217\u57e0\u756b\u9762<\/figcaption><\/figure>\n\n\n\n<p>\u6211\u5011\u53ef\u4ee5\u5148\u7528WEB\u9023\u770b\u770b\u756b\u9762\u6b63\u4e0d\u6b63\u5e38\uff0c\u5167\u5bb9\u4e0d\u50cf\u9810\u8a2d\u7684CameraWebServer\u7bc4\u4f8b\u90a3\u9ebc\u591a\u529f\u80fd\uff0c\u5c31\u53ea\u6709\u4e00\u500b\u756b\u9762\u505a\u4e32\u6d41\u800c\u5df2\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1603388464-2331187507-g_n.png?resize=838%2C694&#038;ssl=1\" alt=\"\" width=\"838\" height=\"694\"\/><\/figure>\n\n\n\n<p>\u90a3\u9ebc\u5982\u679c\u4f60\u6709synology\u6216qnap\u9019\u985e\u7684\u6a5f\u5668\u8a72\u5982\u4f55\u8a2d\u5b9a\u9304\u5f71\u529f\u80fd\u5462\uff1f<\/p>\n\n\n\n<p>\u6211\u9019\u88e1\u4ee5qnap\u7684Surveillance Station\u70ba\u4f8b<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1603388592-3657057674-g.png?w=1290&#038;ssl=1\" alt=\"\"\/><figcaption class=\"wp-element-caption\">Surveillance Station\u76e3\u63a7\u8edf\u9ad4<\/figcaption><\/figure>\n\n\n\n<p>1.\u958b\u555fSurveillance Station<\/p>\n\n\n\n<p>2.\u65b0\u589e\u4e00\u53f0\u651d\u5f71\u6a5f\uff0c\u9078\u64c7\u4ee5\u4e0b\u53c3\u6578<br>\u5ee0\u724c\uff1aGeneric Model<br>\u6a5f\u578b\uff1aGeneric JPEG<br>URL\uff1a\/mjpeg\/1<br>\u540d\u7a31\uff1a\u4efb\u610f\u8f38\u5165\uff0c\u4f8b\u5982\u5009\u5eab\u3001\u66f8\u623f<br>\u7db2\u8def\u4f4d\u7f6e\uff1a\u53d6\u5f97\u7684IP<br>\u57e0\u865f\uff1a554<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1603390270-3176401036-g_n.png?resize=841%2C530&#038;ssl=1\" alt=\"\" width=\"841\" height=\"530\"\/><figcaption class=\"wp-element-caption\">\u651d\u5f71\u6a5f\u53c3\u6578\u8a2d\u5b9a<\/figcaption><\/figure>\n\n\n\n<p>\u89c0\u5bdf\u9023\u7dda\u72c0\u6cc1\u6b63\u5e38<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1603390342-2980655657-g_n.png?resize=840%2C417&#038;ssl=1\" alt=\"\" width=\"840\" height=\"417\"\/><\/figure>\n\n\n\n<p>\u5229\u7528qnap\u7684\u64ad\u653e\u5668\u4e5f\u5f88\u6b63\u5e38<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1603390370-976920699-g_n.png?resize=841%2C428&#038;ssl=1\" alt=\"\" width=\"841\" height=\"428\"\/><\/figure>\n\n\n\n<p>\u9304\u5f71\u90e8\u4efd\u4e5f\u76f8\u7576\u6b63\u5e38\uff0c\u90fd\u6c92\u6709\u65b7\u7dda<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1603390581-3496549527-g_n.png?resize=842%2C431&#038;ssl=1\" alt=\"\" width=\"842\" height=\"431\"\/><\/figure>\n\n\n\n<p>\u7b46\u8005\u5c07ESP32CAM\u958b\u555f\u7d04\u4e00\u9031\uff0c\u9304\u5f71\u4e00\u76f4\u90fd\u6b63\u5e38\u3002\u4e0d\u904e\u767c\u73feRTSP\u7684fps\u6bd4http\u4f86\u7684\u5feb\uff0c\u800c\u4e00\u9031\u6e2c\u8a66\u4e0b\u4f86\uff0cESP32\u6478\u8d77\u4f86\u4e5f\u53ea\u662f\u6eab\u6eab\u7684\u800c\u5df2\uff0c\u4e26\u7121\u767c\u71d9\u3002<\/p>\n\n\n\n<p>\u82e5\u8981\u4f7f\u7528Python\u8b80\u53d6rtsp\u5f71\u50cf\u505aAI\u8fa8\u8b58\uff0c\u53ef\u4ee5\u53c3\u8003\u672c\u7bc7\uff1a<a href=\"https:\/\/www.nmking.io\/index.php\/2022\/12\/15\/esp32_ch2-13\/\">\u4f7f\u7528Python\u8b80\u53d6ESP32CAM\u7684RTSP\u4e32\u6d41<\/a><\/p>\n\n\n\n<p>\u4ee5\u4e0a\u5831\u544a<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u6709\u4e00\u4f4dESP32\u611b\u73a9\u7fa4\u7d44\u7684\u7db2\u53cbPO\u4e86\u4e00\u7bc7\u628aESP32\u6539\u76e3\u8996\u5668\u5e38\u7528\u7684RTSP\u5354\u5b9a\uff0c\u9019\u6a23\u5c31\u53ef\u4ee5\u63a5\u4e0a\u6211\u5bb6\u7684QNA [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[],"class_list":["post-717","post","type-post","status-publish","format-standard","hentry","category-esp32"],"blocksy_meta":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/posts\/717","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/comments?post=717"}],"version-history":[{"count":1,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/posts\/717\/revisions"}],"predecessor-version":[{"id":720,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/posts\/717\/revisions\/720"}],"wp:attachment":[{"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/media?parent=717"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/categories?post=717"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/tags?post=717"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}