基于ffmpeg采集摄像头推送rtp流
程序员文章站
2022-03-04 23:26:04
...
1.识别当前系统的摄像头
./ffmpeg -f avfoundation -list_devices true -i ""
显示以下列表,摄像头序号为0
[AVFoundation input device @ 0x7fe926d00dc0] AVFoundation video devices:
[AVFoundation input device @ 0x7fe926d00dc0] [0] USB摄像头
[AVFoundation input device @ 0x7fe926d00dc0] [1] Capture screen 0
[AVFoundation input device @ 0x7fe926d00dc0] AVFoundation audio devices:
[AVFoundation input device @ 0x7fe926d00dc0] [0] Unknown USB Audio Device
2.想看看摄像头支持什么样的分辨率、帧率
$ ./ffmpeg -f avfoundation -i "0"
ffmpeg version 4.2.2-tessus https://evermeet.cx/ffmpeg/ Copyright (c) 2000-2019 the FFmpeg developers
built with Apple clang version 11.0.0 (clang-1100.0.33.16)
configuration: --cc=/usr/bin/clang --prefix=/opt/ffmpeg --extra-version=tessus --enable-avisynth --enable-fontconfig --enable-gpl --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libfreetype --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libmysofa --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvmaf --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-version3 --pkg-config-flags=--static --disable-ffplay
libavutil 56. 31.100 / 56. 31.100
libavcodec 58. 54.100 / 58. 54.100
libavformat 58. 29.100 / 58. 29.100
libavdevice 58. 8.100 / 58. 8.100
libavfilter 7. 57.100 / 7. 57.100
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100
[avfoundation @ 0x7fbac7005600] Selected framerate (29.970030) is not supported by the device.
[avfoundation @ 0x7fbac7005600] Supported modes:
[avfoundation @ 0x7fbac7005600] [email protected][30.000030 30.000030]fps
[avfoundation @ 0x7fbac7005600] [email protected][25.000000 25.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][20.000000 20.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][15.000015 15.000015]fps
[avfoundation @ 0x7fbac7005600] [email protected][10.000000 10.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][5.000000 5.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][30.000030 30.000030]fps
[avfoundation @ 0x7fbac7005600] [email protected][25.000000 25.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][20.000000 20.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][15.000015 15.000015]fps
[avfoundation @ 0x7fbac7005600] [email protected][10.000000 10.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][5.000000 5.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][30.000030 30.000030]fps
[avfoundation @ 0x7fbac7005600] [email protected][25.000000 25.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][20.000000 20.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][15.000015 15.000015]fps
[avfoundation @ 0x7fbac7005600] [email protected][10.000000 10.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][5.000000 5.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][30.000030 30.000030]fps
[avfoundation @ 0x7fbac7005600] [email protected][25.000000 25.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][20.000000 20.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][15.000015 15.000015]fps
[avfoundation @ 0x7fbac7005600] [email protected][10.000000 10.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][5.000000 5.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][30.000030 30.000030]fps
[avfoundation @ 0x7fbac7005600] [email protected][25.000000 25.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][20.000000 20.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][15.000015 15.000015]fps
[avfoundation @ 0x7fbac7005600] [email protected][10.000000 10.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][5.000000 5.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][30.000030 30.000030]fps
[avfoundation @ 0x7fbac7005600] [email protected][25.000000 25.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][20.000000 20.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][15.000015 15.000015]fps
[avfoundation @ 0x7fbac7005600] [email protected][10.000000 10.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][5.000000 5.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][30.000030 30.000030]fps
[avfoundation @ 0x7fbac7005600] [email protected][25.000000 25.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][20.000000 20.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][15.000015 15.000015]fps
[avfoundation @ 0x7fbac7005600] [email protected][10.000000 10.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][5.000000 5.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][30.000030 30.000030]fps
[avfoundation @ 0x7fbac7005600] [email protected][25.000000 25.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][20.000000 20.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][15.000015 15.000015]fps
[avfoundation @ 0x7fbac7005600] [email protected][10.000000 10.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][5.000000 5.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][30.000030 30.000030]fps
[avfoundation @ 0x7fbac7005600] [email protected][25.000000 25.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][20.000000 20.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][15.000015 15.000015]fps
[avfoundation @ 0x7fbac7005600] [email protected][10.000000 10.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][5.000000 5.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][30.000030 30.000030]fps
[avfoundation @ 0x7fbac7005600] [email protected][25.000000 25.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][20.000000 20.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][15.000015 15.000015]fps
[avfoundation @ 0x7fbac7005600] [email protected][10.000000 10.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][5.000000 5.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][30.000030 30.000030]fps
[avfoundation @ 0x7fbac7005600] [email protected][25.000000 25.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][20.000000 20.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][15.000015 15.000015]fps
[avfoundation @ 0x7fbac7005600] [email protected][10.000000 10.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][5.000000 5.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][30.000030 30.000030]fps
[avfoundation @ 0x7fbac7005600] [email protected][25.000000 25.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][20.000000 20.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][15.000015 15.000015]fps
[avfoundation @ 0x7fbac7005600] [email protected][10.000000 10.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][5.000000 5.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][30.000030 30.000030]fps
[avfoundation @ 0x7fbac7005600] [email protected][25.000000 25.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][20.000000 20.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][15.000015 15.000015]fps
[avfoundation @ 0x7fbac7005600] [email protected][10.000000 10.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][5.000000 5.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][30.000030 30.000030]fps
[avfoundation @ 0x7fbac7005600] [email protected][25.000000 25.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][20.000000 20.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][15.000015 15.000015]fps
[avfoundation @ 0x7fbac7005600] [email protected][10.000000 10.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][5.000000 5.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][30.000030 30.000030]fps
[avfoundation @ 0x7fbac7005600] [email protected][25.000000 25.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][20.000000 20.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][15.000015 15.000015]fps
[avfoundation @ 0x7fbac7005600] [email protected][10.000000 10.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][5.000000 5.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][30.000030 30.000030]fps
[avfoundation @ 0x7fbac7005600] [email protected][25.000000 25.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][20.000000 20.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][15.000015 15.000015]fps
[avfoundation @ 0x7fbac7005600] [email protected][10.000000 10.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][5.000000 5.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][30.000030 30.000030]fps
[avfoundation @ 0x7fbac7005600] [email protected][25.000000 25.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][20.000000 20.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][15.000015 15.000015]fps
[avfoundation @ 0x7fbac7005600] [email protected][10.000000 10.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][5.000000 5.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][30.000030 30.000030]fps
[avfoundation @ 0x7fbac7005600] [email protected][25.000000 25.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][20.000000 20.000000]fps
[avfoundation @ 0x7fbac7005600] [email protected][15.000015 15.000015]fps
2.ffmepg采集摄像头,封装成rtp推送到远端pc
./ffmpeg -f avfoundation -framerate 30 -s 1280x720 -i "0" -vcodec libx264 -an -preset veryfast -f rtp rtp://192.168.158.44:5000
此时会打印一个sdp行,保存下来,在远端PC保存为SDP文件,用ffplay或者vlc打开,即可播放。
v=0
o=- 0 0 IN IP4 127.0.0.1
s=No Name
c=IN IP4 192.168.158.44
t=0 0
a=tool:libavformat 58.29.100
m=video 5000 RTP/AVP 96
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1