Capture webcam images using ffmpeg on MacOS

0
5035
Capture webcam images using ffmpeg on MacOS
Capture webcam images using ffmpeg on MacOS

To capture webcam images using ffmpeg on MacOS, use the following command:

$ ffmpeg -f avfoundation -r 30 -i "1"  -frames:v 1  capture.jpg

To explain the arguments:

  • -f avfoundation: the format to use for webcam capture.
  • -r 30: to specify video framerate for capturing.
  • -i "1": the webcam device ID to capture.
  • -frames:v 1: to export only 1 frame of video device
  • capture.jpg: output image filename. You should change into your own filename.

By default, ffmpeg will take screenshot of the largest image size available from the webcam. To specify the output image size, use -s WxH option, like this:

$ ffmpeg -f avfoundation -r 30 -i "1"  -frames:v 1 -s 800x600  capture-800x600.jpg

To determine the image size available to capture from webcam, use following command:

$ ffmpeg -hide_banner -f avfoundation -i "1"
[avfoundation @ 0x1507041a0] Selected framerate (29.970030) is not supported by the device.
[avfoundation @ 0x1507041a0] Supported modes:
[avfoundation @ 0x1507041a0]   160x90@[5.000000 30.000030]fps
    Last message repeated 1 times
[avfoundation @ 0x1507041a0]   160x120@[5.000000 30.000030]fps
    Last message repeated 1 times
[avfoundation @ 0x1507041a0]   176x144@[5.000000 30.000030]fps
    Last message repeated 1 times
[avfoundation @ 0x1507041a0]   320x180@[5.000000 30.000030]fps
    Last message repeated 1 times
[avfoundation @ 0x1507041a0]   320x240@[5.000000 30.000030]fps
    Last message repeated 1 times
[avfoundation @ 0x1507041a0]   352x288@[5.000000 30.000030]fps
    Last message repeated 1 times
[avfoundation @ 0x1507041a0]   432x240@[5.000000 30.000030]fps
    Last message repeated 1 times
[avfoundation @ 0x1507041a0]   640x360@[5.000000 30.000030]fps
[avfoundation @ 0x1507041a0]   640x480@[5.000000 30.000030]fps
    Last message repeated 1 times
[avfoundation @ 0x1507041a0]   800x448@[5.000000 30.000030]fps
    Last message repeated 1 times
[avfoundation @ 0x1507041a0]   800x600@[5.000000 30.000030]fps
[avfoundation @ 0x1507041a0]   800x600@[5.000000 24.000038]fps
[avfoundation @ 0x1507041a0]   864x480@[5.000000 30.000030]fps
[avfoundation @ 0x1507041a0]   864x480@[5.000000 24.000038]fps
[avfoundation @ 0x1507041a0]   960x720@[5.000000 30.000030]fps
[avfoundation @ 0x1507041a0]   960x720@[5.000000 15.000015]fps
[avfoundation @ 0x1507041a0]   1024x576@[5.000000 30.000030]fps
[avfoundation @ 0x1507041a0]   1024x576@[5.000000 15.000015]fps
[avfoundation @ 0x1507041a0]   1280x720@[5.000000 30.000030]fps
[avfoundation @ 0x1507041a0]   1280x720@[5.000000 10.000000]fps
[avfoundation @ 0x1507041a0]   1600x896@[5.000000 30.000030]fps
[avfoundation @ 0x1507041a0]   1600x896@[5.000000 7.500002]fps
[avfoundation @ 0x1507041a0]   1920x1080@[5.000000 30.000030]fps
[avfoundation @ 0x1507041a0]   1920x1080@[5.000000 5.000000]fps

You will see a list of supported video/image size and frame rates, which can be used for capturing image.

Have fun!