直接用html 的<video>缺點:
1,緩衝速度慢,徹底依賴網絡速度。
2,網絡終端的狀況下,會從新緩衝
在我美國服務器測試下,基本沒法觀看視頻。
而後我參考了一個flask 直流視頻播放,測試效果也很是不理想,參考:http://python.jobbole.com/80994/
單張圖片的加載方式,徹底沒法使用。(本機播放攝像頭仍是比較流暢的)
ffmpeg+nginx 實現視頻推流拉流:
缺點:直播,速度快,可是沒法拖動視頻等問題。
環境ubuntu 14.04.5 LTS \n \l
1,安裝nginx: 參考:https://www.vultr.com/docs/setup-nginx-rtmp-on-ubuntu-14-04html
apt-get install build-essential libpcre3 libpcre3-dev libssl-dev libtool zlib1g-dev openssl wget http://nginx.org/download/nginx-1.7.5.tar.gz wget https://github.com/arut/nginx-rtmp-module/archive/master.zip apt-get install unzip tar -zxvf nginx-1.7.5.tar.gz unzip master.zip cd nginx-1.7.5 ./configure --with-http_ssl_module --add-module=../nginx-rtmp-module-master make make instal service nginx start 查看使用的配置文件service nginx configtest 默認端口是80 若是被佔用,更換端口,修改配置文件,個人是/usr/local/nginx/conf/nginx.conf 中的http,server listen http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 8090; 配置文件中添加: rtmp { server { listen 1935; chunk_size 4000; # TV mode: one publisher, many subscribers application wstv{ # enable live streaming live on; # record first 1K of stream record all; record_path /tmp/av; record_max_size 1K; # append current timestamp to each flv record_unique on; # publish only from localhost # allow publish 127.0.0.1; # deny publish all; allow play all; } }} 重啓nginx,沒有報錯則正常。 2,安裝。 sudo add-apt-repository ppa:kirillshkrogalev/ffmpeg-next sudo apt-get update sudo apt-get install ffmpeg 安裝成功以後,能夠把mp4 轉換成flv ,這樣會快些,可是畫面質量有所降低。 ffmpeg -i "video.mp4 " -y -ab 32 -ar 22050 -qscale 10 -s 640*480 -r 15 /opt/a.flv 5.推流: 執行:ffmpeg -re -i a.flv -vcodec libx264 -acodec aac -strict -2 -f flv rtmp://localhost:1935/wstv/home 沒有報錯則正常 6,拉流,在網上下載一個VLC media 添加網絡串流。rtmp://xx.xx.xx.xx:1935/wstv/home 點擊播放
簡單點,有人作好了docker https://hub.docker.com/r/datarhei/nginx-rtmp/python