Created
March 16, 2016 18:48
-
-
Save timsutton/0c6439eb6eb1621a5964 to your computer and use it in GitHub Desktop.
Screen recording with Python and AVFoundation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# pylint: disable-msg=e1101,e0611 | |
import time | |
import AVFoundation as AVF | |
import Quartz | |
from Foundation import NSObject, NSURL | |
def main(): | |
display_id = Quartz.CGMainDisplayID() | |
session = AVF.AVCaptureSession.alloc().init() | |
screen_input = AVF.AVCaptureScreenInput.alloc().initWithDisplayID_(display_id) | |
file_output = AVF.AVCaptureMovieFileOutput.alloc().init() | |
session.addInput_(screen_input) | |
session.addOutput_(file_output) | |
session.startRunning() | |
file_url = NSURL.fileURLWithPath_('foo.mov') | |
# Cheat and pass a dummy delegate object where normally we'd have a | |
# AVCaptureFileOutputRecordingDelegate | |
file_url = file_output.startRecordingToOutputFileURL_recordingDelegate_( | |
file_url, NSObject.alloc().init()) | |
time.sleep(10) | |
session.stopRunning() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
update: got it working :D