流媒体开发9ffmpeg实现视频录制
Posted 努力努力再努力~~
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了流媒体开发9ffmpeg实现视频录制相关的知识,希望对你有一定的参考价值。
使用ffmpeg通过录制音视频,分为两种:
1、一种是录制麦克风和电脑自带摄像头的音视频
2、一种是录制电脑系统自带的音频和录屏
本节说明一下怎么实现音视频的录制,并且进行一些参数的调节
一、安装、设备查看
1、dshow软件安装
- 是桌面录制和系统音频录制的一个插件
- 先安装dshow软件 Screen Capturer Recorder,
- 项目地址: https://sourceforge.net/projects/screencapturer/files/
2、查看当前可用于录制的设备
-
然后查看可用设备名字:ffmpeg -list_devices true -f dshow -i dummy
-
提取关键信息如下:
- “Lenovo EasyCamera” #联想自带的摄像
- “screen-capture-recorder” #屏幕捕获器,是dshow软件虚拟出来的,录制桌面
- “楹﹀厠椋?(High Definition Audio 璁惧)” #音频设备麦克风
- “virtual-audio-capturer” #录制系统声音,只使用这个录制出来只有系统的声音,没有麦克风的声音
-
具体打印如下
C:\\Users\\Administrator>ffmpeg -list_devices true -f dshow -i dummy
ffmpeg version 4.2.1 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 9.1.1 (GCC) 20190807
configuration: --disable-static --enable-shared --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray -
-enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libth
eora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libv
idstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va
--enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
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
[dshow @ 009fdb00] DirectShow video devices (some may be both video and audio devices)
[dshow @ 009fdb00] "Lenovo EasyCamera" #联想自带的摄像机
[dshow @ 009fdb00] Alternative name "@device_pnp_\\\\?\\usb#vid_5986&pid_055e&mi_00#7&330b8916&0&0000#65e8773d-8f56-11d0-a3b9-00a0c9223196\\global"
[dshow @ 009fdb00] "screen-capture-recorder" #屏幕捕获器,是dshow软件虚拟出来的
[dshow @ 009fdb00] Alternative name "@device_sw_860BB310-5D01-11D0-BD3B-00A0C911CE86\\4EA6930A-2C8A-4AE6-A561-56E4B5044439"
[dshow @ 009fdb00] DirectShow audio devices
[dshow @ 009fdb00] "楹﹀厠椋?(High Definition Audio 璁惧)"#麦克风
[dshow @ 009fdb00] Alternative name "@device_cm_33D9A762-90C8-11D0-BD43-00A0C911CE86\\楹﹀厠椋?(High Definition Audio 璁惧)"
[dshow @ 009fdb00] "virtual-audio-capturer" #录制系统声音
[dshow @ 009fdb00] Alternative name "@device_sw_33D9A762-90C8-11D0-BD43-00A0C911CE86\\8E14549B-DB61-4309-AFA1-3578E927E935"
dummy: Immediate exit requested
二、音视频录制
1、录制视频(默认参数)
- 桌面:
ffmpeg -f dshow -i video="screen-capture-recorder" v-out.mp4
-f dshow:表示插件,-i video表示输入时桌面录制设备
- 摄像头:
ffmpeg -f dshow -i video="Lenovo EasyCamera" -y v-out2.flv (要根据自己摄像头名称)
2、录制声音(默认参数)
- 系统声音:
ffmpeg -f dshow -i audio="virtual-audio-capturer" a-out.aac
- 系统+麦克风声音:
ffmpeg -f dshow -i audio="麦克风 (High Definition Audio)" -f dshow -i audio="virtual-audio-capturer" -filter_complex amix=inputs=2:duration=first:dropout_transition=2 a-out2.aac
使用过滤器filter_complex将麦克风音频和系统音频混音录制
3、音视频混合录制
- 同时录制声音和视频(默认参数)
ffmpeg -f dshow -i audio="麦克风 (Realtek Audio)" -f dshow -i audio="virtualaudio-capturer" -filter_complex amix=inputs=2:duration=first:dropout_transition=2 -f dshow -i video="virtual-audio-capturer" -y av-out.flv
- 录制屏幕视频和系统音频:
ffmpeg -f dshow -i audio="virtual-audio-capturer" -f dshow -i video="screen-capture-recorder" -y av-out.flv
三、录制参数设置
1、查看可设录制参数
ffmpeg -f dshow -list_options true -i video=“screen-capture-recorder”
ffmpeg version 4.2.1 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 9.1.1 (GCC) 20190807
configuration: --disable-static --enable-shared --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray -
-enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libth
eora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libv
idstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va
--enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
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
[dshow @ 003df800] DirectShow video device options (from video devices)
[dshow @ 003df800] Pin "Capture" (alternative pin name "1")
[dshow @ 003df800] pixel_format=bgr0 min s=1x1 fps=0.02 max s=1920x1080 fps=30
[dshow @ 003df800] pixel_format=bgr0 min s=1x1 fps=0.02 max s=1920x1080 fps=30
[dshow @ 003df800] pixel_format=bgr24 min s=1x1 fps=0.02 max s=1920x1080 fps=30
[dshow @ 003df800] pixel_format=rgb555le min s=1x1 fps=0.02 max s=1920x1080 fps=30
[dshow @ 003df800] pixel_format=rgb555le min s=1x1 fps=0.02 max s=1920x1080 fps=30
[dshow @ 003df800] pixel_format=rgb8 min s=1x1 fps=0.02 max s=1920x1080 fps=30
[dshow @ 003df800] pixel_format=yuv420p min s=1x1 fps=0.02 max s=1920x1080 fps=30
leaving aero onvideo=screen-capture-recorder: Immediate exit requested
音频可设参数查看:
ffmpeg -f dshow -list_options true -i audio="virtual-audio-capturer“
最大最小值一样,没啥可以设置的
[dshow @ 00a7f800] DirectShow audio only device options (from audio devices)
[dshow @ 00a7f800] Pin "Capture Virtual Audio Pin" (alternative pin name "1")
[dshow @ 00a7f800] min ch=2 bits=16 rate= 44100 max ch=2 bits=16 rate= 44100
audio=virtual-audio-capturer: Immediate exit requested
2、指定参数录制
修改录制的分辨率、帧率、颜色空间、码率、编码的格式:
ffmpeg -f dshow -i audio="virtual-audio-capturer" -f dshow -video_size 1920x1080 -framerate 15 -pixel_format yuv420p -i video="screen-capture-recorder" -b:v 3M -vcodec libx264 -y av-out.flv
###-framerate 15属于采集修改为15帧
-i video="screen-capture-recorder" -b:v 3M -vcodec libx264 -r 15 -y av-out.flv
这里的-r属于编码成15帧
以上是关于流媒体开发9ffmpeg实现视频录制的主要内容,如果未能解决你的问题,请参考以下文章