Can not apply video setting dictionary to AVCaptureMovieFileOutput

42 Views Asked by At

I wrote a small script to record video from a webcam, via PyObjC. I needed to apply a dictionary named video_settings which I specified in startRecordingToOutputFileURL_recordingDelegate_ function. with the settings of the video being recorded. But after the video recording test, the setting did not apply. How make that, to set settings dictionary for video, during recoding? Bellow, script:

import time

import pathlib

from AVFoundation import *

from AppKit import *


def record(length: int, name: str):
    session = AVCaptureSession.alloc().init()

    device = AVCaptureDevice.defaultDeviceWithMediaType_(AVMediaTypeVideo)

    input_ = AVCaptureDeviceInput.deviceInputWithDevice_error_(device, None)[0]
    session.addInput_(input_)
    output_url = NSURL.fileURLWithPath_(name)

    video_settings = {
        AVVideoWidthKey: 640,
        AVVideoHeightKey: 180,
        AVVideoCompressionPropertiesKey: {
            AVVideoAverageBitRateKey: 10000000,
            AVVideoProfileLevelKey: AVVideoProfileLevelH264HighAutoLevel,
            AVVideoAllowFrameReorderingKey: kCFBooleanFalse
        },
        AVVideoColorPropertiesKey: {
            AVVideoColorPrimariesKey: AVVideoColorPrimaries_ITU_R_709_2,
            AVVideoTransferFunctionKey: AVVideoTransferFunction_ITU_R_709_2,
            AVVideoFieldMode: kCFBooleanTrue

        }
    }

    output = AVCaptureMovieFileOutput.alloc().init()
    session.addOutput_(output)
    session.startRunning()

    output.startRecordingToOutputFileURL_recordingDelegate_(output_url, CFDictionaryRef(video_settings))

    time.sleep(length)

    output.stopRecording()
    session.stopRunning()
    return session


record(3, 'video_file.mov')

path = pathlib.Path('video_file.mov').cwd().__str__() + '/video_file.mov'
NSWorkspace.sharedWorkspace().openFile_(path)
0

There are 0 best solutions below