1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# coding:utf-8 # coding:utf-8 import cv2 import urllib2 import sys import time import threading import socket import re ''' 解决MJPG响应头的问题:https://www.eefocus.com/spencer/blog/13-11/300493_f17a8.html ''' ###全局变量### ifMJPGon = False BUFF_LENTH = 2048 #缓冲区大小 last_message = "" #最新一次的视频流数据,发给客户端 MJPG_head = ''' HTTP/1.0 200 OK Connection: close Server: MJPG-Streamer/0.2 Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0 Pragma: no-cache Expires: Mon, 3 Jan 2000 12:34:56 GMT Content-Type: multipart/x-mixed-replace;boundary=boundarydonotcross ''' ERR_notice = """ HTTP/1.1 200 OK Date: Fri, 22 May 2009 06:07:21 GMT Content-Type: text/html; charset=UTF-8 <html> <head> <meta charset="UTF-8"> </head> <title>welcome to Jamax</title> <body> <!--body goes here--> <div align="center" > <br> <br> <font size="8">Welcome To </font> <font size="8" color="#0000FF"> H</font> <font size="8" color="#00FF00">i</font> <font size="8" color="#FF0000">C</font> <font size="8" color="#0000FF">o</font> <font size="8" color="#00FF00">n</font> <br><br><br><br><br><br> <font size="2" color="#000000"></font> <br> <font size="4">This is the interface where the error occurred. Please check if the network connection and video streaming are enabled.</font> <br><br> </div> <br><br><br><br><br><br><br><br> <div align="right" > <font size="2" color="#000000">Welcome to HiCon. Do what you want, except for illegal activitiess.</font> <br> <font size="2" color="#000000">Copyright © 1998 - 2019 Jama Ma.All Rights Reserved</font> </div> </body> </html> """ ############# def get_stream(kk ,host): #声明使用全局变量 global last_message global BUFF_LENTH global ifMJPGon #host = "jama.mazhipeng.com:2613" #在这里记得修改IP,否则是无法调用的,刚刚浏览器输入的地址 hoststr = 'http://' + host + "/?action=stream" request = urllib2.Request(hoststr) request.add_header('User-agent', 'Internet Explorer') try: stream = urllib2.urlopen(request) print stream.code except : print "ERR:获取视频流错误,请检查网络配置和MJPG是否开启\n" exit(0) bytes='' ifMJPGon = True while True: bytes += stream.read(BUFF_LENTH) where_list = [m.start() for m in re.finditer("--boundarydonotcross", bytes)] if len(where_list)>=2: mutex.acquire() # 上锁保护共享数据 last_message = bytes[where_list[0]:where_list[1]] #切片 mutex.release() #print last_message bytes = bytes[where_list[1]:] def client(): # 等待外网使用者连接的套接字 visitor_conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # IPV4模式,TCP模式 visitor_conn.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) # 结束后立即释放端口 visitor_conn.bind(("", 6146)) visitor_conn.listen(5) # 最多可以连接的数目 while True: c, addr = visitor_conn.accept() # 建立客户端连接 print "NOTICE:链接~" threading.Thread(target=client_server, args=(True, c)).start() def client_server(kk, c): global last_message global ifMJPGon print ifMJPGon try: if ifMJPGon: c.sendall(MJPG_head) else: c.sendall(ERR_notice) c.close() except: return while True: mutex.acquire() # 上锁保护共享数据 message = last_message mutex.release() try: c.sendall(message) except: break print "发送结束" c.close() # 关闭连接 if __name__ == '__main__': # 默认是未上锁的状态 mutex = threading.Lock() #这个参数是视频流的URL if len(sys.argv)>1: host = sys.argv[1] threading.Thread(target=get_stream, args=(True, "127.0.0.1:8080",)).start() threading.Thread(target=client, args=()).start() while True: time.sleep(0.1) |
月份:2019年7月
更改ubuntu的登录信息
/var/run/motd.dynamic文件是修改上面的部分
/etc/motd 修改下面的部分
pip换源(十分好用)
https://blog.csdn.net/yuzaipiaofei/article/details/80891108
pip install 需要安装的包 -i https://pypi.tuna.tsinghua.edu.cn/simple
安装wordpress及注意事项
https://www.jianshu.com/p/800fe17f3de2
注意增加文件夹权限
https://my.oschina.net/yingximu/blog/1931050