Tag: avfoundation

在iOS中压缩video

我看过这个问题和这个问题 ,都没能帮上忙。 我已经尝试了以下内容: – (void)compress:(NSURL *)videoPath completionBlock:(void(^)(id data, BOOL result))block{ self.outputFilePath = [[NSString alloc] initWithFormat:@"%@%@", NSTemporaryDirectory(), @"output.mov"]; NSURL *outputURL = [NSURL fileURLWithPath:self.outputFilePath]; [self compressVideoWithURL:self.movieURL outputURL:outputURL handler:^(AVAssetExportSession *exportSession) { }]; } – (void)compressVideoWithURL:(NSURL*)inputURL outputURL:(NSURL*)outputURL handler:(void (^)(AVAssetExportSession*))handler { AVURLAsset *asset = [AVURLAsset assetWithURL:self.movieURL]; AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetLowQuality]; exportSession.fileLengthLimit = 3000000; exportSession.outputURL = outputURL; exportSession.outputFileType […]

AVAssetWriter如何创build没有压缩的movvideo?

我从一系列图像创buildvideo。 我的工作的目的是创build一个没有压缩的.movvideo。 我已经在开发库中看到它存在一个关键“AVVideoCompressionPropertiesKey”,但我不知道如何用这个键指定没有压缩。 请问你能帮帮我吗? 这是我的示例代码: NSDictionary *videoCleanApertureSettings = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:320], AVVideoCleanApertureWidthKey, [NSNumber numberWithInt:480], AVVideoCleanApertureHeightKey, [NSNumber numberWithInt:10], AVVideoCleanApertureHorizontalOffsetKey, [NSNumber numberWithInt:10], AVVideoCleanApertureVerticalOffsetKey, nil]; NSDictionary *codecSettings = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:960000], AVVideoAverageBitRateKey, [NSNumber numberWithInt:1],AVVideoMaxKeyFrameIntervalKey, videoCleanApertureSettings, AVVideoCleanApertureKey, nil]; NSDictionary *videoOutputSettings = [NSDictionary dictionaryWithObjectsAndKeys:AVVideoCodecH264, AVVideoCodecKey,codecSettings,AVVideoCompressionPropertiesKey, [NSNumber numberWithInt:size.width], AVVideoWidthKey, [NSNumber numberWithInt:size.height], AVVideoHeightKey, nil]; self.videoWriterInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:videoOutputSettings];

无法使用AVCapturePhotoOutput捕捉照片swift + xcode

