Access webcam by ffmpeg in Windows
Tags: ffmpeg
Published: 2024-03-03 20:58:59

In Windows, access multimedia devices such as webcam is through the DirectShow library.

# Display available devices

```
ffmpeg -hide_banner -f dshow -list_devices true -i dummy
[dshow @ 000001ff6c6f1540] "Logi C615 HD WebCam" (video)
[dshow @ 000001ff6c6f1540]   Alternative name "@device_pnp_\\?\usb#vid_046d&pid_082c&mi_02#7&67fa7ba&0&0002#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\global"
[dshow @ 000001ff6c6f1540] "Intel Virtual Camera" (video)
[dshow @ 000001ff6c6f1540]   Alternative name "@device_sw_{860BB310-5D01-11D0-BD3B-00A0C911CE86}\{49C7D45E-2F4B-40FF-BEF7-A7D95B2CD31D}"
[dshow @ 000001ff6c6f1540] "Microphone (Logi C615 HD WebCam)" (audio)
[dshow @ 000001ff6c6f1540]   Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\wave_{C332401D-216A-4F5F-8354-B5A0FAEC6C35}"
[in#0 @ 000001ff6c6adc00] Error opening input: Immediate exit requested
Error opening input file dummy.
```

# Display capacity of a video device

```
ffmpeg -hide_banner -f dshow -list_options true -i video="Logi C615 HD WebCam"
[dshow @ 000001ee64890200] DirectShow video device options (from video devices)
[dshow @ 000001ee64890200]  Pin "Capture" (alternative pin name "0")
[dshow @ 000001ee64890200]   pixel_format=yuyv422  min s=640x480 fps=5 max s=640x480 fps=30
[dshow @ 000001ee64890200]   pixel_format=yuyv422  min s=640x480 fps=5 max s=640x480 fps=30 (tv, bt470bg/bt709/unknown, topleft)
[dshow @ 000001ee64890200]   pixel_format=yuyv422  min s=160x120 fps=5 max s=160x120 fps=30
[dshow @ 000001ee64890200]   pixel_format=yuyv422  min s=160x120 fps=5 max s=160x120 fps=30 (tv, bt470bg/bt709/unknown, topleft)
[dshow @ 000001ee64890200]   pixel_format=yuyv422  min s=176x144 fps=5 max s=176x144 fps=30
[dshow @ 000001ee64890200]   pixel_format=yuyv422  min s=176x144 fps=5 max s=176x144 fps=30 (tv, bt470bg/bt709/unknown, topleft)
[dshow @ 000001ee64890200]   pixel_format=yuyv422  min s=320x240 fps=5 max s=320x240 fps=30
[dshow @ 000001ee64890200]   pixel_format=yuyv422  min s=320x240 fps=5 max s=320x240 fps=30 (tv, bt470bg/bt709/unknown, topleft)
[dshow @ 000001ee64890200]   pixel_format=yuyv422  min s=432x240 fps=5 max s=432x240 fps=30
[dshow @ 000001ee64890200]   pixel_format=yuyv422  min s=432x240 fps=5 max s=432x240 fps=30 (tv, bt470bg/bt709/unknown, topleft)
[dshow @ 000001ee64890200]   pixel_format=yuyv422  min s=352x288 fps=5 max s=352x288 fps=30
[dshow @ 000001ee64890200]   pixel_format=yuyv422  min s=352x288 fps=5 max s=352x288 fps=30 (tv, bt470bg/bt709/unknown, topleft)
[dshow @ 000001ee64890200]   pixel_format=yuyv422  min s=640x360 fps=5 max s=640x360 fps=30
[dshow @ 000001ee64890200]   pixel_format=yuyv422  min s=640x360 fps=5 max s=640x360 fps=30 (tv, bt470bg/bt709/unknown, topleft)
[dshow @ 000001ee64890200]   pixel_format=yuyv422  min s=800x448 fps=5 max s=800x448 fps=30
[dshow @ 000001ee64890200]   pixel_format=yuyv422  min s=800x448 fps=5 max s=800x448 fps=30 (tv, bt470bg/bt709/unknown, topleft)
[dshow @ 000001ee64890200]   pixel_format=yuyv422  min s=864x480 fps=5 max s=864x480 fps=24
[dshow @ 000001ee64890200]   pixel_format=yuyv422  min s=864x480 fps=5 max s=864x480 fps=24 (tv, bt470bg/bt709/unknown, topleft)
[dshow @ 000001ee64890200]   pixel_format=yuyv422  min s=1024x576 fps=5 max s=1024x576 fps=15
[dshow @ 000001ee64890200]   pixel_format=yuyv422  min s=1024x576 fps=5 max s=1024x576 fps=15 (tv, bt470bg/bt709/unknown, topleft)
[dshow @ 000001ee64890200]   pixel_format=yuyv422  min s=800x600 fps=5 max s=800x600 fps=24
[dshow @ 000001ee64890200]   pixel_format=yuyv422  min s=800x600 fps=5 max s=800x600 fps=24 (tv, bt470bg/bt709/unknown, topleft)
[dshow @ 000001ee64890200]   pixel_format=yuyv422  min s=960x720 fps=5 max s=960x720 fps=15
[dshow @ 000001ee64890200]   pixel_format=yuyv422  min s=960x720 fps=5 max s=960x720 fps=15 (tv, bt470bg/bt709/unknown, topleft)
[dshow @ 000001ee64890200]   pixel_format=yuyv422  min s=1280x720 fps=5 max s=1280x720 fps=10
[dshow @ 000001ee64890200]   pixel_format=yuyv422  min s=1280x720 fps=5 max s=1280x720 fps=10 (tv, bt470bg/bt709/unknown, topleft)
[dshow @ 000001ee64890200]   pixel_format=yuyv422  min s=1600x896 fps=5 max s=1600x896 fps=7.5
[dshow @ 000001ee64890200]   pixel_format=yuyv422  min s=1600x896 fps=5 max s=1600x896 fps=7.5 (tv, bt470bg/bt709/unknown, topleft)
[dshow @ 000001ee64890200]   pixel_format=yuyv422  min s=1920x1080 fps=5 max s=1920x1080 fps=5
[dshow @ 000001ee64890200]   pixel_format=yuyv422  min s=1920x1080 fps=5 max s=1920x1080 fps=5 (tv, bt470bg/bt709/unknown, topleft)
[dshow @ 000001ee64890200]   vcodec=mjpeg  min s=640x480 fps=5 max s=640x480 fps=30
[dshow @ 000001ee64890200]   vcodec=mjpeg  min s=640x480 fps=5 max s=640x480 fps=30 (pc, bt470bg/bt709/unknown, center)
[dshow @ 000001ee64890200]   vcodec=mjpeg  min s=160x120 fps=5 max s=160x120 fps=30
[dshow @ 000001ee64890200]   vcodec=mjpeg  min s=160x120 fps=5 max s=160x120 fps=30 (pc, bt470bg/bt709/unknown, center)
[dshow @ 000001ee64890200]   vcodec=mjpeg  min s=176x144 fps=5 max s=176x144 fps=30
[dshow @ 000001ee64890200]   vcodec=mjpeg  min s=176x144 fps=5 max s=176x144 fps=30 (pc, bt470bg/bt709/unknown, center)
[dshow @ 000001ee64890200]   vcodec=mjpeg  min s=320x240 fps=5 max s=320x240 fps=30
[dshow @ 000001ee64890200]   vcodec=mjpeg  min s=320x240 fps=5 max s=320x240 fps=30 (pc, bt470bg/bt709/unknown, center)
[dshow @ 000001ee64890200]   vcodec=mjpeg  min s=432x240 fps=5 max s=432x240 fps=30
[dshow @ 000001ee64890200]   vcodec=mjpeg  min s=432x240 fps=5 max s=432x240 fps=30 (pc, bt470bg/bt709/unknown, center)
[dshow @ 000001ee64890200]   vcodec=mjpeg  min s=352x288 fps=5 max s=352x288 fps=30
[dshow @ 000001ee64890200]   vcodec=mjpeg  min s=352x288 fps=5 max s=352x288 fps=30 (pc, bt470bg/bt709/unknown, center)
[dshow @ 000001ee64890200]   vcodec=mjpeg  min s=640x360 fps=5 max s=640x360 fps=30
[dshow @ 000001ee64890200]   vcodec=mjpeg  min s=640x360 fps=5 max s=640x360 fps=30 (pc, bt470bg/bt709/unknown, center)
[dshow @ 000001ee64890200]   vcodec=mjpeg  min s=800x448 fps=5 max s=800x448 fps=30
[dshow @ 000001ee64890200]   vcodec=mjpeg  min s=800x448 fps=5 max s=800x448 fps=30 (pc, bt470bg/bt709/unknown, center)
[dshow @ 000001ee64890200]   vcodec=mjpeg  min s=864x480 fps=5 max s=864x480 fps=30
[dshow @ 000001ee64890200]   vcodec=mjpeg  min s=864x480 fps=5 max s=864x480 fps=30 (pc, bt470bg/bt709/unknown, center)
[dshow @ 000001ee64890200]   vcodec=mjpeg  min s=1024x576 fps=5 max s=1024x576 fps=30
[dshow @ 000001ee64890200]   vcodec=mjpeg  min s=1024x576 fps=5 max s=1024x576 fps=30 (pc, bt470bg/bt709/unknown, center)
[dshow @ 000001ee64890200]   vcodec=mjpeg  min s=800x600 fps=5 max s=800x600 fps=30
[dshow @ 000001ee64890200]   vcodec=mjpeg  min s=800x600 fps=5 max s=800x600 fps=30 (pc, bt470bg/bt709/unknown, center)
[dshow @ 000001ee64890200]   vcodec=mjpeg  min s=960x720 fps=5 max s=960x720 fps=30
[dshow @ 000001ee64890200]   vcodec=mjpeg  min s=960x720 fps=5 max s=960x720 fps=30 (pc, bt470bg/bt709/unknown, center)
[dshow @ 000001ee64890200]   vcodec=mjpeg  min s=1280x720 fps=5 max s=1280x720 fps=30
[dshow @ 000001ee64890200]   vcodec=mjpeg  min s=1280x720 fps=5 max s=1280x720 fps=30 (pc, bt470bg/bt709/unknown, center)
[dshow @ 000001ee64890200]   vcodec=mjpeg  min s=1600x896 fps=5 max s=1600x896 fps=30
[dshow @ 000001ee64890200]   vcodec=mjpeg  min s=1600x896 fps=5 max s=1600x896 fps=30 (pc, bt470bg/bt709/unknown, center)
[dshow @ 000001ee64890200]   vcodec=mjpeg  min s=1920x1080 fps=5 max s=1920x1080 fps=30
[dshow @ 000001ee64890200]   vcodec=mjpeg  min s=1920x1080 fps=5 max s=1920x1080 fps=30 (pc, bt470bg/bt709/unknown, center)
[in#0 @ 000001ee64854500] Error opening input: Immediate exit requested
Error opening input file video=Logi C615 HD WebCam.
```

