-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
v1_EN_SampleTranscode2HLS
HLS需要h.264+aac,若符合这个要求可以按照Usage: HLS部署,若不符合这个要求则需要转码。
如何知道流是否是h264+aac编码:
-
Usage: HLS中的
Q&A
说明的问题。 - 看编码器的参数,FMLE可以选视频编码为vp6或者h264,音频一般为mp3/NellyMoser。,所以FMLE肯定推流是不符合要求的。
- 看SRS的日志,若显示
hls only support video h.264/avc codec. ret=601
,就明显说明是编码问题。
备注:在虚拟机上测试,一路流转码为aac,需要3%CPU,在物理机上可能稍好点。转码的开销比分发要大,实际应用需要考虑这个因素。
分发纯音频流参考:HLS audio only
Suppose the server ip is 192.168.1.170
Step 1, get SRS. For detail, read GIT
git clone https://github.com/winlinvip/simple-rtmp-server
cd simple-rtmp-server/trunk
Or update the exists code:
git pull
Step 2, build SRS. For detail, read Build
./configure --disable-all --with-ssl --with-hls --with-nginx --with-ffmpeg --with-transcode && make
第三步,启动分发hls(m3u8/ts)的nginx。 For detail, read HLS
sudo ./objs/nginx/sbin/nginx
备注:为了突出HLS的配置,我们在HLS的实例中没有使用SRS内置的HTTP Server,可以配置几行就可以不用nginx。参考:Usage: HTTP
备注:请确定nginx已经启动,可以访问http://192.168.1.170/nginx.html,若能看到nginx is ok
则没有问题。
第四步,编写SRS配置文件。 For detail, read HLS
Save bellow as config, or use conf/transcode2hls.audio.only.conf
:
# conf/transcode2hls.audio.only.conf
listen 1935;
max_connections 1000;
vhost __defaultVhost__ {
hls {
enabled on;
hls_path ./objs/nginx/html;
hls_fragment 10;
hls_window 60;
}
transcode {
enabled on;
ffmpeg ./objs/ffmpeg/bin/ffmpeg;
engine ff {
enabled on;
vcodec copy;
acodec libaacplus;
abitrate 45;
asample_rate 44100;
achannels 2;
aparams {
}
output rtmp://127.0.0.1:[port]/[app]?vhost=[vhost]/[stream]_[engine];
}
}
}
备注:这个配置使用只转码音频,因为视频是h.264符合要求,若需要全转码,参考HLS+Transcode
第五步,启动SRS。 For detail, read HLS
./objs/srs -c conf/transcode2hls.audio.only.conf
第六步,启动推流编码器。 For detail, read HLS
Use FFMPEG to publish stream:
for((;;)); do \
./objs/ffmpeg/bin/ffmpeg -re -i ./doc/source.200kbps.768x320.flv \
-vcodec copy -acodec copy \
-f flv -y rtmp://192.168.1.170/live/livestream; \
sleep 1; \
done
Or use FMLE to publish:
FMS URL: rtmp://192.168.1.170/live
Stream: livestream
生成的流地址为:
- RTMP流地址为(FMLE推流无HLS地址):
rtmp://192.168.1.170/live/livestream
- 转码后的RTMP流地址为:
rtmp://192.168.1.170/live/livestream_ff
- 转码后的HLS流地址为:
http://192.168.1.170/live/livestream_ff.m3u8
备注:因为FMLE推上来的音频有问题,不是aac,所以srs会报错(当然啦,不然就不用转码了)。这个错误可以忽略,srs是说,rtmp流没有问题,但是无法切片为hls,因为音频编码不对。没有关系,ffmpeg会转码后重新推一路流给srs。
备注:如何只对符合要求的流切hls?可以用vhost。默认的vhost不切hls,将转码后的流推送到另外一个vhost,这个vhost切hls。
第七步,观看RTMP流。 For detail, read HLS
RTMP url is: rtmp://192.168.1.170:1935/live/livestream_ff
User can use vlc to play the RTMP stream.
Or, use online SRS player: http://winlinvip.github.io/srs.release/trunk/research/players/srs_player.html?vhost=defaultVhost&autostart=true&server=192.168.1.170&app=live&stream=livestream_ff&port=1935
Note: Please replace all ip 192.168.1.170 to your server ip.
第八步,观看HLS流。 For detail, read HLS
HLS流地址为: http://192.168.1.170/live/livestream_ff.m3u8
可以使用VLC观看。
Note: Please replace all ip 192.168.1.170 to your server ip.
Winlin 2014.3
Welcome to SRS wiki!
Please select your language:
Please select your language:
Please select your language:
Please select your language:
Please select your language: