reference http://blogger.gtwang.org/2015/03/raspberry-pi-nginx-rtmp-server-live-streaming.html
需要的環境
apt-get update
apt-get -y install nginx
apt-get -y remove nginx
apt-get clean
sudo rm -rf /etc/nginx/*
apt-get install -y curl build-essential libpcre3-dev libpcre++-dev zlib1g-dev libcurl4-openssl-dev libssl-dev
編譯安裝
建編譯目錄nginx_src
cd 某個目錄底下/nginx_src
git clone https://github.com/arut/nginx-rtmp-module.git
git clone https://github.com/nginx/nginx.git
cd 某個目錄底下/nginx_src/nginx
./auto/configure --prefix=/串流的根目錄 --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --pid-path=/var/run/nginx.pid --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_ssl_module --without-http_proxy_module --add-module=某個目錄底下/nginx_src/nginx-rtmp-module
make
make install
設定
編輯 /etc/nginx/nginx.conf 加入
rtmp {
server {
listen 1935;
ping 30s;
notify_method get;
application rtmp {
live on;
}
}
}
串流的UI
mkdir 某個目錄底下/strobe_src
cd 某個目錄底下/strobe_src
wget http://downloads.sourceforge.net/project/smp.adobe/Strobe Media Playback 1.6 Release (source and binaries)/StrobeMediaPlayback_1.6.328-full.zip
unzip StrobeMediaPlayback_1.6.328-full.zip
cp -r for\ Flash\ Player\ 10.1 /串流的根目錄/html/strobe
編輯 /串流的根目錄/html/index.html
<!DOCTYPE html>
<html>
<head>
<title>Live Streaming</title>
<!-- strobe -->
<script type="text/javascript" src="strobe/lib/swfobject.js"></script>
<script type="text/javascript">
var parameters = {
src: "rtmp://{pi_address}/rtmp/live",
autoPlay: false,
controlBarAutoHide: false,
playButtonOverlay: true,
showVideoInfoOverlayOnStartUp: true,
optimizeBuffering : false,
initialBufferTime : 0.1,
expandedBufferTime : 0.1,
minContinuousPlayback : 0.1,
poster: "images/poster.png"
};
swfobject.embedSWF(
"strobe/StrobeMediaPlayback.swf"
, "StrobeMediaPlayback"
, 1024
, 768
, "10.1.0"
, "strobe/expressInstall.swf"
, parameters
, {
allowFullScreen: "true"
}
, {
name: "StrobeMediaPlayback"
}
);
</script>
</head>
<body>
<div id="StrobeMediaPlayback"></div>
</body>
</html>
影像軟解
使用 avconv 製作影像串流
安裝 libav-tools 套件:
apt-get install libav-tools
插上 USB 網路攝影機之後
avconv -f video4linux2 -r 24 -i /dev/video0 -f flv rtmp://localhost:1935/rtmp/live
影像硬解
使用 GStreamer 製作影像串流
安裝 GStreamer:
apt-get install gstreamer1.0-tools
插上 USB 網路攝影機之後
gst-launch-1.0 -v v4l2src ! 'video/x-raw, width=640, height=480, framerate=30/1' ! queue ! videoconvert ! omxh264enc ! h264parse ! flvmux ! rtmpsink location='rtmp://localhost/rtmp/live live=1'