# Display capacity of a audio device

```
ffmpeg -hide_banner -f dshow -list_options true -i audio="Microphone (Logi C615 HD WebCam)"
[dshow @ 0000017b378e2140] DirectShow audio only device options (from audio devices)
[dshow @ 0000017b378e2140]  Pin "Capture" (alternative pin name "Capture")
[dshow @ 0000017b378e2140]   ch= 2, bits=16, rate= 44100
    Last message repeated 1 times
[dshow @ 0000017b378e2140]   ch= 1, bits=16, rate= 44100
[dshow @ 0000017b378e2140]   ch= 2, bits=16, rate= 32000
[dshow @ 0000017b378e2140]   ch= 1, bits=16, rate= 32000
[dshow @ 0000017b378e2140]   ch= 2, bits=16, rate= 22050
[dshow @ 0000017b378e2140]   ch= 1, bits=16, rate= 22050
[dshow @ 0000017b378e2140]   ch= 2, bits=16, rate= 11025
[dshow @ 0000017b378e2140]   ch= 1, bits=16, rate= 11025
[dshow @ 0000017b378e2140]   ch= 2, bits=16, rate=  8000
[dshow @ 0000017b378e2140]   ch= 1, bits=16, rate=  8000
[dshow @ 0000017b378e2140]   ch= 2, bits= 8, rate= 44100
[dshow @ 0000017b378e2140]   ch= 1, bits= 8, rate= 44100
[dshow @ 0000017b378e2140]   ch= 2, bits= 8, rate= 22050
[dshow @ 0000017b378e2140]   ch= 1, bits= 8, rate= 22050
[dshow @ 0000017b378e2140]   ch= 2, bits= 8, rate= 11025
[dshow @ 0000017b378e2140]   ch= 1, bits= 8, rate= 11025
[dshow @ 0000017b378e2140]   ch= 2, bits= 8, rate=  8000
[dshow @ 0000017b378e2140]   ch= 1, bits= 8, rate=  8000
[dshow @ 0000017b378e2140]   ch= 2, bits=16, rate= 48000
[dshow @ 0000017b378e2140]   ch= 1, bits=16, rate= 48000
[dshow @ 0000017b378e2140]   ch= 2, bits=16, rate= 96000
[dshow @ 0000017b378e2140]   ch= 1, bits=16, rate= 96000
[in#0 @ 0000017b3789bac0] Error opening input: Immediate exit requested
Error opening input file audio=Microphone (Logi C615 HD WebCam).
```

# create a avi video from webcam's mjpeg source, without reencode,  and stop recording after 30s

```
ffmpeg -hide_banner -f dshow -t 30 -vcodec mjpeg -video_size 1920x1080 -framerate 30 -i video="Logi C615 HD WebCam" -vcodec copy output.avi
[mjpeg @ 0000024aec2e57c0] unable to decode APP fields: Invalid data found when processing input
Input #0, dshow, from 'video=Logi C615 HD WebCam':
  Duration: N/A, start: 253712.074389, bitrate: N/A
  Stream #0:0: Video: mjpeg (Baseline) (MJPG / 0x47504A4D), yuvj422p(pc, bt470bg/bt709/unknown), 1920x1080, 30 fps, 30 tbr, 10000k tbn
Output #0, avi, to 'output.avi':
  Metadata:
    ISFT            : Lavf60.16.100
  Stream #0:0: Video: mjpeg (Baseline) (MJPG / 0x47504A4D), yuvj422p(pc, bt470bg/bt709/unknown), 1920x1080, q=2-31, 30 fps, 30 tbr, 60 tbn
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
[out#0/avi @ 0000024aec55df00] video:160382kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.029904%
size=  160430kB time=00:00:29.93 bitrate=43901.2kbits/s speed=0.998x
```