参考博客

http://blog.chinaunix.net/uid-11344913-id-4665455.html

在osx系统下通过ffmpeg查看设备

ffmpeg -f avfoundation -list_devices true -i ""

显示结果如下:

SingerdeMacBook-Pro:~ Singer$ ffmpeg -f avfoundation -list_devices true -i ""
ffmpeg version 3.0 Copyright (c) 2000-2016 the FFmpeg developers
built with Apple LLVM version 7.0.2 (clang-700.1.81)
configuration: --prefix=/usr/local/Cellar/ffmpeg/3.0 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-opencl --enable-libx264 --enable-libmp3lame --enable-libxvid --enable-vda
libavutil 55. 17.103 / 55. 17.103
libavcodec 57. 24.102 / 57. 24.102
libavformat 57. 25.100 / 57. 25.100
libavdevice 57. 0.101 / 57. 0.101
libavfilter 6. 31.100 / 6. 31.100
libavresample 3. 0. 0 / 3. 0. 0
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.101 / 2. 0.101
libpostproc 54. 0.100 / 54. 0.100
[AVFoundation input device @ 0x7f9a2bc1b6e0] AVFoundation video devices:
[AVFoundation input device @ 0x7f9a2bc1b6e0] [0] FaceTime HD Camera
[AVFoundation input device @ 0x7f9a2bc1b6e0] [1] Capture screen 0
[AVFoundation input device @ 0x7f9a2bc1b6e0] AVFoundation audio devices:
[AVFoundation input device @ 0x7f9a2bc1b6e0] [0] Built-in Microphone
: Input/output error

从上面我们可以看到设备如下:

AVFoundation video devices:
[0] FaceTime HD Camera
[1] Capture screen 0
AVFoundation audio devices:
[0] Built-in Microphone

如果希望将桌面录制或者分享,可以使用命令行如下:

ffmpeg -f avfoundation -i "1" -vcodec libx264 -preset ultrafast -acodec libfaac -f flv rtmp://192.168.1.105:1935/live1/room1

如果需要桌面+麦克风,比如一般做远程教育分享ppt或者桌面,有音频讲解 命令行如下:

ffmpeg -f avfoundation -i "1:0" -vcodec libx264 -preset ultrafast -acodec libmp3lame -ar 44100 -ac 1 -f flv rtmp://192.168.1.105:1935/live1/room1

如果需要桌面+麦克风,并且还要摄像头拍摄到自己,比如一般用于互动主播,游戏主播,命令行如下

ffmpeg -f avfoundation -framerate 30 -i "1:0" \
-f avfoundation -framerate 30 -video_size 640x480 -i "0" \
-c:v libx264 -preset ultrafast \
-filter_complex 'overlay=main_w-overlay_w-10:main_h-overlay_h-10' -acodec libmp3lame -ar 44100 -ac 1 -f flv rtmp://192.168.1.105:1935/live1/room1

然后你就可以用过支持rtmp协议的播放软件(例如VCL播放器)测试观看了

最终效果

目前用命令录屏推流 我测试的时候遇到一点问题,以上几个命令 在推了一段时间后会报一个错

av_interleaved_write_frame(): Broken pipe

我也刚开始接触ffmpeg,不知道怎么回事,如果有知道的大神,还请在评论中回复,指点下~。

服务器用的是nginx的rtmp模块搭建的,不知道是否还需要做额外配置)谢谢

