Mac通过ffmpeg读取摄像头并流化为m3u8格式

1、安装brew

命令行输入

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

brew 是mac下一款强大的package管理工具

2、通过brew安装ffmpeg

brew install ffmpeg

3、查看机器上所有设备

ffmpeg -devices

ffmpeg version 4.0 Copyright (c) 2000-2018 the FFmpeg developers   built with Apple LLVM version 9.1.0 (clang-902.0.39.1)  

-----省略-----

avfoundation    AVFoundation input device   <===  摄像头

D  lavfi           Libavfilter virtual input device

4、查看device信息

ffmpeg -f avfoundation -list_devices true -i ""

[AVFoundation input device @ 0x7f9d97403e00] AVFoundation video devices:

[AVFoundation input device @ 0x7f9d97403e00] [0] FaceTime HD Camera

[AVFoundation input device @ 0x7f9d97403e00] [1] Capture screen 0

[AVFoundation input device @ 0x7f9d97403e00] AVFoundation audio devices:

[AVFoundation input device @ 0x7f9d97403e00] [0] Built-in Microphone

5、测试捕捉摄像头数据

ffmpeg -f avfoundation -framerate 30 -i "0" -target pal-vcd [输出文件.mpg]

6、启动系统自带Apache服务器

sudo apachectl start

7、将捕获的摄像头数据推流到服务器

sudo ffmpeg -f avfoundation -framerate 30 -i "0" -c:v libx264 -c:a aac -strict -2 -f hls -hls_list_size 0 /Library/WebServer/Documents/output.m3u8

8、通过ALC视频播放软件播放视频流

访问地址为:http://127.0.0.1/output.m3u8

你可能感兴趣的:(Mac通过ffmpeg读取摄像头并流化为m3u8格式)