iphone - 在 iphone 中使用 ip 摄像头进行视频流式传输

标签 iphone objective-c ffmpeg

我正在为连接网络摄像机开发应用程序并获取流。我不知道如何将流转换为视频。我已经分析过了,然后我尝试了 FFMPEG 库。但是我没有使用 FFMPEG 获得正确的 ios 网址。你能建议实现指南吗?

现在我正在集成 ffmpeg,当我集成时打开 avformat_find_stream_info() 函数时出现错误。我使用增加或减少pFormatCtx->max_analyze_duration 的值。但对此没有解决方案。

[mjpeg @ 0x8b85000] max_analyze_duration 1000 达到 40000
[mjpeg @ 0x8b85000] 从比特率估计持续时间,这可能不准确

请帮助如何解决这个问题。

最佳答案

查看 Apple 的“AVCam”示例。
它正是这样做的,并且有很多内联注释。

https://developer.apple.com/library/ios/#samplecode/AVCam/Introduction/Intro.html

这是一个小代码片段,它将为您指明正确的方向:

首先创建一个 AVCaptureSession...

            // Init the device inputs
AVCaptureDeviceInput *newVideoInput = [[AVCaptureDeviceInput alloc] initWithDevice:[self backFacingCamera] error:nil];
AVCaptureDeviceInput *newAudioInput = [[AVCaptureDeviceInput alloc] initWithDevice:[self audioDevice] error:nil];


// Setup the still image file output
AVCaptureStillImageOutput *newStillImageOutput = [[AVCaptureStillImageOutput alloc] init];
NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys:
                                AVVideoCodecJPEG, AVVideoCodecKey,
                                nil];
[newStillImageOutput setOutputSettings:outputSettings];
[outputSettings release];


// Create session (use default AVCaptureSessionPresetHigh)
AVCaptureSession *newCaptureSession = [[AVCaptureSession alloc] init];  

创建视频文件输出
AVCaptureMovieFileOutput *aMovieFileOutput = [[AVCaptureMovieFileOutput alloc] init];
if ([aSession canAddOutput:aMovieFileOutput])
[aSession addOutput:aMovieFileOutput];

保存文件:
-(void)recorder:(AVCamRecorder *)recorder recordingDidFinishToOutputFileURL:(NSURL *)outputFileURL error:(NSError *)error
{
    if ([[self recorder] recordsAudio] && ![[self recorder] recordsVideo]) {
        // If the file was created on a device that doesn't support video recording, it can't be saved to the assets 
        // library. Instead, save it in the app's Documents directory, whence it can be copied from the device via
        // iTunes file sharing.
        [self copyFileToDocuments:outputFileURL];

        if ([[UIDevice currentDevice] isMultitaskingSupported]) {
            [[UIApplication sharedApplication] endBackgroundTask:[self backgroundRecordingID]];
        }       

        if ([[self delegate] respondsToSelector:@selector(captureManagerRecordingFinished:)]) {
            [[self delegate] captureManagerRecordingFinished:self];
        }
    }
    else {  
        ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
        [library writeVideoAtPathToSavedPhotosAlbum:outputFileURL
                                    completionBlock:^(NSURL *assetURL, NSError *error) {
                                        if (error) {
                                            if ([[self delegate] respondsToSelector:@selector(captureManager:didFailWithError:)]) {
                                                [[self delegate] captureManager:self didFailWithError:error];
                                            }                                           
                                        }

                                        if ([[UIDevice currentDevice] isMultitaskingSupported]) {
                                            [[UIApplication sharedApplication] endBackgroundTask:[self backgroundRecordingID]];
                                        }

                                        if ([[self delegate] respondsToSelector:@selector(captureManagerRecordingFinished:)]) {
                                            [[self delegate] captureManagerRecordingFinished:self];
                                        }
                                    }];
        [library release];
    }
}

关于iphone - 在 iphone 中使用 ip 摄像头进行视频流式传输,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17500664/

相关文章:

ios - 将 UITextField MM/YY 格式化为过期时间

iphone - 如何确定 iOS 上的设置何时更改

ios - AFNetworking 未实现

FFmpeg:如何在音频文件中间多次降低音量几秒钟?

nginx - 是否可以同时提供 hls 和 dash mpeg

iphone - 在未(尚未)发布的游戏中测试成就

iphone - 如何使用 Bonjour 跨子网宣传服务?

iphone - 流式传输 JPEG,检测 JPEG 的结尾

iphone - 事件中无法播放声音(wav)

node.js - 将 HLS .m3u8 文件及其段文件 .ts 存储在 cassandra 数据库中是否很好?