jbaiter / gphoto2-cffi

Python bindings for libgphoto2 with an idiomatic API
GNU Lesser General Public License v3.0
37 stars 16 forks source link

capture_video() not working with a Canon camera #18

Open johker01 opened 7 years ago

johker01 commented 7 years ago

When trying to capture a video with a Canon EOS 60D using the following piece of code

import gphoto2cffi as gp

camera = gp.Camera()
videoData = camera.capture_video(2)

the following error message shows up

Traceback (most recent call last):
  File "test.py", line 8, in <module>
    context = gp.gphoto2.VideoCaptureContext(camera)
  File "/Users/johker/git/photobooth.py/venv/lib/python3.6/site-packages/gphoto2cffi/gphoto2.py", line 147, in __init__
    self.camera._get_config()['actions']['movie'].set(True)
KeyError: 'movie'

Indeed, there is no such key:

>>> pprint(camera._get_config())
{'actions': {'autofocusdrive': ConfigItem('Drive Canon DSLR Autofocus', toggle, False, rw),
             'cancelautofocus': ConfigItem('Cancel Canon DSLR Autofocus', toggle, False, rw),
             'eosremoterelease': ConfigItem('Canon EOS Remote Release', selection, 'None', rw),
             'eoszoom': ConfigItem('Canon EOS Zoom', text, '0', rw),
             'eoszoomposition': ConfigItem('Canon EOS Zoom Position', text, '0,0', rw),
             'manualfocusdrive': ConfigItem('Drive Canon DSLR Manual focus', selection, 'None', rw),
             'opcode': ConfigItem('PTP Opcode', text, '0x1001,0xparam1,0xparam2', rw),
             'syncdatetime': ConfigItem('Synchronize camera date and time with PC', toggle, False, rw),
             'uilock': ConfigItem('UI Lock', toggle, None, rw),
             'viewfinder': ConfigItem('Canon EOS Viewfinder', toggle, None, rw)},
 'capturesettings': {'aeb': ConfigItem('Auto Exposure Bracketing', selection, 'off', rw),
                     'aperture': ConfigItem('Aperture', selection, 'implicit auto', rw),
                     'autoexposuremode': ConfigItem('Canon Auto Exposure Mode', selection, 'Unknown value 0014', rw),
                     'bracketmode': ConfigItem('Bracket Mode', text, '0', rw),
                     'drivemode': ConfigItem('Drive Mode', selection, 'Single', rw),
                     'exposurecompensation': ConfigItem('Exposure Compensation', selection, '0', rw),
                     'focusmode': ConfigItem('Focus Mode', selection, 'One Shot', rw),
                     'picturestyle': ConfigItem('Picture Style', selection, 'Standard', rw),
                     'shutterspeed': ConfigItem('Shutter Speed', selection, 'auto', rw)},
 'imgsettings': {'colorspace': ConfigItem('Color Space', selection, 'sRGB', rw),
                 'colortemperature': ConfigItem('Color Temperature', text, '5200', rw),
                 'imageformat': ConfigItem('Image Format', selection, 'Large Fine JPEG', rw),
                 'imageformatsd': ConfigItem('Image Format SD', selection, 'Large Fine JPEG', rw),
                 'iso': ConfigItem('ISO Speed', selection, 'Auto', rw),
                 'whitebalance': ConfigItem('WhiteBalance', selection, 'Auto', rw),
                 'whitebalancexa': ConfigItem('WhiteBalance X A', text, '0', rw),
                 'whitebalancexb': ConfigItem('WhiteBalance X B', text, '0', rw)},
 'other': {'5001': ConfigItem('Battery Level', selection, '25', ro),
           'd303': ConfigItem('PTP Property 0xd303', text, '1', ro),
           'd402': ConfigItem('PTP Property 0xd402', text, 'Canon EOS 60D', ro),
           'd406': ConfigItem('PTP Property 0xd406', text, 'Unknown Initiator', rw),
           'd407': ConfigItem('PTP Property 0xd407', text, '1', ro)},
 'settings': {'artist': ConfigItem('Artist', text, '', rw),
              'autopoweroff': ConfigItem('Auto Power Off', text, '120', rw),
              'capture': ConfigItem('Capture', toggle, False, rw),
              'capturetarget': ConfigItem('Capture Target', selection, 'Memory card', rw),
              'copyright': ConfigItem('Copyright', text, '', rw),
              'customfuncex': ConfigItem('Custom Functions Ex', text, '50,1,4,44,5,701,1,0,704,1,0,706,1,0,80b,1,0,80f,1,0,', rw),
              'datetime': ConfigItem('Camera Date and Time', date, 1487276077, rw),
              'depthoffield': ConfigItem('Depth of Field', text, '0', rw),
              'evfmode': ConfigItem('EVF Mode', selection, 'Unknown value 0002', rw),
              'focusinfo': ConfigItem('Focus Info', text, 'eosversion=2,size=5184x3456,size2=5184x3456,points={{0,743,86,108},{-860,393,107,88},{860,393,107,88},{-1368,0,107,88},{0,0,131,129},{1368,0,107,88},{-860,-393,107,88},{860,-393,107,88},{0,-743,86,108}},select={},unknown={10000000ffff}', rw),
              'movierecordtarget': ConfigItem('Recording Destination', selection, 'None', rw),
              'output': ConfigItem('Camera Output', selection, 'Off', rw),
              'ownername': ConfigItem('Owner Name', text, '', rw),
              'reviewtime': ConfigItem('Quick Review Time', selection, '2 seconds', rw)},
 'status': {'': ConfigItem('Battery Level', text, '25%', ro),
            'availableshots': ConfigItem('Available Shots', text, '968', rw),
            'batterylevel': ConfigItem('Battery Level', text, 'Low', rw),
            'cameramodel': ConfigItem('Camera Model', text, 'Canon EOS 60D', rw),
            'deviceversion': ConfigItem('Device Version', text, '3-1.1.2', rw),
            'eosserialnumber': ConfigItem('Serial Number', text, 'xxx', rw),
            'lensname': ConfigItem('Lens Name', text, 'EF-S15-85mm f/3.5-5.6 IS USM', rw),
            'manufacturer': ConfigItem('Camera Manufacturer', text, 'Canon Inc.', rw),
            'model': ConfigItem('Camera Model', text, '2147484295', rw),
            'ptpversion': ConfigItem('PTP Version', text, '256', rw),
            'serialnumber': ConfigItem('Serial Number', text, 'xxx', rw),
            'shuttercounter': ConfigItem('Shutter Counter', text, '22636', rw),
            'vendorextension': ConfigItem('Vendor Extension', text, 'None', rw)}}

