您的位置:首页 > 资讯

直播APP短视频软件搭建RTMP和HLS流媒体服务

日期:2024-08-29 17:03    点击:38

流媒体

HLS/RTMP是两种成熟而且广泛应用的流媒体分发方式。 这也是我们在开发直播APP或短视频软件需要搭建的服务之一

RTMP指Adobe的RTMP(Realtime Message Protocol),广泛应用于低延时直播,也是编码器和服务器对接的实际标准协议,在PC(Flash)上有最佳观看体验和最佳稳定性。

HLS指Apple的HLS(Http Live Streaming),本身就是Live(直播)的,不过Vod(点播)也能支持。HLS是Apple平台的标准流媒体协议,和RTMP在PC上一样支持得天衣无缝。

使用nginx-rtmp模块

使用docker镜像启动容器

		
  1. docker run -itd --name rtmp-002 -p 1935:1935 -p 80:80 alfg/nginx-rtmp:latest

使用ffmpeg推流:

		
  1. ffmpeg -re -i test.flv -c copy -f flv rtmp://localhost:1935/stream/test
  2. #ffmpeg test source
  3. ffmpeg -r 30 -f lavfi -i testsrc -vf scale=1280:960 -vcodec libx264 -profile:v baseline -pix_fmt yuv420p \ -f flv rtmp://localhost/live/test

循环推流:

		
  1. You should be able to use the -stream_loop
  2. -1 flag before the input (-i):
  3. ffmpeg -threads 2 -re -fflags +genpts -stream_loop -1 -i ./test.mp4 -c copy ./test.m3u8
  4. The -fflags
  5. +genpts will regenerate the pts timestamps so it loops smoothly, otherwise the time sequence will be incorrect as it loops.
  6. FFmpeg >= 2.8.4 is required in this case.

使用播放器播放流媒体

Http flv点播服务


编译nginx时添加—with-http_flv_module 启用flv模块.

添加nginx配置:

		
  1. server {
  2. listen 80;
  3. server_name fze.net localhost;
  4. root /video;
  5. limit_rate_after 5m; #5分钟后限速
  6. limit_rate 256k; #限速为256kb/s
  7. location ~ \.flv {
  8. flv; }
  9. location ~ \.mp4 {
  10. mp4;
  11. }

  12. }

售前客服
咨询电话
点击查看联系方式