1. 查看机器上所有设备
ffmpeg -devices
ffmpeg version N-93466-g681957b88d Copyright (c) 2000-2019 the FFmpeg developers
built with Apple LLVM version 10.0.0 (clang-1000.11.45.5)
Devices:
D. = Demuxing supported
.E = Muxing supported
--
D avfoundation AVFoundation input device 「摄像头」
D lavfi Libavfilter virtual input device
E sdl,sdl2 SDL2 output device
2. 查看device信息
ffmpeg -f avfoundation -list_devices true -i ""
[AVFoundation input device @ 0x7f914561f100] AVFoundation video devices:
[AVFoundation input device @ 0x7f914561f100] [0] FaceTime HD Camera
[AVFoundation input device @ 0x7f914561f100] [1] Capture screen 0
[AVFoundation input device @ 0x7f914561f100] AVFoundation audio devices:
[AVFoundation input device @ 0x7f914561f100] [0] Built-in Microphone
3. 测试捕捉摄像头数据保存到文件
ffmpeg -f avfoundation -framerate 30 -i "0" -target pal-vcd [输出文件.mpg]
4. 推送摄像头数据到远程服务器
ffmpeg -f avfoundation -framerate 30 -video_size 320x240 -i "0" -vcodec libx264 -acodec libfaac -f flv rtmp://116.196.19.33/test
5. 使用vlc播放器即可播放 rtmp://116.196.19.33/test
参考命令
ffmpeg -f avfoundation -framerate 30 -video_size 640x480 -i "0" -vcodec libx264 -preset ultrafast -acodec libfaac -f flv rtmp://localhost:1935/zbcs/room
ffmpeg -f avfoundation -framerate 30 -video_size 640x480 -i "0" -vcodec libx264 -acodec libfaac -f flv rtmp://localhost:1935/zbcs/room
ffmpeg -f avfoundation -framerate 30 -video_size 640x480 -i "0" \-c:v libx264 -preset ultrafast -acodec libfaac -f flv rtmp://localhost:1935/zbcs/room
ffmpeg -f avfoundation -framerate 30 -video_size 640x480 -i "0" -vcodec libx264 -preset ultrafast -acodec libfaac -f flv rtmp://localhost:1935/zbcs/room
ffmpeg -f avfoundation -framerate 30 -video_size 640x480 -i "0" -pixel_format nv12 -preset ultrafast -acodec libfaac -f flv rtmp://localhost:1935/zbcs/room
ffmpeg -f avfoundation -framerate 30 -video_size 1280x720 -i "0" -vf format=yuv444p,crop=426:240:507:339 -preset ultrafast -acodec libfaac -f flv rtmp://localhost:1935/zbcs/room
ffmpeg -f avfoundation -capture_cursor 1 -i 1:0 -r 30000/1001 -s 1280x800 -vsync 2 -c:v libvpx-vp9 -c:a libopus -b:v 1M -b:a 128K capture.webm -f flv rtmp://localhost:1935/zbcs/room
ffmpeg -f avfoundation -pixel_format uyvy422 -i "1" -f flv rtmp://localhost:1935/zbcs/room
//推流桌面 - 只有桌面内容
ffmpeg -f avfoundation -pixel_format uyvy422 -i "1" -f flv rtmp://192.168.10.61:1935/zbcs/room
ffmpeg -f avfoundation -i "1" -vcodec libx264 -preset ultrafast -acodec libfaac -f flv rtmp://192.168.10.61:1935/zbcs/room
//推流摄像头
ffmpeg -f avfoundation -framerate 30 -video_size 1280x720 -i "0" -vcodec libx264 -acodec libfaac -f flv rtmp://192.168.10.61:1935/zbcs/room
//只推流麦克风
ffmpeg -f avfoundation -i ":0" -vcodec libx264 -preset ultrafast -acodec libmp3lame -ar 44100 -ac 1 -f flv rtmp://192.168.10.61:1935/zbcs/room
//摄像头+麦克分
ffmpeg -f avfoundation -framerate 30 -video_size 1280x720 -i "0:0" -vcodec libx264 -preset ultrafast -acodec libmp3lame -ar 44100 -ac 1 -f flv rtmp://192.168.10.61:1935/zbcs/room
ffmpeg -f avfoundation -framerate 30 -video_size 1280x720 -i "0:0" -vsync 2 -vcodec libx264 -preset ultrafast -acodec libmp3lame -ar 44100 -ac 1 -b:v 1M -b:a 128K -f flv rtmp://192.168.10.61:1935/zbcs/room
参考:
https://www.jianshu.com/p/575136f63348
https://blog.csdn.net/jeffasd/article/details/71205664?utm_source=blogxgwz0