{"id":10,"date":"2021-06-22T22:17:33","date_gmt":"2021-06-22T14:17:33","guid":{"rendered":"http:\/\/www.tysql.com\/?p=10"},"modified":"2021-06-22T22:20:56","modified_gmt":"2021-06-22T14:20:56","slug":"python-mjpeg%e8%a7%86%e9%a2%91%e6%8e%a8%e6%b5%81","status":"publish","type":"post","link":"https:\/\/www.tysql.com\/index.php\/2021\/06\/22\/python-mjpeg%e8%a7%86%e9%a2%91%e6%8e%a8%e6%b5%81\/","title":{"rendered":"python mjpeg\u89c6\u9891\u63a8\u6d41"},"content":{"rendered":"\n<p><strong>\u6700\u8fd1\u60f3\u505a\u4e00\u4e2a\u7c7b\u4f3c\u4e91\u624b\u673a\u7684\u4e00\u4e2a\u4e1c\u897f,\u9700\u8981\u8fdc\u7a0b\u663e\u793a\u6a21\u62df\u5668\u5185\u7684\u5185\u5bb9,\u770b\u5230\u4e86\u8fd9\u4e2a,\u4f46\u662f\u76ee\u524d\u6b64\u9879\u76ee\u5e76\u6ca1\u6709\u91c7\u7528\u6b64\u65b9\u6cd5,\u56e0\u4e3a\u867d\u7136\u56fe\u50cf\u6548\u679c\u8fd8\u53ef\u4ee5,\u4f46\u662f\u5bf9\u5e26\u5bbd\u7684\u5360\u7528\u592a\u5927\u4e86,\u6ca1\u8fd9\u4e48\u5927\u7684\u4e0a\u4f20\u5e26\u5bbd,\u4ee3\u7801\u8fd8\u662f\u8bb0\u5f55\u4e0b.<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:false,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;darcula&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\">import time\nimport socket\n\ndef readImg(i):\n    file = open('Y:\/\/1.jpg', 'rb')\n    file_data = file.read()\n    file.close()\n    return file_data\n\ns = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\ns.bind(('0.0.0.0', 5888))\ns.listen(5)\nwhile 1:\n    c,a = s.accept()\n    data = c.recv(1024).decode()\n    if &quot;camera&quot; in data:\n        i = 0\n        header = b'HTTP\/1.1 220 OK\\r\\nContent-Type: multipart\/x-mixed-replace; boundary=frame\\r\\n\\r\\n'\n        c.sendall(header)\n        while 1:\n            body = readImg(str(i))\n            r = b'--frame\\r\\nContent-Type: image\/jpeg\\r\\n\\r\\n'+body\n            try:\n                c.sendall(r)\n            except Exception as e:\n                c.close()\n            i += 1\n            time.sleep(0.1)\n    else:\n        c.close()<\/pre><\/div>\n\n\n\n<p>\u8fd0\u884c\u8d77\u6765\u540e\u6253\u5f00\u6d4f\u89c8\u5668\u8bbf\u95ee&nbsp;http:\/\/127.0.0.1:5888\/camera&nbsp;\u5c31\u53ef\u4ee5\u770b\u5230\u6548\u679c<\/p>\n\n\n\n<p>B\u7ad9\u770b\u5230\u7684,\u539f\u89c6\u9891\u94fe\u63a5<a href=\"https:\/\/www.bilibili.com\/video\/BV1uU4y1Y7nD?from=search&amp;seid=5264842891449557674\">https:\/\/www.bilibili.com\/video\/BV1uU4y1Y7nD?from=search&amp;seid=5264842891449557674<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u60f3\u505a\u4e00\u4e2a\u7c7b\u4f3c\u4e91\u624b\u673a\u7684\u4e00\u4e2a\u4e1c\u897f,\u9700\u8981\u8fdc\u7a0b\u663e\u793a\u6a21\u62df\u5668\u5185\u7684\u5185\u5bb9,\u770b\u5230\u4e86\u8fd9\u4e2a,\u4f46\u662f\u76ee\u524d\u6b64\u9879\u76ee\u5e76\u6ca1\u6709\u91c7\u7528\u6b64\u65b9\u6cd5,\u56e0\u4e3a &hellip; <a href=\"https:\/\/www.tysql.com\/index.php\/2021\/06\/22\/python-mjpeg%e8%a7%86%e9%a2%91%e6%8e%a8%e6%b5%81\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">python mjpeg\u89c6\u9891\u63a8\u6d41<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-10","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/www.tysql.com\/index.php\/wp-json\/wp\/v2\/posts\/10","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tysql.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tysql.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tysql.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tysql.com\/index.php\/wp-json\/wp\/v2\/comments?post=10"}],"version-history":[{"count":1,"href":"https:\/\/www.tysql.com\/index.php\/wp-json\/wp\/v2\/posts\/10\/revisions"}],"predecessor-version":[{"id":11,"href":"https:\/\/www.tysql.com\/index.php\/wp-json\/wp\/v2\/posts\/10\/revisions\/11"}],"wp:attachment":[{"href":"https:\/\/www.tysql.com\/index.php\/wp-json\/wp\/v2\/media?parent=10"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tysql.com\/index.php\/wp-json\/wp\/v2\/categories?post=10"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tysql.com\/index.php\/wp-json\/wp\/v2\/tags?post=10"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}