ffmpeg -f avfoundation -framerate 30 -i "1:0" \
> -f avfoundation -framerate 30 -video_size 640x480 -i "0" \
> -c:v libx264 -preset ultrafast \
> -filter_complex 'overlay=main_w-overlay_w-10:main_h-overlay_h-10' -acodec libmp3lame -ar 44100 -ac 1 -f flv rtmp://192.168.1.105:1935/live1/room1
ffmpeg version 3.0 Copyright (c) 2000-2016 the FFmpeg developers
built with Apple LLVM version 7.0.2 (clang-700.1.81)
configuration: --prefix=/usr/local/Cellar/ffmpeg/3.0 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-opencl --enable-libx264 --enable-libmp3lame --enable-libxvid --enable-vda
libavutil 55. 17.103 / 55. 17.103
libavcodec 57. 24.102 / 57. 24.102
libavformat 57. 25.100 / 57. 25.100
libavdevice 57. 0.101 / 57. 0.101
libavfilter 6. 31.100 / 6. 31.100
libavresample 3. 0. 0 / 3. 0. 0
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.101 / 2. 0.101
libpostproc 54. 0.100 / 54. 0.100
[avfoundation @ 0x7fc549000400] Selected pixel format (yuv420p) is not supported by the input device.
[avfoundation @ 0x7fc549000400] Supported pixel formats:
[avfoundation @ 0x7fc549000400] uyvy422
[avfoundation @ 0x7fc549000400] yuyv422
[avfoundation @ 0x7fc549000400] nv12
[avfoundation @ 0x7fc549000400] 0rgb
[avfoundation @ 0x7fc549000400] bgr0
[avfoundation @ 0x7fc549000400] Overriding selected pixel format to use uyvy422 instead.
[avfoundation @ 0x7fc549000400] Stream #0: not enough frames to estimate rate; consider increasing probesize
Input #0, avfoundation, from '1:0':
Duration: N/A, start: 21897.641167, bitrate: 2822 kb/s
Stream #0:0: Video: rawvideo (UYVY / 0x59565955), uyvy422, 2880x1800, 1000k tbr, 1000k tbn, 1000k tbc
Stream #0:1: Audio: pcm_f32le, 44100 Hz, stereo, flt, 2822 kb/s
[avfoundation @ 0x7fc54a086800] Selected pixel format (yuv420p) is not supported by the input device.
[avfoundation @ 0x7fc54a086800] Supported pixel formats:
[avfoundation @ 0x7fc54a086800] uyvy422
[avfoundation @ 0x7fc54a086800] yuyv422
[avfoundation @ 0x7fc54a086800] nv12
[avfoundation @ 0x7fc54a086800] 0rgb
[avfoundation @ 0x7fc54a086800] bgr0
[avfoundation @ 0x7fc54a086800] Overriding selected pixel format to use uyvy422 instead.
Input #1, avfoundation, from '0':
Duration: N/A, start: 21898.372233, bitrate: N/A
Stream #1:0: Video: rawvideo (UYVY / 0x59565955), uyvy422, 640x480, 29.97 tbr, 1000k tbn, 1000k tbc
[libx264 @ 0x7fc54995de00] MB rate (20340000000) > level limit (2073600)
[libx264 @ 0x7fc54995de00] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 @ 0x7fc54995de00] profile Constrained Baseline, level 5.2
[libx264 @ 0x7fc54995de00] 264 - core 148 r2601 a0cd7d3 - H.264/MPEG-4 AVC codec - Copyleft 2003-2015 - http://www.videolan.org/x264.html - options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=250 keyint_min=25 scenecut=0 intra_refresh=0 rc=crf mbtree=0 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=0
Output #0, flv, to 'rtmp://192.168.1.105:1935/live1/room1':
Metadata:
encoder : Lavf57.25.100
Stream #0:0: Video: h264 (libx264) ([7][0][0][0] / 0x0007), yuv420p, 2880x1800, q=-1--1, 1000k fps, 1k tbn, 1000k tbc (default)
Metadata:
encoder : Lavc57.24.102 libx264
Side data:
unknown side data type 10 (24 bytes)
Stream #0:1: Audio: mp3 (libmp3lame) ([2][0][0][0] / 0x0002), 44100 Hz, mono, fltp
Metadata:
encoder : Lavc57.24.102 libmp3lame
Stream mapping:
Stream #0:0 (rawvideo) -> overlay:main (graph 0)
Stream #1:0 (rawvideo) -> overlay:overlay (graph 0)
overlay (graph 0) -> Stream #0:0 (libx264)
Stream #0:1 -> #0:1 (pcm_f32le (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
[avfoundation @ 0x7fc54a086800] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)
frame= 1 fps=0.0 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A speed= [avfoundation @ 0x7fc549000400] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)
frame= 5 fps=5.0 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A speed= frame= 6 fps=4.0 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A speed= frame= 9 fps=4.5 q=0.0 size= 0kB time=00:00:01.11 bitrate= 2.7kbits/sframe= 14 fps=5.6 q=19.0 size= 676kB time=00:00:01.86 bitrate=2964.4kbits/frame= 16 fps=5.3 q=17.0 size= 945kB time=00:00:01.86 bitrate=4143.2kbits/frame= 20 fps=5.7 q=19.0 size= 1659kB time=00:00:01.92 bitrate=7074.0kbits/frame= 26 fps=6.4 q=19.0 size= 2386kB time=00:00:02.69 bitrate=7257.9kbits/frame= 29 fps=6.4 q=21.0 size= 2718kB time=00:00:03.41 bitrate=6520.5kbits/frame= 32 fps=6.3 q=18.0 size= 2907kB time=00:00:03.41 bitrate=6973.6kbits/frame= 38 fps=6.8 q=17.0 size= 3503kB time=00:00:04.16 bitrate=6891.4kbits/frame= 41 fps=6.8 q=20.0 size= 3874kB time=00:00:04.95 bitrate=6399.7kbits/frame= 43 fps=6.5 q=18.0 size= 4013kB time=00:00:04.95 bitrate=6629.3kbits/frame= 49 fps=6.9 q=18.0 size= 4502kB time=00:00:06.25 bitrate=5894.7kbits/frame= 53 fps=7.0 q=21.0 size= 5001kB time=00:00:06.46 bitrate=6332.6kbits/frame= 57 fps=7.1 q=18.0 size= 5438kB time=00:00:07.07 bitrate=6296.3kbits/frame= 64 fps=7.5 q=18.0 size= 6019kB time=00:00:07.82 bitrate=6301.4kbits/frame= 65 fps=7.2 q=22.0 size= 6135kB time=00:00:08.00 bitrate=6281.8kbits/frame= 69 fps=7.2 q=20.0 size= 6386kB time=00:00:08.63 bitrate=6061.0kbits/frame= 74 fps=7.3 q=19.0 size= 6822kB time=00:00:08.79 bitrate=6351.1kbits/frame= 75 fps=7.1 q=23.0 size= 6877kB time=00:00:08.79 bitrate=6402.7kbits/frame= 80 fps=7.2 q=18.0 size= 7259kB time=00:00:09.54 bitrate=6228.4kbits/frame= 86 fps=7.4 q=18.0 size= 7776kB time=00:00:10.25 bitrate=6213.4kbits/frame= 87 fps=7.2 q=22.0 size= 7843kB time=00:00:10.95 bitrate=5867.4kbits/frame= 92 fps=7.3 q=18.0 size= 8121kB time=00:00:11.01 bitrate=6042.1kbits/frame= 98 fps=7.5 q=18.0 size= 8698kB time=00:00:11.78 bitrate=6047.1kbits/frame= 100 fps=7.3 q=17.0 size= 8898kB time=00:00:12.52 bitrate=5817.7kbits/frame= 102 fps=7.2 q=20.0 size= 9030kB time=00:00:13.30 bitrate=5561.6kbits/frame= 106 fps=7.2 q=20.0 size= 9411kB time=00:00:13.87 bitrate=5555.8kbits/frame= 108 fps=7.1 q=20.0 size= 9557kB time=00:00:14.10 bitrate=5551.7kbits/frame= 111 fps=7.1 q=20.0 size= 9877kB time=00:00:14.65 bitrate=5522.7kbits/frame= 116 fps=7.2 q=19.0 size= 10305kB time=00:00:15.40 bitrate=5481.7kbits/frame= 119 fps=7.1 q=22.0 size= 10536kB time=00:00:15.43 bitrate=5591.1kbits/frame= 122 fps=7.1 q=19.0 size= 10822kB time=00:00:15.61 bitrate=5677.1kbits/frame= 129 fps=7.3 q=21.0 size= 11436kB time=00:00:16.36 bitrate=5725.4kbits/frame= 133 fps=7.3 q=21.0 size= 11816kB time=00:00:17.14 bitrate=5645.2kbits/frame= 136 fps=7.3 q=18.0 size= 12159kB time=00:00:17.90 bitrate=5563.2kbits/frame= 141 fps=7.3 q=17.0 size= 12530kB time=00:00:18.64 bitrate=5506.2kbits/frame= 144 fps=7.3 q=21.0 size= 12835kB time=00:00:18.66 bitrate=5632.2kbits/frame= 146 fps=7.2 q=17.0 size= 12984kB time=00:00:19.13 bitrate=5558.5kbits/frame= 153 fps=7.4 q=18.0 size= 13696kB time=00:00:19.42 bitrate=5777.3kbits/frame= 156 fps=7.3 q=21.0 size= 14008kB time=00:00:19.92 bitrate=5760.2kbits/frame= 160 fps=7.4 q=18.0 size= 14397kB time=00:00:20.67 bitrate=5705.4kbits/frame= 167 fps=7.5 q=16.0 size= 15053kB time=00:00:22.23 bitrate=5545.9kbits/frame= 169 fps=7.4 q=18.0 size= 15205kB time=00:00:22.23 bitrate=5601.6kbits/frame= 172 fps=7.4 q=17.0 size= 15421kB time=00:00:22.40 bitrate=5639.0kbits/frame= 178 fps=7.5 q=20.0 size= 15991kB time=00:00:23.01 bitrate=5692.4kbits/frame= 180 fps=7.4 q=17.0 size= 16226kB time=00:00:23.01 bitrate=5776.1kbits/frame= 184 fps=7.4 q=16.0 size= 16612kB time=00:00:23.28 bitrate=5844.9kbits/frame= 190 fps=7.5 q=20.0 size= 17139kB time=00:00:24.04 bitrate=5839.8kbits/frame= 192 fps=7.4 q=17.0 size= 17348kB time=00:00:24.53 bitrate=5792.2kbits/frame= 195 fps=7.4 q=16.0 size= 17554kB time=00:00:24.81 bitrate=5794.9kbits/frame= 199 fps=7.4 q=18.0 size= 17979kB time=00:00:25.58 bitrate=5756.1kbits/frame= 202 fps=7.4 q=16.0 size= 18201kB time=00:00:26.10 bitrate=5712.6kbits/frame= 205 fps=7.4 q=17.0 size= 18445kB time=00:00:26.79 bitrate=5639.9kbits/frame= 209 fps=7.4 q=18.0 size= 18808kB time=00:00:27.56 bitrate=5589.6kbits/frame= 212 fps=7.3 q=16.0 size= 19082kB time=00:00:27.56 bitrate=5671.0kbits/frame= 215 fps=7.3 q=16.0 size= 19413kB time=00:00:27.93 bitrate=5694.0kbits/frame= 219 fps=7.3 q=18.0 size= 19873kB time=00:00:28.70 bitrate=5672.1kbits/frame= 221 fps=7.3 q=16.0 size= 20000kB time=00:00:29.16 bitrate=5616.8kbits/frame= 225 fps=7.3 q=17.0 size= 20443kB time=00:00:29.87 bitrate=5606.3kbits/frame= 229 fps=7.3 q=17.0 size= 20875kB time=00:00:30.23 bitrate=5656.0kbits/frame= 232 fps=7.3 q=17.0 size= 21093kB time=00:00:30.63 bitrate=5641.1kbits/frame= 237 fps=7.3 q=17.0 size= 21625kB time=00:00:30.75 bitrate=5760.9kbits/frame= 241 fps=7.3 q=16.0 size= 22111kB time=00:00:31.52 bitrate=5746.1kbits/frame= 243 fps=7.3 q=18.0 size= 22327kB time=00:00:32.17 bitrate=5684.3kbits/frame= 248 fps=7.3 q=15.0 size= 22659kB time=00:00:32.94 bitrate=5633.7kbits/frame= 251 fps=7.3 q=21.0 size= 23012kB time=00:00:33.72 bitrate=5590.6kbits/frame= 254 fps=7.3 q=21.0 size= 23227kB time=00:00:33.72 bitrate=5642.7kbits/frame= 260 fps=7.3 q=21.0 size= 23630kB time=00:00:34.03 bitrate=5687.9kbits/frame= 263 fps=7.3 q=20.0 size= 23967kB time=00:00:34.61 bitrate=5672.3kbits/av_interleaved_write_frame(): Broken pipe
Last message repeated 1 times
[flv @ 0x7fc54995be00] Failed to update header with correct duration.
[flv @ 0x7fc54995be00] Failed to update header with correct filesize.
Error writing trailer of rtmp://192.168.1.105:1935/live1/room1: Broken pipeframe= 264 fps=7.3 q=18.0 Lsize= 25180kB time=00:00:34.80 bitrate=5927.3kbits/s speed=0.967x
video:25152kB audio:20kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.027315%
[libx264 @ 0x7fc54995de00] frame I:2 Avg QP:17.00 size:952357
[libx264 @ 0x7fc54995de00] frame P:262 Avg QP:18.57 size: 94027
[libx264 @ 0x7fc54995de00] mb I I16..4: 100.0% 0.0% 0.0%
[libx264 @ 0x7fc54995de00] mb P I16..4: 1.4% 0.0% 0.0% P16..4: 10.8% 0.0% 0.0% 0.0% 0.0% skip:87.8%
[libx264 @ 0x7fc54995de00] coded y,uvDC,uvAC intra: 68.5% 67.1% 65.3% inter: 7.5% 9.0% 7.1%
[libx264 @ 0x7fc54995de00] i16 v,h,dc,p: 33% 27% 27% 12%
[libx264 @ 0x7fc54995de00] i8c dc,h,v,p: 58% 20% 16% 5%
[libx264 @ 0x7fc54995de00] kb/s:5865.17
Conversion failed!

