相关疑难解决方法(0)

AVURLAsset拒绝加载视频

我正在尝试将视频文件加载到我的iPad应用程序中AVURLAsset,使用异步加载的东西等待它准备好.问题是,当我运行它时,我得到一个完全通用的"失败"错误消息,我不知道该怎么做.如果我把它交给一个视频MPMoviePlayerController,但是AVURLAsset似乎拒绝与它有任何关系.

码:

asset = [[AVURLAsset alloc] initWithURL:[NSURL URLWithString:[docPath stringByAppendingPathComponent:@"video.mov"]] options:nil];
[asset loadValuesAsynchronouslyForKeys:[NSArray arrayWithObject:@"tracks"] completionHandler:^{
    dispatch_async(dispatch_get_main_queue(), ^{
        [self composeIfReady];
    });
}];
Run Code Online (Sandbox Code Playgroud)

...

- (void)composeIfReady
{
    NSError *error = nil;
    if([asset statusOfValueForKey:@"tracks" error:&error] == AVKeyValueStatusFailed)
        NSLog(@"error loading: %@", [error description]);
    if(error == nil)
        NSLog(@"okay awesome");
}
Run Code Online (Sandbox Code Playgroud)

输出:

error loading: Error Domain=AVFoundationErrorDomain Code=-11800 "The operation couldn’t be completed. (AVFoundationErrorDomain error -11800.)" UserInfo=0x1696f0 {NSUnderlyingError=0x169a40 "The operation couldn’t be completed. (OSStatus error -12936.)"}
Run Code Online (Sandbox Code Playgroud)

顺便说一下,-11800是"未知错误"的错误代码.有点死路一条.有任何想法吗?在我尝试加载资产之前,我应该设置一些东西吗?

video avfoundation ipad ios4 ios

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

将AVAudioPCMBuffer写入压缩的AVAudioFile中

我们正在开发一个记录并保留麦克风输入的应用程序。使用的AVAudioRecorder是不是一种选择,因为需要实时音频处理。

AVAudioEngine 之所以使用,是因为它提供了对输入音频的低级访问。

let audioEngine  = AVAudioEngine()
let inputNode = audioEngine.inputNode
let inputFormat = inputNode.inputFormat(forBus: 0)
inputNode.installTap(onBus: 0, bufferSize: AVAudioFrameCount(inputFormat.sampleRate * sampleInterval), format: inputFormat) { (buffer: AVAudioPCMBuffer, time: AVAudioTime) -> Void in
    // sound preprocessing
    // writing to audio file
    audioFile.write(buffer.floatChannelData![0])
})
Run Code Online (Sandbox Code Playgroud)

我们的问题是录音量很大。对于5个小时的录制,输出的音频文件为1.2GB .caf格式。

let audioFile = AVAudioFile(forWriting: recordingPath, settings: [:], commonFormat: .pcmFormatFloat32, interleaved: isInterleaved)
Run Code Online (Sandbox Code Playgroud)

是否有压缩音频文件的好方法?

默认采样频率为44100Hz。我们将使用AVAudioMixerNode将输入下采样到20Khz(在我们的情况下,较低的质量是可以接受的),但是输出的大小在大小上是不可接受的。

录音中包含很大部分的背景噪音。

有什么建议么?

avfoundation ios swift avaudiofile

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

标签 统计

avfoundation ×2

ios ×2

avaudiofile ×1

ios4 ×1

ipad ×1

swift ×1

video ×1