我正在使用AVCaptureSession会话预设录制视频AVCaptureSessionPreset640x480.我正在使用AVCaptureVideoPreviewLayer非标准尺寸(300 x 300),在录制时将重力设置为纵横填充.它的设置如下:
self.previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:_captureSession];
_previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
_previewLayer.frame = _previewView.bounds; // 300 x 300
[_previewView.layer addSublayer:_previewLayer];
Run Code Online (Sandbox Code Playgroud)
录制视频后,我想以快速格式将其写入文件.在播放过程中,我再次以300 x 300非标准尺寸的图层播放视频.由于这些视频最终将通过网络连接传输,因此保留完整的640x480视频似乎很浪费.
导出视频以匹配300 x 300预览图层的最佳方法是什么?我是一个AVFoundation菜鸟,所以如果我以错误的方式解决这个问题,请告诉我.我只是希望录制期间在预览图层中显示的录制视频与磁盘上导出的视频相匹配.
avfoundation ios avcapture avcapturesession avvideocomposition
有没有方便的方法在iOS 6或iOS 7中使用HDR照片捕捉时使用AVCaptureSession?我搜索了StackOverflow并找不到任何东西.
NSInvalidArgumentException当我开始在一个视频viewController控制器中拍摄照片时开始录制视频时,我偶尔会遇到异常.我已经尝试了Google和So的一些建议,但仍然在startRecordingToOutputFileURL:fileURL通话时收到此错误.
如果我没有访问另一个拍摄照片的视图控制器,我就不会收到错误 - 只有当我拍照时才会出现错误,然后切换到进行视频录制的新视图控制器.
我认为拍照留下了一些遗留问题,但是当我初始化我的录像机视图控制器时,我没有错误设置会话和诸如此类的东西.有什么想法或如何从中恢复?为什么这是一个NSInvalidArgumentException例外?谢谢!
这是我的代码:
dispatch_async(dispatch_get_main_queue(), ^{
// Try to Fix bug:
// http://stackoverflow.com/questions/5979962/error-while-recording-video-on-iphone-using-avfoundation
[self.captureSession beginConfiguration];
// Ensure session is running
if ( [self.captureSession isRunning] == NO ) {
NSLog(@"Capture session is NOT running... Starting it now!");
[self.captureSession startRunning];
}
else {
NSLog(@"Capture session is ALREADY running...");
}
NSLog(@"File URL is: %@",fileURL);
NSLog(@"FileOutput is: %@",self.fileOutput);
[self.fileOutput startRecordingToOutputFileURL:fileURL recordingDelegate:self];
// Try to Fix bug:
// http://stackoverflow.com/questions/5979962/error-while-recording-video-on-iphone-using-avfoundation
[self.captureSession commitConfiguration];
});
Run Code Online (Sandbox Code Playgroud)
这是错误回溯:
2014-05-18 16:01:38.818 app[1699:60b] …Run Code Online (Sandbox Code Playgroud) 我正在尝试更改摄像机视图Front和.Back它运行良好Pause/Record.如果Flip Camera View录制的视频没有翻转选项它工作正常.但如果我们曾经,那么进一步录制视频不保存导致AVAssetWriterStatusFailed- The operation could not be completed.任何人都可以帮我找到我出错的地方吗?以下是我的代码.
Run Code Online (Sandbox Code Playgroud)- (void)flipCamera{ NSArray * inputs = _session.inputs; for ( AVCaptureDeviceInput * INPUT in inputs ) { AVCaptureDevice * Device = INPUT.device ; if ( [ Device hasMediaType : AVMediaTypeVideo ] ) { AVCaptureDevicePosition position = Device . position ; AVCaptureDevice * newCamera = nil ; AVCaptureDeviceInput * newInput = nil ; if ( position == AVCaptureDevicePositionFront ) newCamera = …
我们如何在iOS 7中使用蓝牙或wifi有效地将摄像头源从一个iOS设备传输到另一个iOS设备.下面是获取流缓冲区的代码.
- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection
{
// Create a UIImage from the sample buffer data
UIImage *image = [self imageFromSampleBuffer:sampleBuffer];
}
// Create a UIImage from sample buffer data
- (UIImage *) imageFromSampleBuffer:(CMSampleBufferRef) sampleBuffer
{
// Get a CMSampleBuffer's Core Video image buffer for the media data
CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
// Lock the base address of the pixel buffer
CVPixelBufferLockBaseAddress(imageBuffer, 0);
// Get the number of bytes per row for the pixel buffer
void *baseAddress = …Run Code Online (Sandbox Code Playgroud) bluetooth ios avcapturesession core-bluetooth multipeer-connectivity
这是Swift 2.我似乎无法找到任何相关内容.我收到了错误
Cannot invoke 'lockForConfiguration' with an argument list of type '(() -> ())'
Run Code Online (Sandbox Code Playgroud)
在这里的第二行.
if let device = captureDevice {
device.lockForConfiguration() {
device.videoZoomFactor = 1.0 + CGFloat(ratioValue)
device.unlockForConfiguration()
}
print(ratioValue)
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 AVCaptureDevice 等它编译和运行的音量级别,但这些值似乎只是随机的,而且我也不断收到溢出错误。
编辑:
RMS 范围在 0 到 20000 左右是否正常?
if let audioCaptureDevice : AVCaptureDevice = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeAudio){
try audioCaptureDevice.lockForConfiguration()
let audioInput = try AVCaptureDeviceInput(device: audioCaptureDevice)
audioCaptureDevice.unlockForConfiguration()
if(captureSession.canAddInput(audioInput)){
captureSession.addInput(audioInput)
print("added input")
}
let audioOutput = AVCaptureAudioDataOutput()
audioOutput.setSampleBufferDelegate(self, queue: GlobalUserInitiatedQueue)
if(captureSession.canAddOutput(audioOutput)){
captureSession.addOutput(audioOutput)
print("added output")
}
//supposed to start session not on UI queue coz it takes a while
dispatch_async(GlobalUserInitiatedQueue) {
print("starting captureSession")
self.captureSession.startRunning()
}
}
Run Code Online (Sandbox Code Playgroud)
...
func captureOutput(captureOutput: AVCaptureOutput!, let didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, fromConnection connection: AVCaptureConnection!) {
// Needs to be initialized …Run Code Online (Sandbox Code Playgroud) 我正在使用WebRTC及其使用AVCaptureSession。它可以正常工作几次,但有时会因此异常而崩溃。
断言失败:(_ internal-> figCaptureSession == NULL),功能-[AVCaptureVideoPreviewLayer attachToFigCaptureSession:],文件/BuildRoot/Library/Caches/com.apple.xbs/Sources/EmbeddedAVAVation/EmbeddedAVFoundation-1187.37.2.1/Aspen/AVCaptureVideoPreviewLayer
我有一个 MacOS Swift 应用程序,可以处理从麦克风录制的音频数据。麦克风具有立体声功能,但我只能录制单声道数据。
在下面的代码中,如果 I let alwaysMono = true,则 func setup() 报告活动格式是立体声,但将其覆盖为单声道。一切都适用于单声道输入流。
如果 I let alwaysMono = false,则 setup() 将 nChannels 设置为 2。但 captureOutput 不会获得任何数据。从 UnsafeMutableAudioBufferListPointer 返回的 AudioBuffer 总是有一个 nil mData。如果我不检查 nil mData,程序就会崩溃。
如何获得完整的立体声输入?
编辑:在 captureOutput 中,CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer 返回错误代码 -12737,对应于 kCMSampleBufferError_ArrayTooSmall。我检查了传入 captureOutput 的 sampleBuffer arg,我看不出它有任何明显的错误。但我不知道该找什么。
另一个编辑:我用内置单声道麦克风测试了我的代码,令我惊讶的是它认为它也是立体声,这表明我获取和使用 AVCaptureDevice.activeFormat 的方式显然有问题。我不知道从这里去哪里。
class Recorder: NSObject, AVCaptureAudioDataOutputSampleBufferDelegate {
let alwaysMono = false
var nChannels:UInt32 = 1
let session : AVCaptureSession!
static let realTimeQueue = DispatchQueue(label: "com.myapp.realtime",
qos: DispatchQoS( qosClass:DispatchQoS.QoSClass.userInitiated, relativePriority: 0 ))
override …Run Code Online (Sandbox Code Playgroud) iPhone 12/12 pro 支持以 10 位格式而不是 8 位格式录制杜比视觉 HDR 视频,但从 iOS 14.1 SDK 中不清楚 AVCaptureVideoDataOutput 是否支持传送 10 位样本缓冲区,这些缓冲区可以使用 AVAssetWriter 附加到视频文件。有没有人想过在SDK中是否可能?
编辑:许多应用程序(例如 Apple 的 Clips 应用程序)已开始支持 Dolby Vision 10 位视频录制。但是我尝试了所有可用的 API,包括 videoHDREnabled,但它不起作用。所以明确的问题是如何使用 AVFoundation API 录制 HDR(杜比视觉)视频?
EDIT2:我能够找出支持 10 位像素缓冲区格式的设备格式(即“x420”,而不是将 420v 或 420f 作为媒体子类型的设备格式)。在 iPhone 12 mini 上,4 种设备格式支持kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange 中的10 位像素缓冲区传送,尽管 AVFoundation 文档说这不是支持的像素格式(引用 - “在 iOS 上,唯一支持的键是 kCVPixelBufferPixelFormatTypeKey。支持的像素格式是 kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange,kCVPixelBufferPixelFormatTypeKey。和 kCVPixelFormatType_32BGRA .”)。下一步是确定是否可以手动选择用于录制的 HDR 格式为 Dolby Vision、HLG 或 HDR10。
avfoundation ios avcapturesession avassetwriter avcapturevideodataoutput
avcapturesession ×10
ios ×7
avfoundation ×5
swift ×3
objective-c ×2
audiobuffer ×1
avcapture ×1
bluetooth ×1
cocoa ×1
cocoa-touch ×1
ios6 ×1
ios7 ×1
macos ×1
uikit ×1
webrtc ×1