小编iHo*_*rse的帖子

如何将CVImageBufferRef转换为UIImage

我试图从相机捕获视频.我已经得到了captureOutput:didOutputSampleBuffer:回调触发器,它给了我一个样本缓冲区,然后我转换为CVImageBufferRef.我然后尝试将该图像转换为UIImage我可以在我的应用程序中查看的图像.

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
{
    CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); 
    /*Lock the image buffer*/
    CVPixelBufferLockBaseAddress(imageBuffer,0); 
    /*Get information about the image*/
    uint8_t *baseAddress = (uint8_t *)CVPixelBufferGetBaseAddress(imageBuffer); 
    size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer); 
    size_t width = CVPixelBufferGetWidth(imageBuffer); 
    size_t height = CVPixelBufferGetHeight(imageBuffer); 

    /*We unlock the  image buffer*/
    CVPixelBufferUnlockBaseAddress(imageBuffer,0);

    /*Create a CGImageRef from the CVImageBufferRef*/
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); 
    CGContextRef newContext = CGBitmapContextCreate(baseAddress, width, height, 8, bytesPerRow, colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst); 
    CGImageRef newImage = CGBitmapContextCreateImage(newContext); 

    /*We release some …
Run Code Online (Sandbox Code Playgroud)

iphone uiimage

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

从iPhone流式传输视频

我可以从iPhone的相机中获得单独的帧.我需要的是一种用声音打包它们以便流式传输到服务器的方法.我拥有它们后发送文件并不是什么大问题.它生成的流媒体文件我遇到了问题.我一直试图让FFMpeg没有太多运气.

任何人都有任何关于如何解决这个问题的想法?我想要一个已知的工作API或有关让FFMpeg在iPhone应用程序中正确编译的说明.

iphone video-encoding video-streaming

18
推荐指数
1
解决办法
1万
查看次数

捕获摄像头和音频输入时出错

使用iOS4中的一些漂亮的新API,我试图从iPhone的摄像头和麦克风捕获输入并将其保存到文件中.下面是我正在使用的代码.

AVCaptureSession* captureSession = [[AVCaptureSession alloc] init];
AVCaptureDevice *audioCaptureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
AVCaptureDeviceInput *audioInput = [AVCaptureDeviceInput deviceInputWithDevice:audioCaptureDevice error:&error];
AVCaptureDeviceInput* videoInput = [[AVCaptureDeviceInput alloc] initWithDevice:captDevice error:&error];
AVCaptureMovieFileOutput * videoOutput = [[AVCaptureMovieFileOutput alloc] init];

if (videoInput && videoOutput && audioInput) 
{
    [captureSession addInput:audioInput];
    [captureSession addInput:videoInput];
    [captureSession addOutput:videoOutput];
    if([captDevice lockForConfiguration:&error])
    {
        if ([captDevice hasTorch]) 
            captDevice.torchMode = AVCaptureTorchModeOn;

        [captDevice unlockForConfiguration];
    }
    else 
    {
        NSLog(@"Could not lock device for config error: %@", error);
    }

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0]; …
Run Code Online (Sandbox Code Playgroud)

iphone video video-capture video-streaming ios4

5
推荐指数
1
解决办法
8971
查看次数