1

I am trying to get an input stream from a webcam on OS X

self.capture = pygame.camera('/dev/video{}'.format(camera),
                                 (640, 480), 'RGB')

I get an error (see below), but there are 2 pieces of information that I can not really stitch together. On first sight, it looks like I do not have the correct camera (not video4linux). However, when running

ffmpeg -f avfoundation -list_devices true -i ""

I get it listed

[AVFoundation input device @ 0x7fbb45700340] [1] FULL HD 1080P Webcam

The next part of the error talks about frame rate. It appears that the frame-rate is slightly off, and that I just next to select a different frame rate. Would this be possible with pygcam? Would this solve my problem?

Error:

Traceback (most recent call last):
  File "webcam2.py", line 129, in <module>
    VideoStreaming("52.191.118.156", 5558, 1)()
  File "webcam2.py", line 22, in __call__
    with self.get_camera_context(self.camera_id) as frames:
  File "webcam2.py", line 89, in __enter__
size=(640, 480))
  File "/Users/q433100/temp/brew-master/lib/python3.6/site-packages/imageio/core/functions.py", line 129, in get_reader
return format.get_reader(request)
  File "/Users/q433100/temp/brew-master/lib/python3.6/site-packages/imageio/core/format.py", line 169, in get_reader
    return self.Reader(self, request)
  File "/Users/q433100/temp/brew-master/lib/python3.6/site-packages/imageio/core/format.py", line 218, in __init__
    self._open(**self.request.kwargs.copy())
  File "/Users/q433100/temp/brew-master/lib/python3.6/site-packages/imageio/plugins/ffmpeg.py", line 327, in _open
    self._load_infos()
  File "/Users/q433100/temp/brew-master/lib/python3.6/site-packages/imageio/plugins/ffmpeg.py", line 476, in _load_infos
    (self.request._video, ffmpeg_err))
IndexError: No video4linux camera at <video1>.

FFMPEG STDERR OUTPUT:

ffmpeg version 3.4.1 Copyright (c) 2000-2017 the FFmpeg developers
  built with Apple LLVM version 9.0.0 (clang-900.0.39.2)
  configuration: --prefix=/Users/q433100/temp/brew-master/Cellar/ffmpeg/3.4.1 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-gpl --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
[avfoundation @ 0x7fbb9e000a00] Selected framerate (29.970030) is not supported by the device
[avfoundation @ 0x7fbb9e000a00] Supported modes:
[avfoundation @ 0x7fbb9e000a00]   160x120@[30.000030 30.000030]fps
[avfoundation @ 0x7fbb9e000a00]   176x144@[30.000030 30.000030]fps
[avfoundation @ 0x7fbb9e000a00]   320x240@[30.000030 30.000030]fps
[avfoundation @ 0x7fbb9e000a00]   352x288@[30.000030 30.000030]fps
[avfoundation @ 0x7fbb9e000a00]   640x360@[30.000030 30.000030]fps
[avfoundation @ 0x7fbb9e000a00]   640x480@[30.000030 30.000030]fps
[avfoundation @ 0x7fbb9e000a00]   800x600@[30.000030 30.000030]fps
[avfoundation @ 0x7fbb9e000a00]   1024x576@[30.000030 30.000030]fps
[avfoundation @ 0x7fbb9e000a00]   960x720@[30.000030 30.000030]fps
[avfoundation @ 0x7fbb9e000a00]   1280x720@[30.000030 30.000030]fps
[avfoundation @ 0x7fbb9e000a00]   1392x768@[30.000030 30.000030]fps
[avfoundation @ 0x7fbb9e000a00]   1280x960@[30.000030 30.000030]fps
[avfoundation @ 0x7fbb9e000a00]   1600x896@[30.000030 30.000030]fps
[avfoundation @ 0x7fbb9e000a00]   1920x1080@[30.000030 30.000030]fps
[avfoundation @ 0x7fbb9e000a00]   160x120@[30.000030 30.000030]fps
[avfoundation @ 0x7fbb9e000a00]   176x144@[30.000030 30.000030]fps
[avfoundation @ 0x7fbb9e000a00]   320x240@[30.000030 30.000030]fps
[avfoundation @ 0x7fbb9e000a00]   352x288@[30.000030 30.000030]fps
[avfoundation @ 0x7fbb9e000a00]   640x360@[30.000030 30.000030]fps
[avfoundation @ 0x7fbb9e000a00]   640x480@[30.000030 30.000030]fps
[avfoundation @ 0x7fbb9e000a00]   800x600@[20.000000 20.000000]fps
[avfoundation @ 0x7fbb9e000a00]   1024x576@[8.000000 8.000000]fps
[avfoundation @ 0x7fbb9e000a00]   960x720@[15.000015 15.000015]fps
1: Input/output error

Update: If I try to force one of the mentioned supported frame rates with ffmped, I get a new error

$ffmpeg -f avfoundation -r 30.000030 -i "1" out.mpg
ffmpeg version 3.4.1 Copyright (c) 2000-2017 the FFmpeg developers
  built with Apple LLVM version 9.0.0 (clang-900.0.39.2)
  configuration: --prefix=/Users/q433100/temp/brew-master/Cellar/ffmpeg/3.4.1 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-gpl --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
[avfoundation @ 0x7fb3c8802600] An error occurred: The activeVideoMinFrameDuration passed is not supported by the device.  Use -activeFormat.videoSupportedFrameRateRanges to discover valid ranges.1: Input/output error

Update 2: Setting the input frame rate to 15 directly in ffmpeg works. Now I just need to figure out how to do this in python with pygame.camera

$ ffmpeg -f avfoundation -r 15.000015 -i "1" out.avi
aL_eX
  • 1,453
  • 2
  • 15
  • 30
Thomas Hubregtsen
  • 449
  • 1
  • 5
  • 22

0 Answers0