- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
实现本题编码视频(带音频)的解决方案后,Video Encoding using AVAssetWriter - CRASHES ,我发现代码在 iPhone 模拟器中运行正常。不幸的是,某些视频在实际的 iPhone 5(和其他设备)上运行时无法对其音频进行编码。
例如,从 WWDC 2011 示例代码 RosyWriter (https://developer.apple.com/library/IOS/samplecode/RosyWriter/Introduction/Intro.html) 生成的视频没有完全编码,因为函数 -[AVAssetReaderOutput copyNextSampleBuffer]
永远不会返回。
视频缓冲区正确进入,但一旦它尝试复制第一个音频 CMSampleBufferRef,调用就会挂起。当我在来自其他来源的视频(例如在 native iOS 相机应用程序中录制的视频)上尝试此操作时,音频导入正确。
此线程,https://groups.google.com/forum/#!topic/coreaudio-api/F4cqCu99nUI ,记下与 AudioQueues 一起使用时挂起的 copyNextSampleBuffer
函数,并建议将操作保持在单个线程上。我试过将所有内容都放在主线程的单独线程中,但没有成功。
有没有其他人遇到过这种情况并有可能的解决方案?
编辑:RosyWriter 生成的视频的轨道似乎与原生相机应用中的视频相反,即音频流为流 0,视频流为流 1。
Stream #0:0(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 60 kb/s
Metadata:
creation_time : 2013-10-28 16:13:05
handler_name : Core Media Data Handler
Stream #0:1(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1920x1080, 8716 kb/s, 28.99 fps, 29.97 tbr, 600 tbn, 1200 tbc
Metadata:
rotate : 90
creation_time : 2013-10-28 16:13:05
handler_name : Core Media Data Handler
不确定这是否会对 AVAssetReader 产生影响。
最佳答案
我在 iOS 9.3.2 上仍然遇到这个问题,解决它的方法是确保 AVAssetReaderAudioMixOutput*
最初设置了选项而不是 nil
当调用 -[AVAssetReaderAudioMixOutput assetReaderAudioMixOutputWithAudioTracks]
时。
例子:
NSDictionary *outputSettings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:kAudioFormatLinearPCM], AVFormatIDKey,
[NSNumber numberWithFloat:44100.0], AVSampleRateKey,
[NSNumber numberWithInt:16], AVLinearPCMBitDepthKey,
[NSNumber numberWithBool:NO], AVLinearPCMIsNonInterleaved,
[NSNumber numberWithBool:NO], AVLinearPCMIsFloatKey,
[NSNumber numberWithBool:NO], AVLinearPCMIsBigEndianKey,
nil];
// create an AVAssetReaderOutput for the audio tracks
NSArray* audioTracks = [asset tracksWithMediaType:AVMediaTypeAudio];
AVAssetReaderAudioMixOutput* _audioReaderOutput = [AVAssetReaderAudioMixOutput assetReaderAudioMixOutputWithAudioTracks:audioTracks audioSettings:outputSettings];
这可以防止以后对 -[AVAssetReaderOutput copyNextSampleBuffer]
的调用挂起。
关于ios - AVAssetReaderOutput copyNextSampleBuffer 在设备上编码带音频的视频时挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20272695/
我正在使用 AVAssetReaderOutput(更具体地说是 AVAssetReaderTrackOutput)逐帧处理视频。我使用 copyNextSampleBuffer() 方法获取视频的连
实现本题编码视频(带音频)的解决方案后,Video Encoding using AVAssetWriter - CRASHES ,我发现代码在 iPhone 模拟器中运行正常。不幸的是,某些视频在实
我正在使用 AVAssetReaderOutput 从 AVAsset 中读取样本,对它们进行一些处理,然后使用 RemoteIO AU 播放结果。 问题是在调用 AudioOutputUnitSto
我有这段代码用于从 AVAssetReaderOutput 中读取数据,该方法在 iOS 4.0 中运行良好,但是在 5.0 中,它在接近尾声时因访问错误而崩溃,不知道为什么,任何人都有有什么意见吗?
我是一名优秀的程序员,十分优秀!