标签: avcapturesession

AVCaptureSession没有任何理由得到内存警告和崩溃

我正在开发一款操纵高清照片的应用程序.我正在用AVCaptureSession拍照,停止它然后对该照片应用效果.

令我疯狂的是,一切正常,仪器告诉我,我按时正确地释放了我使用的所有内存.它真的很高,有时达到100mb.但它迅速下降.

然后我重新开始我的捕获会话,我收到了内存警告.绝对没有理由; _; 我释放时使用的所有内存...然后下次我将重新启动捕获会话时应用程序崩溃.没有消息,没有日志,什么都没有.

我不知道如何解决这个问题,我不知道在哪里寻找...如果有人能帮助我一点点我会很高兴的!

提前致谢!

iphone warnings avcapturesession

15
推荐指数
2
解决办法
5526
查看次数

AVCaptureSession没有提供良好的照片质量和良好的分辨率

我正在努力AVCaptureSession捕捉图像.它的工作正常但没有给出好的分辨率.我将它与iPhone相机拍摄的图像进行了比较,我发现iPhone相机图像比AVCaptureSession图像要好得多.

我在stackOverflow上看到过3-4个关于此的链接,但找不到任何解决方案.

我也试过了所有的预设

AVCaptureSessionPresetPhoto, 
AVCaptureSessionPresetHigh, 
AVCaptureSessionPresetMedium, 
AVCaptureSessionPresetLow, 
AVCaptureSessionPreset352x288, 
AVCaptureSessionPreset640x480, 
AVCaptureSessionPreset1280x720, 
AVCaptureSessionPreset1920x1080, 
AVCaptureSessionPresetiFrame960x540, 
AVCaptureSessionPresetiFrame1280x720, 
Run Code Online (Sandbox Code Playgroud)

但是静止图像质量较差.如果我的问题不够明确或者我错过了什么,请告诉我.

iphone camera objective-c avcapturesession ios5

15
推荐指数
3
解决办法
1万
查看次数

如何使用RTMPStreamPublisher发布视频时在iPhone上存储视频?

现在我正在使用RTMPStreamPublisherwowzaserver发布视频.它正在成功上传,但有人能告诉我如何在上传到服务器时将相同的视频存储在iPhone上吗?

我使用https://github.com/slavavdovichenko/MediaLibDemos,但没有太多可用的文档.如果我可以存储发送的数据,那么我的工作就会成功.

以下是他们用于上传流的方法,但我找不到在iPhone设备上存储相同视频的方法:

// ACTIONS

