iOS- AVCaptureStillImageOutput 快门声问题

Colin丶 2014-09-24 10:03:03
加精
之前没接触过摄像头这块。
现在遇到了点问题。
希望高人解答。

问题描述:
我想获取摄像头对应的图片, 但不是通过UIImagePickerController获取系统的, 而是自定义拍照界面。
这里通过 AVCaptureStillImageOutput 来截取静图。 但是, 每次获取图片的时候, 都会有快门声。
我的真机是日版的, 本身拍照是关不掉快门声音。
但是,我用百度App的时候, 发现它图片搜索功能里面, 获取摄像头静图的时候是没有声音的。

所以想在获取静图的时候, 去掉快门声。

望高手支招..

我的代码如下:
1. 初始化

//3.创建、配置输出
captureOutput = [[AVCaptureStillImageOutput alloc] init];
NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys:AVVideoCodecJPEG,AVVideoCodecKey,nil];
[captureOutput setOutputSettings:outputSettings];
[self.session addOutput:captureOutput];



2. 获取静图
-(void)Captureimage
{
returnImage = [[UIImage alloc]init];
//get connection
AVCaptureConnection *videoConnection = nil;
for (AVCaptureConnection *connection in captureOutput.connections) {
for (AVCaptureInputPort *port in [connection inputPorts]) {
if ([[port mediaType] isEqual:AVMediaTypeVideo] ) {
videoConnection = connection;
break;
}
}
if (videoConnection) { break; }
}


//get UIImage
[captureOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler:
^(CMSampleBufferRef imageSampleBuffer, NSError *error) {
CFDictionaryRef exifAttachments =
CMGetAttachment(imageSampleBuffer, kCGImagePropertyExifDictionary, NULL);
if (exifAttachments) {
// Do something with the attachments.
}

// Continue as appropriate.
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
UIImage *t_image = [UIImage imageWithData:imageData];
returnImage = [[UIImage alloc]initWithCGImage:t_image.CGImage scale:1.0 orientation:UIImageOrientationRight];

}];

}


...全文
6404 26 打赏 收藏 转发到动态 举报
写回复
用AI写文章
26 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_34465774 2016-03-29
  • 打赏
  • 举报
回复
你是怎么去掉声音的啊,跪求解决方案
sinat_34085289 2016-03-24
  • 打赏
  • 举报
回复
怎么去掉的声音的,我的也去不掉
guomingyue1991 2015-12-08
  • 打赏
  • 举报
回复
怎么去掉声音的啊 求解啊
tanbiao1987 2015-06-23
  • 打赏
  • 举报
回复
o-c 是怎样解决的,能不能贴出来呀,正在纠结中。
beyondcj 2014-10-06
  • 打赏
  • 举报
回复
beyondcj 2014-10-03
  • 打赏
  • 举报
回复
chinacaoxinbo 2014-09-26
  • 打赏
  • 举报
回复
学习一下。。。。
baoweiaaaa 2014-09-25
  • 打赏
  • 举报
回复
写的不错不错。。。
Colin丶 2014-09-25
  • 打赏
  • 举报
回复
多谢各位了。 给分结帖。
Colin丶 2014-09-25
  • 打赏
  • 举报
回复
引用 13 楼 zhangao0086 的回复:
光这样是不够的,AVCaptureVideoDataOutput只是定义能够输出,还需要定义输入设备,比如前置、后置摄像头或者音频设备等,这些操作主要是为了初始化一个AVCaptureSession对象,AVCaptureSession的实例初始化好后,调用startRunning方法就能开启摄像头了,然后实现delegate回调,我晚一点可以出个OC的demo
不麻烦了。 oc的demo不用写了。 我已经弄好了。 多谢。 只是现在还是有点乱。 回头认真看看文档去。 谢谢了。
Bannings 2014-09-25
  • 打赏
  • 举报
回复
引用 14 楼 hitwhylz 的回复:
[quote=引用 13 楼 zhangao0086 的回复:] 光这样是不够的,AVCaptureVideoDataOutput只是定义能够输出,还需要定义输入设备,比如前置、后置摄像头或者音频设备等,这些操作主要是为了初始化一个AVCaptureSession对象,AVCaptureSession的实例初始化好后,调用startRunning方法就能开启摄像头了,然后实现delegate回调,我晚一点可以出个OC的demo
我的AVCaptureSession 已经定义好了。 摄像头也正常开启了。 你说的delegate是指这个吗? // 抽样缓存写入时所调用的委托程序 - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection 这个是什么时候被调用的?[/quote] 这个是当图像缓冲区有新的内容时就会回调,只要开启摄像头,就几乎是实时回调
Colin丶 2014-09-25
  • 打赏
  • 举报
