Ignore cameras that do not support MJPEG format video.
authorJoseph Coffland <joseph@cauldrondevelopment.com>
Wed, 19 Feb 2020 23:38:48 +0000 (15:38 -0800)
committerJoseph Coffland <joseph@cauldrondevelopment.com>
Wed, 19 Feb 2020 23:38:48 +0000 (15:38 -0800)
CHANGELOG.md
src/py/bbctrl/Camera.py
src/py/bbctrl/__init__.py

index 169b16a44f03b1a0b0dd4883f1392014db21c062..690f78bc300823767a2fefbb0e7f6602b8b3e05b 100644 (file)
@@ -10,6 +10,7 @@ Buildbotics CNC Controller Firmware Changelog
  - Add axis bounds GCode variables ``#<_x_min>``, ``#<_x_max>``, etc.
  - Expose ``junction-accel`` planning parameter.
  - Fixed problem with manual firmware upload on OSX.
+ - Ignore cameras that do not support MJPEG format video.
 
 ## v0.4.12
  - Segments straddle arc in linearization.
index 796500cc1af939ee62016846e62c49ab7cd5c50a..17f1bb7dfea59b0bf9c4475a0a637b6e69616141 100755 (executable)
@@ -285,7 +285,7 @@ class Camera(object):
         self.width = args.width
         self.height = args.height
         self.fps = args.fps
-        self.fourcc = string_to_fourcc(args.fourcc)
+        self.fourcc = 'MJPG'
         self.max_clients = args.camera_clients
 
         self.overtemp = False
@@ -376,11 +376,22 @@ class Camera(object):
             if caps.capabilities & v4l2.V4L2_CAP_VIDEO_CAPTURE == 0:
                 raise Exception('Video capture not supported.')
 
-            self.log.info('Formats: %s', self.dev.get_formats())
-            self.log.info('Sizes: %s', self.dev.get_frame_sizes(self.fourcc))
+            fourcc  = string_to_fourcc(self.fourcc)
+            formats = self.dev.get_formats()
+            sizes   = self.dev.get_frame_sizes(fourcc)
+
+            self.log.info('Formats: %s', formats)
+            self.log.info('Sizes: %s', sizes)
             self.log.info('Audio: %s', self.dev.get_audio())
 
-            self.dev.set_format(self.width, self.height, fourcc = self.fourcc)
+            hasFormat = False
+            for name, description in formats:
+                if name == self.fourcc: hasFormat = True
+
+            if not hasFormat:
+                raise Exception(self.fourcc + ' video format not supported.')
+
+            self.dev.set_format(self.width, self.height, fourcc = fourcc)
             self.dev.set_fps(self.fps)
             self.dev.create_buffers(4)
             self.dev.start()
index acde54c45539dbc5b2a4202d385152af3f6554e2..b1a64522237d2ab9ec200733f2821e6a7e3e95a8 100644 (file)
@@ -150,8 +150,6 @@ def parse_args():
                         help = 'Camera height')
     parser.add_argument('--fps', default = 15, type = int,
                         help = 'Camera frames per second')
-    parser.add_argument('--fourcc', default = 'MJPG',
-                        help = 'Camera frame format')
     parser.add_argument('--camera-clients', default = 4,
                         help = 'Maximum simultaneous camera clients')
     parser.add_argument('--demo', action = 'store_true',