centos使用ffmpeg+srs实现笔记本电脑摄像头推流监控

一、安装ffmpeg

1、包管理安装或者二进制编译安装(比较慢)都可以

[root@localhost ~]# ffmpeg -version
ffmpeg version 4.1.6 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 7.3.0 (GCC)
configuration: 
libavutil      56. 22.100 / 56. 22.100
libavcodec     58. 35.100 / 58. 35.100
libavformat    58. 20.100 / 58. 20.100
libavdevice    58.  5.100 / 58.  5.100
libavfilter     7. 40.101 /  7. 40.101
libswscale      5.  3.100 /  5.  3.100
libswresample   3.  3.100 /  3.  3.100

2、使用摄像头

摄像头设备都在/dev目录下,自行甄别,也有的是usb摄像头的

[root@localhost ~]# ffprobe /dev/video0

二、使用容器化srs(可跨架构x86,arm64都可以)

这边我就将其后台运行并且--restart=always

docker run -d  -it -p 1935:1935 -p 1985:1985 -p 8080:8080 --restart=always    registry.cn-hangzhou.aliyuncs.com/ossrs/srs:4 ./objs/srs -c conf/docker.conf 

可以看到暴露的服务端口,可以登录到ip:8080去网页控制台查看详情

[root@localhost ~]# docker ps -a
CONTAINER ID        IMAGE                                           COMMAND                  CREATED             STATUS              PORTS                                                                                         NAMES
ee0a196805aa        registry.cn-hangzhou.aliyuncs.com/ossrs/srs:4   "./objs/srs -c conf/…"   11 hours ago        Up 36 minutes       0.0.0.0:1935->1935/tcp, 0.0.0.0:1985->1985/tcp, 8000/udp, 0.0.0.0:8080->8080/tcp, 10080/udp   eager_ramanujan

三、开始推流

[root@localhost ~]# ffmpeg -r 30  -i /dev/video0 -vcodec flv  -max_delay 100 -f flv -g 5 -b 7000000 rtmp://localhost/live/livestream
ffmpeg version 4.1.6 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 7.3.0 (GCC)
  configuration: 
  libavutil      56. 22.100 / 56. 22.100
  libavcodec     58. 35.100 / 58. 35.100
  libavformat    58. 20.100 / 58. 20.100
  libavdevice    58.  5.100 / 58.  5.100
  libavfilter     7. 40.101 /  7. 40.101
  libswscale      5.  3.100 /  5.  3.100
  libswresample   3.  3.100 /  3.  3.100
Input #0, video4linux2,v4l2, from '/dev/video0':
  Duration: N/A, start: 52353.546701, bitrate: 124416 kb/s
    Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 960x540, 124416 kb/s, 15 fps, 15 tbr, 1000k tbn, 1000k tbc
Please use -b:a or -b:v, -b is ambiguous
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> flv1 (flv))
Press [q] to stop, [?] for help
Output #0, flv, to 'rtmp://localhost/live/livestream':
  Metadata:
    encoder         : Lavf58.20.100
    Stream #0:0: Video: flv1 (flv) ([2][0][0][0] / 0x0002), yuv420p, 960x540, q=2-31, 7000 kb/s, 30 fps, 1k tbn, 30 tbc
    Metadata:
      encoder         : Lavc58.35.100 flv
    Side data:
      cpb: bitrate max/min/avg: 0/0/7000000 buffer size: 0 vbv_delay: -1
frame= 2079 fps= 15 q=2.0 size=   30437kB time=00:01:09.26 bitrate=3599.7kbits/s speed=0.497x    

然后打开srs的web控制台
点击RTC推流

四、使用vlc播放视频流

posted @ 2022-10-27 10:53  带着泥土  阅读(424)  评论(1)    收藏  举报