-(void)doConnect {
#if 0 // use ffmpeg rtmp 
    NSString *url = [NSString stringWithFormat:@"%@/%@", hostTextField.text, streamTextField.text];
    upstream = [[BroadcastStreamClient alloc] init:url  resolution:RESOLUTION_LOW];
    upstream.delegate = self;
    upstream.encoder = [MPMediaEncoder new];
    [upstream start];
    socket = [[RTMPClient alloc] init:host]
    btnConnect.title = @"Disconnect";     
    return;
#endif

#if 0 // use inside RTMPClient instance
    upstream = [[BroadcastStreamClient alloc] init:hostTextField.text resolution:RESOLUTION_LOW];
    //upstream = [[BroadcastStreamClient alloc] initOnlyAudio:hostTextField.text];
    //upstream = [[BroadcastStreamClient alloc] initOnlyVideo:hostTextField.text resolution:RESOLUTION_LOW];

#else // use outside RTMPClient instance

    if …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c rtmp ios avcapturesession

15
推荐指数
1
解决办法
1126
查看次数

使用AVCaptureVideoDataOutput或AVCaptureMovieFileOutput使用Swift捕获视频

我需要一些关于如何在不使用UIImagePicker的情况下捕获视频的指导.视频需要在按钮单击时启动和停止,然后将此数据保存到NSDocumentDirectory.我是swift的新手,所以任何帮助都会有用.

我需要帮助的代码部分是启动和停止视频会话并将其转换为数据.我创建了一个运行captureStillImageAsynchronouslyFromConnection的图片,并将此数据保存到NSDocumentDirectory.我已经设置了一个视频捕获会话,并准备好代码保存数据,但不知道如何从会话中获取数据.

var previewLayer : AVCaptureVideoPreviewLayer?
var captureDevice : AVCaptureDevice?
var videoCaptureOutput = AVCaptureVideoDataOutput()

let captureSession = AVCaptureSession()

override func viewDidLoad() {
    super.viewDidLoad()

    captureSession.sessionPreset = AVCaptureSessionPreset640x480
    let devices = AVCaptureDevice.devices()

    for device in devices {
        if (device.hasMediaType(AVMediaTypeVideo)) {
            if device.position == AVCaptureDevicePosition.Back {
                captureDevice = device as? AVCaptureDevice
                if captureDevice != nil {
                    beginSession()
                }
            }   
        }
    }
}

func beginSession() {
    var err : NSError? = nil
    captureSession.addInput(AVCaptureDeviceInput(device: captureDevice, error: &err)) …
Run Code Online (Sandbox Code Playgroud)

avcapturesession swift

15
推荐指数
1
解决办法
1万
查看次数

如何从AVCapturePhoto生成具有正确方向的UIImage?

我正在调用AVFoundation的委托方法来处理照片捕获,但是我很难将它生成的AVCapturePhoto转换为具有正确方向的UIImage.虽然下面的例程是成功的,但我总是得到一个面向右侧的UIImage(UIImage.imageOrientation = 3).使用UIImage(数据:图像)并尝试首先使用photo.cgImageRepresentation()时,我无法提供方向?takeRetainedValue()也没有帮助.请协助.

在此处,图像方向至关重要,因为生成的图像将被输入Vision框架工作流程.

func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) {
    // capture image finished
    print("Image captured.")
    if let imageData = photo.fileDataRepresentation() {
        if let uiImage = UIImage(data: imageData){
            // do stuff to UIImage
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

更新1: 阅读Apple的Photo Capture编程指南(iOS11过时),我确实找到了一件我做错的事情:

  1. 在每次捕获调用(self.capturePhotoOutput.capturePhoto)时,必须与PhotoOutput对象建立连接并更新其方向以匹配拍摄照片时设备的方向.为此,我创建了UIDeviceOrientation的扩展,并在我创建的snapPhoto()函数上使用它来调用捕获例程并等待执行didFinishProcessingPhoto委托方法.我添加了代码的快照,因为这里的代码示例分隔符似乎没有正确显示它们. 在此输入图像描述 在此输入图像描述

更新2 链接到GitHub上的完整项目:https://github.com/agu3rra/Out-Loud

avfoundation avcapturesession swift4 ios11

15
推荐指数
4
解决办法
6399
查看次数

视频以错误的方向保存AVCaptureSession

我正在尝试录制视频(不显示相机)并保存.但正在保存的视频无法以正确的方向保存.我已经尝试强制UIViewController成为一个特定的方向,但这没有帮助.所有视频都以纵向录制.我的代码如下:

session = [[AVCaptureSession alloc] init];
[session beginConfiguration];
session.sessionPreset = AVCaptureSessionPresetHigh;


AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
for (AVCaptureDevice *cam in [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo])
{
    if (cam.position == AVCaptureDevicePositionFront)
        device = cam;
}

NSError *error = nil;
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
if (!input) {
    // Handle the error appropriately.
    NSLog(@"ERROR: trying to open camera: %@", error);
}

AVCaptureDevice *audioDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
AVCaptureDeviceInput * audioInput = [AVCaptureDeviceInput deviceInputWithDevice:audioDevice error:nil];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [paths objectAtIndex:0]; …
Run Code Online (Sandbox Code Playgroud)

objective-c ios avcapturesession

14
推荐指数
2
解决办法
1万
查看次数

会话重启后AVcapture会话缓慢启动

我有一个主视图控制器,它可以分割成具有avcapturesession的第二个视图控制器.我第一次从主视图控制器切换到捕获会话控制器,大约需要50ms(使用"仪器"检查).然后我从捕获会话中回到主视图控制器,然后从主控制器返回到avcapturesession控制器.每次从主视图控制器切换到avcapturesession需要更长的时间,并且通过第5次或第6次迭代,segue需要大约10秒.(与第一次50ms相比.)我已经粘贴了下面的avcapture会话的相关代码.谁能帮忙解决这个问题?谢谢

此类(类型为NSObject)管理
实际实现avcapturesession 的第二个视图控制器的捕获会话

#import "CaptureSessionManager.h"

@implementation CaptureSessionManager

@synthesize captureSession;
@synthesize previewLayer;

#pragma mark Capture Session Configuration

- (id)init {
    if ((self = [super init])) {
        [self setCaptureSession:[[AVCaptureSession alloc] init]];
    }
    return self;
}

- (void)addVideoPreviewLayer {
    [self setPreviewLayer:[[[AVCaptureVideoPreviewLayer alloc] initWithSession:[self     captureSession]] autorelease]];
    [[self previewLayer] setVideoGravity:AVLayerVideoGravityResizeAspectFill];

}

- (void)addVideoInput {
        AVCaptureDevice *videoDevice = [AVCaptureDevice   defaultDeviceWithMediaType:AVMediaTypeVideo];
     if (videoDevice) {
         NSError *error;
        AVCaptureDeviceInput *videoIn = [AVCaptureDeviceInput  deviceInputWithDevice:videoDevice error:&error];
        if (!error) {
           if ([[self captureSession] canAddInput:videoIn])
               [[self captureSession] addInput:videoIn];

        //else
        //  NSLog(@"Couldn't add …
Run Code Online (Sandbox Code Playgroud)

performance ios avcapturesession

14
推荐指数
2
解决办法
7165
查看次数

AVCaptureSession和背景音频iOS 7

每当我启动以麦克风作为输入运行的AVCaptureSession时,它都会取消当前正在运行的任何背景音乐(例如iPod音乐).如果我注释掉添加音频输入的行,背景音频将继续.

有没有人知道用麦克风录制视频剪辑的方法,同时继续允许播放背景音频?当您尝试录制视频并且当前正在播放音乐时,也会出现错误.

试图这样做:

[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: nil];
UInt32 doSetProperty = 1;
AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(doSetProperty), &doSetProperty);
[[AVAudioSession sharedInstance] setActive: YES error: nil];
Run Code Online (Sandbox Code Playgroud)

'AudioSessionSetProperty' is deprecated: first deprecated in iOS 7.0

所以我试着这样做:

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *setCategoryError = nil; 
[audioSession setCategory:AVAudioSessionCategoryPlayback
              withOptions:AVAudioSessionCategoryOptionMixWithOthers
                    error:&setCategoryError];
[audioSession setActive:YES error:nil];
Run Code Online (Sandbox Code Playgroud)

但最后它没有奏效.感谢帮助!

objective-c ios avcapturesession avcapturedevice avaudiosession

14
推荐指数
2
解决办法
6149
查看次数

AVCaptureMovieFileOutput - 没有活动/启用的连接

我正在尝试使用AVFoundation在我的iPhone应用程序中录制视频.但每当我单击"录制"按钮时,应用程序都会崩溃

- [AVCaptureMovieFileOutput startRecordingToOutputFileURL:recordingDelegate:] - 没有活动/启用的连接.

我知道同样的问题,但是它的答案都没有帮助我.我的问题是相同的代码完全适用于另一个应用程序,当我尝试在这个应用程序中使用完全相同的代码 - 崩溃.但仍然照片捕捉工作正常.

在这里添加我的代码 - 请帮助我,提前致谢

  -(void)viewDidLoad
  {
 [super viewDidLoad];
 self.captureSession = [[AVCaptureSession alloc] init];

   AVCaptureDevice *videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
AVCaptureDevice *audioDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];

  self.videoInput = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:nil];
  self.audioInput = [[AVCaptureDeviceInput alloc] initWithDevice:audioDevice error:nil];

  self.stillImageOutput = [[AVCaptureStillImageOutput alloc] init];
  NSDictionary *stillImageOutputSettings = [[NSDictionary alloc] initWithObjectsAndKeys:
                                          AVVideoCodecJPEG, AVVideoCodecKey, nil];
  [self.stillImageOutput setOutputSettings:stillImageOutputSettings];

  self.movieOutput = [[AVCaptureMovieFileOutput alloc] init];

  [self.captureSession addInput:self.videoInput];
  [self.captureSession addOutput:self.stillImageOutput];




   previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:self.captureSession];
   UIView *aView = self.view;
   previewLayer.frame = CGRectMake(70, 190, 270, …
Run Code Online (Sandbox Code Playgroud)

video objective-c avfoundation ios avcapturesession

14
推荐指数
3
解决办法
9931
查看次数

使用AVFoundation在Swift 3.0中扫描条形码或QR码

我正在按照本教程尝试将代码从Swift 2.0转换为3.0.但是当我启动应用程序时,该应用程序无法运行!我的意思是,没有任何反应 这是我的代码:

视图控制器:

class ViewController: UIViewController ,BarcodeDelegate {

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

        let barcodeViewController: BarcodeViewController = segue.destination as! BarcodeViewController
        barcodeViewController.delegate = self

    }



    func barcodeReaded(barcode: String) {
        codeTextView.text = barcode
        print(barcode)
    }

}
Run Code Online (Sandbox Code Playgroud)

BarcodeVC:

import AVFoundation


protocol BarcodeDelegate {

    func barcodeReaded(barcode: String)
}

class BarcodeViewController: UIViewController,AVCaptureMetadataOutputObjectsDelegate {

    var delegate: BarcodeDelegate?
    var captureSession: AVCaptureSession!
    var code: String?


    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        print("works")

        self.captureSession = …
Run Code Online (Sandbox Code Playgroud)

ios avcapturesession swift swift3

14
推荐指数
2
解决办法
2万
查看次数