I made sure that my camera is switched to video mode using the hardware dial wheel, as my camera doesn't support recording video in Av/Tv/P/... modes. Recording a video using gphoto2 using the following command works: gphoto2 --set-config eosviewfinder=1 --set-config movierecordtarget=Card --wait-event=10s --set-config movierecordtarget=None --wait-event-and-download=2s

Trying to replicate the gphoto2 command using gphoto2cffi doesn't work unfortunately:

import time

import gphoto2cffi as gp

camera = gp.Camera()
print('viewfinder')
camera._get_config()['actions']['viewfinder'].set(True)
print('card')
camera._get_config()['settings']['movierecordtarget'].set('Card')
print('sleep')
time.sleep(5)
print('none')
camera._get_config()['settings']['movierecordtarget'].set('None')

The following error occurs:

viewfinder
card
Traceback (most recent call last):
  File "test.py", line 10, in <module>
    camera._get_config()['settings']['movierecordtarget'].set('Card')
  File "/Users/johker/git/photobooth.py/venv/lib/python3.6/site-packages/gphoto2cffi/gphoto2.py", line 100, in wrapped
    rval = meth(self, *args, **kwargs)
  File "/Users/johker/git/photobooth.py/venv/lib/python3.6/site-packages/gphoto2cffi/gphoto2.py", line 500, in set
    lib.gp_camera_set_config(self._cam._cam, self._root, self._cam._ctx)
  File "/Users/johker/git/photobooth.py/venv/lib/python3.6/site-packages/gphoto2cffi/backend.py", line 123, in <lambda>
    return lambda *a, **kw: self._check_error(val(*a, **kw))
  File "/Users/johker/git/photobooth.py/venv/lib/python3.6/site-packages/gphoto2cffi/backend.py", line 116, in _check_error
    raise errors.error_from_code(rval)
gphoto2cffi.errors.CameraBusy: -110
jbaiter commented 7 years ago

Hm... It would probably be a good idea to consult the gphoto source code and see which library calls are made based on your command-line query. I will probably also have to look into some changes that were made to the gphoto2 API since 2015 (when this package was mainly developed), from the ChangeLog I can see that there were a lot of changes to make Canon EOS work better, maybe this is related.