Using CMSampleBufferRef with CMSampleBufferGet* will result in ValueError

Issue #257 resolved
Gentoli created an issue

Hello,

I am trying to use AVFoundation to capture display with AVCaptureScreenInput and AVCaptureStillImageOutput. After all I got a CMSampleBufferRef.

CMSapleBufferGet* should take a CMSampleBufferRef and return the attribute but insted gives a ValueError

ValueError: depythonifying 'pointer', got 'CMSampleBufferRef'

I am new to pyobjc, this might just be I am not using the bridge correctly.

Edit:
This will work if the Type Encoding is changed for CMSapleBufferGet* functions.

Thanks!

Comments (4)

  1. Gentoli reporter

    Sample Code

    import time
    import AVFoundation as AVF
    import Quartz
    import CoreMedia as CM
    
    def capture_handle(bufRecv,err):
        print("callback")
        try:
            print(CM.CMSampleBufferGetNumSamples(bufRecv))
        except ValueError as err:
            print(err)
        pass 
    
    def main():
        display_id = Quartz.CGMainDisplayID()
    
        session = AVF.AVCaptureSession.alloc().init()
        screen_input = AVF.AVCaptureScreenInput.alloc().initWithDisplayID_(display_id)
        mem_output = AVF.AVCaptureStillImageOutput.alloc().init()
    
        session.addInput_(screen_input)
        session.addOutput_(mem_output)
        session.startRunning()
    
        connection = mem_output.connectionWithMediaType_(AVF.AVMediaTypeVideo)
        if connection:
            mem_output.captureStillImageAsynchronouslyFromConnection_completionHandler_(connection,capture_handle)
    
        time.sleep(2)
        session.stopRunning()
    
    
    if __name__ == "__main__":
        main()
        print("end")
    

    Output

    callback
    ValueError: depythonifying 'pointer', got 'CMSampleBufferRef'
    end
    

    Tested in Python 2.7 and 3.7

  2. Ronald Oussoren repo owner

    This looks like a bug in the metadata. I'll see if I can push out an update next weekend.

  3. Log in to comment