日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【流媒体开发】9、ffmpeg实现视频录制

發(fā)布時(shí)間:2023/12/16 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【流媒体开发】9、ffmpeg实现视频录制 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

使用ffmpeg通過錄制音視頻,分為兩種:
1、一種是錄制麥克風(fēng)和電腦自帶攝像頭的音視頻
2、一種是錄制電腦系統(tǒng)自帶的音頻和錄屏
本節(jié)說明一下怎么實(shí)現(xiàn)音視頻的錄制,并且進(jìn)行一些參數(shù)的調(diào)節(jié)

一、安裝、設(shè)備查看

1、dshow軟件安裝

  • 是桌面錄制和系統(tǒng)音頻錄制的一個(gè)插件
  • 先安裝dshow軟件 Screen Capturer Recorder,
  • 項(xiàng)目地址: https://sourceforge.net/projects/screencapturer/files/

2、查看當(dāng)前可用于錄制的設(shè)備

  • 然后查看可用設(shè)備名字:ffmpeg -list_devices true -f dshow -i dummy

  • 提取關(guān)鍵信息如下:

    • “Lenovo EasyCamera” #聯(lián)想自帶的攝像
    • “screen-capture-recorder” #屏幕捕獲器,是dshow軟件虛擬出來的,錄制桌面
    • “楹﹀厠椋?(High Definition Audio 璁懼)” #音頻設(shè)備麥克風(fēng)
    • “virtual-audio-capturer” #錄制系統(tǒng)聲音,只使用這個(gè)錄制出來只有系統(tǒng)的聲音,沒有麥克風(fēng)的聲音
  • 具體打印如下

C:\Users\Administrator>ffmpeg -list_devices true -f dshow -i dummy ffmpeg version 4.2.1 Copyright (c) 2000-2019 the FFmpeg developersbuilt with gcc 9.1.1 (GCC) 20190807configuration: --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-libopenmptlibavutil 56. 31.100 / 56. 31.100libavcodec 58. 54.100 / 58. 54.100libavformat 58. 29.100 / 58. 29.100libavdevice 58. 8.100 / 58. 8.100libavfilter 7. 57.100 / 7. 57.100libswscale 5. 5.100 / 5. 5.100libswresample 3. 5.100 / 3. 5.100libpostproc 55. 5.100 / 55. 5.100 [dshow @ 009fdb00] DirectShow video devices (some may be both video and audio devices) [dshow @ 009fdb00] "Lenovo EasyCamera" #聯(lián)想自帶的攝像機(jī) [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 璁懼)"#麥克風(fēng) [dshow @ 009fdb00] Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\楹﹀厠椋?(High Definition Audio 璁懼)" [dshow @ 009fdb00] "virtual-audio-capturer" #錄制系統(tǒng)聲音 [dshow @ 009fdb00] Alternative name "@device_sw_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\{8E14549B-DB61-4309-AFA1-3578E927E935}" dummy: Immediate exit requested

二、音視頻錄制

1、錄制視頻(默認(rèn)參數(shù))

  • 桌面:
ffmpeg -f dshow -i video="screen-capture-recorder" v-out.mp4

-f dshow:表示插件,-i video表示輸入時(shí)桌面錄制設(shè)備

  • 攝像頭:
ffmpeg -f dshow -i video="Lenovo EasyCamera" -y v-out2.flv (要根據(jù)自己攝像頭名稱)

2、錄制聲音(默認(rèn)參數(shù))

  • 系統(tǒng)聲音:
ffmpeg -f dshow -i audio="virtual-audio-capturer" a-out.aac
  • 系統(tǒng)+麥克風(fēng)聲音:
ffmpeg -f dshow -i audio="麥克風(fēng) (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將麥克風(fēng)音頻和系統(tǒng)音頻混音錄制

3、音視頻混合錄制

  • 同時(shí)錄制聲音和視頻(默認(rèn)參數(shù))
ffmpeg -f dshow -i audio="麥克風(fēng) (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
  • 錄制屏幕視頻和系統(tǒng)音頻:
ffmpeg -f dshow -i audio="virtual-audio-capturer" -f dshow -i video="screen-capture-recorder" -y av-out.flv

三、錄制參數(shù)設(shè)置

1、查看可設(shè)錄制參數(shù)

ffmpeg -f dshow -list_options true -i video=“screen-capture-recorder”

ffmpeg version 4.2.1 Copyright (c) 2000-2019 the FFmpeg developersbuilt with gcc 9.1.1 (GCC) 20190807configuration: --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-libopenmptlibavutil 56. 31.100 / 56. 31.100libavcodec 58. 54.100 / 58. 54.100libavformat 58. 29.100 / 58. 29.100libavdevice 58. 8.100 / 58. 8.100libavfilter 7. 57.100 / 7. 57.100libswscale 5. 5.100 / 5. 5.100libswresample 3. 5.100 / 3. 5.100libpostproc 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

音頻可設(shè)參數(shù)查看:
ffmpeg -f dshow -list_options true -i audio="virtual-audio-capturer“

最大最小值一樣,沒啥可以設(shè)置的 [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、指定參數(shù)錄制

修改錄制的分辨率、幀率、顏色空間、碼率、編碼的格式:

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

總結(jié)

以上是生活随笔為你收集整理的【流媒体开发】9、ffmpeg实现视频录制的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。