OSX下面用ffmpeg抓取桌面以及摄像头推流进行直播的更多相关文章

  1. 使用JavaCV/OpenCV抓取并存储摄像头图像

    http://blog.csdn.net/ljsspace/article/details/6702178  分类: 图形图像(3)  版权声明:本文为博主原创文章,未经博主允许不得转载. 本程序通过 ...

  2. VNC 抓取远程桌面

    VNC (Virtual Network Computing)是虚拟网络计算机的缩写.VNC 是一款优秀的远程控制工具软件,由著名的 AT&T 的欧洲研究实验室开发的.VNC 是在基于 UNI ...

  3. python爬虫-抓取acg12动漫壁纸排行设置为桌面壁纸

    ACG-wallpaper 初学python,之前想抓取P站的一些图片来着,然后发现acg12这里有专门的壁纸榜单,就写了个抓取壁纸作为mac桌面壁纸玩玩. 功能:抓取acg12壁纸榜单的动漫壁纸,并 ...

  4. Fiddler:在PC和移动设备上抓取HTTPS数据包

    Fiddler是一个免费的Web调试代理,支持任何浏览器.系统以及平台.这个工具是进行Web和App网络开发的必备工具,戳此处下载. 根据Fiddler官网的描述,具有以下六大特点: Web调试 性能 ...

  5. PowerShell定时抓取屏幕图像

         昨天的博文写了定时记录操作系统行为,其实说白了就是抓取了击键的记录和对应窗口的标题栏,而很多应用程序标题栏又包含当时记录的文件路径和文件名,用这种方式可以大致记录操作了哪些程序,打开了哪些文 ...

  6. [原创]使用logcat快速抓取android崩溃日志

    在android APP测试过程中会发生不少的crash,目前抓取日志的主流方法是通过eclipse或者eclipse的ddms组件进行捕抓,这两种方法有个缺点是启动时非常耗时.本文通过adb程序与b ...

  7. 如何使用fiddler抓取https请求(PC和移动端)

    最近做一个抓取移动端app接口,并执行评论,收藏的接口功能测试.怎么搞/(ㄒoㄒ)/~~ 按照老思路试一试,第一步还是要用fiddler来帮忙获取接口信息! 一.基本的抓取http请求设置: 1.cm ...

  8. 用python的requests第三方模块抓取王者荣耀所有英雄的皮肤

    本文使用python的第三方模块requests爬取王者荣耀所有英雄的图片,并将图片按每个英雄为一个目录存入文件夹中,方便用作桌面壁纸 下面时具体的代码,已通过python3.6测试,可以成功运行: ...

  9. Fiddler抓取https证书问题

    正常的使用方法  Fiddler 抓包工具总结    大部分问题的解决方案  fiddler4在win7抓取https的配置整理 像我脸一样黑的解决方案  Fiddler https 证书问题     ...

