无法将视频设置字典应用于 AVCaptureMovieFileOutput

问题描述 投票:0回答:0

我写了一个小脚本来通过 PyObjC 从网络摄像头录制视频。我需要应用我在

video_settings
函数中指定的名为
startRecordingToOutputFileURL_recordingDelegate_
的字典。与正在录制的视频的设置。但是经过视频录制测试,设置不适用。如何在重新编码期间设置视频的设置字典? 贝娄,剧本:

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)
python macos video avfoundation pyobjc
© www.soinside.com 2019 - 2024. All rights reserved.