一、获取本地设备命令:
ffmpeg -list_devices true -f dshow -i dummy
输出结果如下:
ffmpeg version 7.0.2-essentials_build-www.gyan.dev Copyright (c) 2000-2024 the FFmpeg developers
built with gcc 13.2.0 (Rev5, Built by MSYS2 project)
configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-sdl2 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-libfreetype --enable-libfribidi --enable-libharfbuzz --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-dxva2 --enable-d3d11va --enable-d3d12va --enable-ffnvcodec --enable-libvpl --enable-nvdec --enable-nvenc --enable-vaapi --enable-libgme --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libtheora --enable-libvo-amrwbenc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-librubberband
libavutil 59. 8.100 / 59. 8.100
libavcodec 61. 3.100 / 61. 3.100
libavformat 61. 1.100 / 61. 1.100
libavdevice 61. 1.100 / 61. 1.100
libavfilter 10. 1.100 / 10. 1.100
libswscale 8. 1.100 / 8. 1.100
libswresample 5. 1.100 / 5. 1.100
libpostproc 58. 1.100 / 58. 1.100
[dshow @ 00000201e56ff6c0] "Lanseyaoji" (video)
[dshow @ 00000201e56ff6c0] Alternative name "@device_pnp_\\?\usb#vid_0bda&pid_5842&mi_00#7&14e718e7&1&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\global"
[dshow @ 00000201e56ff6c0] "OBS Virtual Camera" (video)
[dshow @ 00000201e56ff6c0] Alternative name "@device_sw_{860BB310-5D01-11D0-BD3B-00A0C911CE86}\{A3FCE0F5-3493-419F-958A-ABA1250EC20B}"
[dshow @ 00000201e56ff6c0] "线路输入 (3- 魅声T800)" (audio)
[dshow @ 00000201e56ff6c0] Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\wave_{033B0D65-D829-4B02-AB38-1D4C6070B4D9}"
[dshow @ 00000201e56ff6c0] "麦克风 (C-Media PCI Audio Device)" (audio)
[dshow @ 00000201e56ff6c0] Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\wave_{18910C88-4E90-422E-9E4E-6CFCB7EA5C21}"
[dshow @ 00000201e56ff6c0] "Aux (C-Media PCI Audio Device)" (audio)
[dshow @ 00000201e56ff6c0] Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\wave_{83C637EB-8DE8-4413-85CA-2BD28C2F95B4}"
[dshow @ 00000201e56ff6c0] "Stereo Mix (C-Media PCI Audio Device)" (audio)
[dshow @ 00000201e56ff6c0] Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\wave_{D91A3A3A-40D5-4812-9E34-404362EF2DA9}"
[dshow @ 00000201e56ff6c0] "SPDIF In (C-Media PCI Audio Device)" (audio)
[dshow @ 00000201e56ff6c0] Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\wave_{DEAE0212-C608-454B-A25F-2B00292C4408}"
[dshow @ 00000201e56ff6c0] "线路输入 (C-Media PCI Audio Device)" (audio)
[dshow @ 00000201e56ff6c0] Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\wave_{E46B84F1-9D79-4951-9D80-4DDDC81D5B01}"
[dshow @ 00000201e56ff6c0] "CD 唱机 (C-Media PCI Audio Device)" (audio)
[dshow @ 00000201e56ff6c0] Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\wave_{F134EB21-D1E6-4F16-A83F-B9216F91C0F3}"
二、从摄像头读取数据并编码为H.264,最后保存为m001.mkv文件
ffmpeg -f dshow -i video="Lanseyaoji" -vcodec libx264 mycamera001.mvk
输出:
ffmpeg version 7.0.2-essentials_build-www.gyan.dev Copyright (c) 2000-2024 the FFmpeg developers
built with gcc 13.2.0 (Rev5, Built by MSYS2 project)
configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-sdl2 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-libfreetype --enable-libfribidi --enable-libharfbuzz --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-dxva2 --enable-d3d11va --enable-d3d12va --enable-ffnvcodec --enable-libvpl --enable-nvdec --enable-nvenc --enable-vaapi --enable-libgme --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libtheora --enable-libvo-amrwbenc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-librubberband
libavutil 59. 8.100 / 59. 8.100
libavcodec 61. 3.100 / 61. 3.100
libavformat 61. 1.100 / 61. 1.100
libavdevice 61. 1.100 / 61. 1.100
libavfilter 10. 1.100 / 10. 1.100
libswscale 8. 1.100 / 8. 1.100
libswresample 5. 1.100 / 5. 1.100
libpostproc 58. 1.100 / 58. 1.100
Input #0, dshow, from 'video=Lanseyaoji':
Duration: N/A, start: 7504.717453, bitrate: N/A
Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 640x480, 30 fps, 30 tbr, 10000k tbn
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[libx264 @ 00000202cbed6140] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 00000202cbed6140] profile High 4:2:2, level 3.0, 4:2:2, 8-bit
[libx264 @ 00000202cbed6140] 264 - core 164 r3191 4613ac3 - H.264/MPEG-4 AVC codec - Copyleft 2003-2024 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=15 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, matroska, to 'mycamera001.mkv':
Metadata:
encoder : Lavf61.1.100
Stream #0:0: Video: h264 (H264 / 0x34363248), yuv422p(progressive), 640x480, q=2-31, 30 fps, 1k tbn
Metadata:
encoder : Lavc61.3.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
[dshow @ 00000202c9672c40] real-time buffer [Lanseyaoji] [video input] too full or near too full (80% of size: 3041280 [rtbufsize parameter])! frame dropped!
[out#0/matroska @ 00000202c97122c0] video:1094KiB audio:0KiB subtitle:0KiB other streams:0KiB global headers:0KiB muxing overhead: 0.254418%
frame= 310 fps= 30 q=-1.0 Lsize= 1097KiB time=00:00:10.26 bitrate= 875.1kbits/s speed=0.978x
[libx264 @ 00000202cbed6140] frame I:2 Avg QP:23.16 size: 38217
[libx264 @ 00000202cbed6140] frame P:78 Avg QP:24.69 size: 9916
[libx264 @ 00000202cbed6140] frame B:230 Avg QP:27.20 size: 1172
[dshow @ 00000202c9672c40] real-time buffer [Lanseyaoji] [video input] too full or near too full (80% of size: 3041280 [rtbufsize parameter])! frame dropped!
[libx264 @ 00000202cbed6140] consecutive B-frames: 1.0% 0.0% 1.0% 98.1%
[libx264 @ 00000202cbed6140] mb I I16..4: 15.7% 45.9% 38.5%
[libx264 @ 00000202cbed6140] mb P I16..4: 0.9% 0.5% 0.1% P16..4: 48.9% 14.6% 12.7% 0.0% 0.0% skip:22.3%
[libx264 @ 00000202cbed6140] mb B I16..4: 0.0% 0.0% 0.0% B16..8: 32.1% 0.7% 0.2% direct: 1.9% skip:65.0% L0:49.4% L1:48.5% BI: 2.2%
[libx264 @ 00000202cbed6140] 8x8 transform intra:42.5% inter:54.0%
[libx264 @ 00000202cbed6140] coded y,uvDC,uvAC intra: 52.3% 76.2% 36.3% inter: 9.3% 30.5% 0.7%
[libx264 @ 00000202cbed6140] i16 v,h,dc,p: 35% 11% 7% 46%
[libx264 @ 00000202cbed6140] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 27% 10% 28% 5% 6% 8% 5% 5% 6%
[libx264 @ 00000202cbed6140] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 31% 16% 12% 5% 7% 10% 7% 7% 5%
[libx264 @ 00000202cbed6140] i8c dc,h,v,p: 51% 13% 28% 8%
[libx264 @ 00000202cbed6140] Weighted P-Frames: Y:9.0% UV:0.0%
[libx264 @ 00000202cbed6140] ref P L0: 38.6% 7.5% 39.9% 13.3% 0.7%
[libx264 @ 00000202cbed6140] ref B L0: 68.8% 26.0% 5.2%
[libx264 @ 00000202cbed6140] ref B L1: 90.3% 9.7%
[libx264 @ 00000202cbed6140] kb/s:866.72
Exiting normally, received signal 2.
ctrl+c退出
三、ffplay直接播放摄像头数据
ffplay -f dshow -i video="Lanseyaoji"