【问题标题】:Create an application that creates a video from iphone screen and add audio from headphones / audio input创建一个从 iphone 屏幕创建视频并从耳机/音频输入添加音频的应用程序
【发布时间】:2012-01-12 03:42:45
【问题描述】:

我正在尝试从 ipad 屏幕as done in this application (ShowME) 创建一个教程视频,使用 AVAssetWriter 我能够捕获屏幕的视频。

我尝试使用 AVCaptureDevice,但它不起作用。我不知道出了什么问题。 我从这个link - A very nice turorial. 学会了从 iPhone 屏幕捕捉视频 但它不会捕获任何音频以及屏幕视频。所以我试了一下:

 -(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 = AVCaptureSessionPresetLow;     

// Setup the queue
dispatch_queue_t queue = dispatch_queue_create("MyQueue", NULL);
//    [_videoOutput setSampleBufferDelegate:self queue:queue];
[_audioOutput setSampleBufferDelegate:self queue:queue];
dispatch_release(queue);
}

我添加了委托方法

- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
       fromConnection:(AVCaptureConnection *)connection

这永远不会被调用。希望任何人都可以帮助我解决这个问题。 我从未将 AVFoundation 用于视频和音频目的,所以可能是一个新手问题。 我阅读了与此相关的其他帖子,发现它们正在将音频与视频合并。我认为我们可以通过这种方式。如果这是不可能的,请通知我。

提前致谢:)

【问题讨论】:

    标签: iphone ios ios4 avfoundation


    【解决方案1】:

    我最终将音频录制为不同的文件,然后将它们合并以创建包含音频和视频的视频。我使用 AVMutableComposition 创建了最终视频。如果有人知道如何在使用 AVAssetWriter 创建视频时使用资产录制它,请帮助我。我可能会更改我的代码:)

    【讨论】:

    • 我认为你的意思是 AVMutableComposition
    • 嘿,我们正在尝试使用单独的视频和音频文件的相同方法,但没有运气,当我开始录制音频时,相机视频卡住了。知道为什么会这样吗?
    • @PGU - 你现在可能已经解决了,但我猜这是一个线程问题。在主线程上安排了太多的执行。如果您需要在主线程上实时运行,请异步执行文件 IO。
    • @DevineDesert -首先感谢您的回答,我一直在开发相同类型的应用程序(屏幕录制功能)我的视频无法保存在真实设备上,我可以获得相同的输出样本我在默认路径 /var/mobile/Applications/8E4FFF35-267D-4B46-9A4B-D7D1BC361F72/Documents/foo.mp4 中使用模拟器的文档目录
    • @MacGeek 对你有帮助吗?
    猜你喜欢
    • 2018-05-12
    • 1970-01-01
    • 1970-01-01
    • 2012-12-13
    • 2012-01-27
    • 1970-01-01
    • 2013-07-23
    • 2023-04-06
    • 1970-01-01
    相关资源
    最近更新 更多