我正在一个自定义相机应用程序和教程使用AVCaptureStillImageOutput,这是不赞成ios 10.我已经设置了相机,我现在卡在如何拍照 这里是我充分的看法,我有相机 import UIKit import AVFoundation var cameraPos = "back" class View3: UIViewController,UIImagePickerControllerDelegate,UINavigationControllerDelegate { @IBOutlet weak var clickButton: UIButton! @IBOutlet var cameraView: UIView! var session: AVCaptureSession? var stillImageOutput: AVCapturePhotoOutput? var videoPreviewLayer: AVCaptureVideoPreviewLayer? override func viewDidLoad() { super.viewDidLoad() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) clickButton.center.x = cameraView.bounds.width/2 […]

AVPlayerViewController使用纯audioAVPlayer

刚开始与AVKit,我想播放一些audio。 在Mastering Modern Media Playback中使用新的AVPlayerViewController会很好,所以我有一个现成的播放/暂停/searchUI。 我基本上有一个容器视图的故事板,有一个embedded到AVPlayerViewController的segue。 然后我使用: override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { if (segue.identifier == "embedAudio") { var playerViewController:AVPlayerViewController = segue.destinationViewController as AVPlayerViewController playerViewController.player = AVPlayer(URL: NSURL(string: "http://dts.podtrac.com/redirect.mp3/files.serialpodcast.org/sites/default/files/podcast/1420057326/serial-s01-e01.mp3")) } } 它embedded很好,并播放,但它有一个大的黑色的QuickTime符号video将是。 我想知道是否有办法让它看起来更像音乐或播客应用程序。

创build一个应用程序,从iPhone屏幕创build一个video,并添加来自耳机/audioinput的audio

我试图从这个应用程序(ShowME)完成从iPad屏幕创build教程video使用AVAssetWriter我能够捕捉屏幕的video。 我尝试使用AVCaptureDevice,但它不工作。 我不知道什么是错的。 我从这个链接学习了从iPhone屏幕捕捉video- 一个非常好的turorial。 但它不会捕获任何audio以及屏幕video。 所以我给了这样一个尝试: -(void)setUpMike{ NSError* error = nil; // Setup the audio input AVCaptureDevice *audioDevice = [AVCaptureDevice defaultDeviceWithMediaType: AVMediaTypeAudio]; AVCaptureDeviceInput *audioInput = [AVCaptureDeviceInput deviceInputWithDevice:audioDevice error:&error ]; // Setup the audio output _audioOutput = [[AVCaptureAudioDataOutput alloc] init]; // Create the session _capSession = [[AVCaptureSession alloc] init]; [_capSession addInput:audioInput]; [_capSession addOutput:_audioOutput]; _capSession.sessionPreset = […]

在后台启动AVAssetExportSession

我的应用程序做了一些处理,在某些时候需要调用一个AVAssetExportSession。 如果会话已经开始,然后我背景的应用程序,一切正常完成。 但是,如果我在调用exportAsynchronouslyWithCompletionHandler之前后台应用程序。 我得到这个错误: AVAssetExportSessionStatusFailed Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo=0x1e550db0 {NSLocalizedFailureReason=An unknown error occurred (-12985), NSUnderlyingError=0x1e574910 "The operation couldn‚Äôt be completed. (OSStatus error -12985.)", NSLocalizedDescription=The operation could not be completed} 是否有可能在后台启动AVAssetExportSession?

使用AVFoundationlogging方形video并添加水印

我正在尝试做的插图 我正在尝试执行以下操作: 播放音乐 录制一个方形video(我在视图中有一个容器,显示你正在录制的内容) 在顶部添加一个标签,在方形video的左下angular添加应用程序的图标和名称。 到目前为止,我设法播放音乐,将AVCaptureVideoPreviewLayer显示在一个方形容器中,并将video保存到相机胶卷中。 问题是,我几乎找不到一些关于使用AVFoundation的模糊教程,这是我的第一个应用程序,使事情变得相当困难。 我设法做这些事情,但我仍然不明白AVFoundation是如何工作的。 这个文档对于初学者来说是模糊的,我还没有find一个我特别想要的教程,并且把多个教程(用Obj C编写)使这个变得不可能。 我的问题如下: video不能保存为正方形。 (提到该应用程序不支持横向方向) video没有audio。 (我认为我应该添加一些video以外的audioinput) 如何将水印添加到video? 我有一个错误:我创build了一个视图(messageView;见代码)与文本和图像,让用户知道video已保存到相机胶卷。 但是如果我第二次开始录制,video将在录制video时出现,而不是在录制之后出现。 我怀疑这与每个video的命名是相同的。 所以我做了准备: override func viewDidLoad() { super.viewDidLoad() // Preset For High Quality captureSession.sessionPreset = AVCaptureSessionPresetHigh // Get available devices capable of recording video let devices = AVCaptureDevice.devicesWithMediaType(AVMediaTypeVideo) as! [AVCaptureDevice] // Get back camera for device in devices […]

如何在没有用户交互的情况下从iOS相机捕捉图像?

我需要从前置摄像头捕捉静止图像并将其存储在Documents目录中。 我在其他post上发现了一些代码,但是想分享一下,以防其他人也有类似的需求。

iOS AVFoundation – 将video转换为60 fps的图像

我试图将整个video转换为60fps的速度,这意味着每秒钟的video产生60个图像的序列图像… 为此,我正在使用AVAssetImageGenerator和generateCGImagesAsynchronouslyForTimes方法… 事情进展得不错,除了我有严重的性能问题regarging批处理执行时间(大约5分钟的13秒video)… 此外,超过以下大小CGSizeMake(512,324),我遇到崩溃… 有没有人有这种处理经验,知道如何减less这个时间的执行,以及能够以更高的分辨率提取图像? 以下是我正在testing的代码… NSURL *movieURL = [NSURL fileURLWithPath:getCaptureMoviePath()]; AVURLAsset *asset=[[AVURLAsset alloc] initWithURL:movieURL options:nil]; AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc] initWithAsset:asset]; generator.appliesPreferredTrackTransform=TRUE; generator.requestedTimeToleranceAfter=kCMTimeZero; generator.requestedTimeToleranceBefore=kCMTimeZero; NSMutableArray *thumbTimes=[NSMutableArray arrayWithCapacity:asset.duration.value]; for(int t=0;t < asset.duration.value;t=t+2) { CMTime thumbTime = CMTimeMake(t, asset.duration.timescale); NSLog(@"Time Scale : %d ", asset.duration.timescale); NSValue *v=[NSValue valueWithCMTime:thumbTime]; [thumbTimes addObject:v]; } NSLog(@"thumbTimes array contains %d objects […]

AVAudioPlayer不能在Swift中播放audio

我有这个代码在一个非常简单的单视图Swift应用程序在我的ViewController : var audioPlayer = AVAudioPlayer() @IBAction func playMyFile(sender: AnyObject) { let fileString = NSBundle.mainBundle().pathForResource("audioFile", ofType: "m4a") let url = NSURL(fileURLWithPath: fileString) var error : NSError? audioPlayer = AVAudioPlayer(contentsOfURL: url, error: &error) audioPlayer.delegate = self audioPlayer.prepareToPlay() if (audioPlayer.isEqual(nil)) { println("There was an error: (er)") } else { audioPlayer.play() NSLog("working") } 我添加了import AVFoundation和audioPlayer是一个全局variables。 当我执行代码时,它会打印“正在工作”,所以无错误地播放声音。 设备没有保持沉默。