回复
引用 13 楼 zhangao0086 的回复:
光这样是不够的,AVCaptureVideoDataOutput只是定义能够输出,还需要定义输入设备,比如前置、后置摄像头或者音频设备等,这些操作主要是为了初始化一个AVCaptureSession对象,AVCaptureSession的实例初始化好后,调用startRunning方法就能开启摄像头了,然后实现delegate回调,我晚一点可以出个OC的demo
我的AVCaptureSession 已经定义好了。 摄像头也正常开启了。 你说的delegate是指这个吗? // 抽样缓存写入时所调用的委托程序 - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection 这个是什么时候被调用的?
Bannings 2014-09-25
  • 打赏
  • 举报
回复
光这样是不够的,AVCaptureVideoDataOutput只是定义能够输出,还需要定义输入设备,比如前置、后置摄像头或者音频设备等,这些操作主要是为了初始化一个AVCaptureSession对象,AVCaptureSession的实例初始化好后,调用startRunning方法就能开启摄像头了,然后实现delegate回调,我晚一点可以出个OC的demo
laoer_2002 2014-09-25
  • 打赏
  • 举报
回复
都是高手
Colin丶 2014-09-25
  • 打赏
  • 举报
回复
引用 8 楼 zhangao0086 的回复:
[quote=引用 6 楼 hitwhylz 的回复:] [quote=引用 2 楼 zhangao0086 的回复:] 我有一篇草稿,正是说的利用AVCaptureSession自定义拍照以及录制视频。但是我在GitHub上已经更新了工程,你可以看一下:https://github.com/zhangao0086/iOS-CoreImage-Swift 实时滤镜:RealTimeFilter
你的可以关掉快门声吗? 我是用AVCaptureSession,实现了拍照功能。 就是拍照的时候有快门声。 [/quote] 你是通过系统API获取的照片,我是从缓冲区中取的图像数据: var outputImage = CIImage(CVPixelBuffer: imageBuffer)[/quote]
// 创建一个VideoDataOutput对象,将其添加到session
    AVCaptureVideoDataOutput *output = [[[AVCaptureVideoDataOutput alloc] init] autorelease];
    [session addOutput:output];

    // 配置output对象
    dispatch_queue_t queue = dispatch_queue_create("myQueue", NULL);
    [output setSampleBufferDelegate:self queue:queue];
    dispatch_release(queue);
是类似这样, 用AVCaptureVideoDataOutput取代AVCaptureStillImageOutput吗
Colin丶 2014-09-25
  • 打赏
  • 举报
回复
引用 8 楼 zhangao0086 的回复:
[quote=引用 6 楼 hitwhylz 的回复:] [quote=引用 2 楼 zhangao0086 的回复:] 我有一篇草稿,正是说的利用AVCaptureSession自定义拍照以及录制视频。但是我在GitHub上已经更新了工程,你可以看一下:https://github.com/zhangao0086/iOS-CoreImage-Swift 实时滤镜:RealTimeFilter
你的可以关掉快门声吗? 我是用AVCaptureSession,实现了拍照功能。 就是拍照的时候有快门声。 [/quote] 你是通过系统API获取的照片,我是从缓冲区中取的图像数据: var outputImage = CIImage(CVPixelBuffer: imageBuffer)[/quote] 您好。 手头有OC写的demo吗。 swift还没接触.. 看着费劲。
hugh_z 2014-09-25
  • 打赏
  • 举报
回复
learning
Bannings 2014-09-25
  • 打赏
  • 举报
回复
引用 6 楼 hitwhylz 的回复:
[quote=引用 2 楼 zhangao0086 的回复:] 我有一篇草稿,正是说的利用AVCaptureSession自定义拍照以及录制视频。但是我在GitHub上已经更新了工程,你可以看一下:https://github.com/zhangao0086/iOS-CoreImage-Swift 实时滤镜:RealTimeFilter
你的可以关掉快门声吗? 我是用AVCaptureSession,实现了拍照功能。 就是拍照的时候有快门声。 [/quote] 你是通过系统API获取的照片,我是从缓冲区中取的图像数据: var outputImage = CIImage(CVPixelBuffer: imageBuffer)
GW786228836 2014-09-25
  • 打赏
  • 举报
回复
Colin丶 2014-09-25
  • 打赏
  • 举报
回复
引用 2 楼 zhangao0086 的回复:
我有一篇草稿,正是说的利用AVCaptureSession自定义拍照以及录制视频。但是我在GitHub上已经更新了工程,你可以看一下:https://github.com/zhangao0086/iOS-CoreImage-Swift 实时滤镜:RealTimeFilter
你的可以关掉快门声吗? 我是用AVCaptureSession,实现了拍照功能。 就是拍照的时候有快门声。
加载更多回复(3)

29,027

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