随机推荐

  1. [iOS]图片高清度太高, 导致内存过大Crash

    先说一下状况, 后台提供的图片太高清了, 每个图片都在2-4MB, iOS上每个页面需要同时下载并展示10-15张. 这个时候, 如果我多滑动collectionView几次, 直接App就崩溃了(r ...

  2. JavaScript执行优先顺序

    js在html中的加载执行顺序 1.加载顺序:引入标记<script />的出现顺序, 页面上的Javascript代码是HTML文档的一部分,所以Javascript在页面装载时执行的顺 ...

  3. struts的理解

    1.struts是一个按MVC模式设计的Web层框架,其实他就是一个大大的servlet,这个Servlet名为ActionServlet,或是ActionServlet的子类.我们可以在web.xm ...

  4. IE 11 使用 flexbox 垂直居中 bug

    不要使用 min-height 改为 height 即可 caniuse: https://caniuse.com/#search=flexbox

  5. oracel回收站清理

    从powerdesigner中往oracle中导入表,出现了很多类似“BIN$Z35FPY7eFZDgUKjAC94NkA==$0 ”这样的表名, 原因是删除表的时候没有彻底的删除表,而是把表放入回收 ...

  6. ruby http爬虫中的 :body 用法问题

    require 'http' url = 'http://localhost/b.php' data = 'whoami=whoami' html = HTTP.via('127.0.0.1',808 ...

  7. CentOS安装SVN客户端

    1.检查系统是否已经安装如果安装就卸载 rpm -qa subversion yum remove subversion 2.安装 yum install subversion 3.建立SVN库 mk ...

  8. 学习mysql replication gitd

  9. WPF中各个Template的分析(转)

    作为新手,还是没看明白本文,留着以后再学习 在使用TabControl.ListView.Menu.TreeView的时候被各种Template搞得头昏眼花,决心把这个问题搞清楚,究竟什么时候该用什么 ...

  10. OS X 10.11:如何完全停用Time Machine。

    家里的2010年21.5英寸iMac越来越慢,用HFS+分区的1.5TB外置硬盘进行备份时,100G数据经常两三个小时还不能备份完.Time Machine虽然方便,但效率太低,不得不停用. 1. 要 ...