在pygame.Camera中设置输入帧速率

时间:2018-01-26 13:49:07

标签: python ffmpeg pygame

我正在尝试从OS X上的网络摄像头获取输入流

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

我收到错误(见下文),但有2条信息无法拼接在一起。乍一看,看起来我没有正确的相机(不是video4linux)。但是,在运行时

ffmpeg -f avfoundation -list_devices true -i ""

我列出了

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

错误的下一部分讨论了帧速率。看起来帧速率稍微偏离,我接下来选择不同的帧速率。使用pygcam会有可能吗?这会解决我的问题吗?

错误:

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

更新: 如果我尝试使用ffmped强制提到所支持的帧速率之一,则会出现新的错误

$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

更新2: 直接在ffmpeg中将输入帧速率设置为15可以正常工作。现在我只需要弄清楚如何在python中使用pygame.camera

来做到这一点
$ ffmpeg -f avfoundation -r 15.000015 -i "1" out.avi

0 个答案:

没有答案