标签: avfoundation

如何从CMSampleBufferRef获取字节,通过网络发送

使用AVFoundation框架工作捕获视频.借助Apple文档http://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/03_MediaCapture.html%23//apple_ref/doc/ UID/TP40010188-CH5-SW2

现在我做了以下事情

1.Created videoCaptureDevice
2.Created AVCaptureDeviceInput并设置videoCaptureDevice
3.Created AVCaptureVideoDataOutput和实现代表
4.Created AVCaptureSession-设定输入作为AVCaptureDeviceInput并设置输出作为AVCaptureVideoDataOutput

5.在AVCaptureVideoDataOutput委托方法中

-(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
Run Code Online (Sandbox Code Playgroud)

我有CMSamplebuffer并转换成UIImage并测试使用打印UIImageview

[self.imageView performSelectorOnMainThread:@selector(setImage:) withObject:image waitUntilDone:YES];
Run Code Online (Sandbox Code Playgroud)

每件事情都很顺利........

我的问题是,我需要通过UDP套接字发送视频帧.尽管下面的一个是我试过的坏主意,UIImage到NSData和通过UDP Pocket发送.BUt得到了如此延迟的视频处理.由于UIImage NSDate导致了很多问题

所以请给我解决方案我的问题

1)任何方法将CMSampleBUffer或CVImageBuffer转换为NSData ??
2)像音频队列服务和视频队列存储UIImage和UIImage到NSDate和发送???

如果我骑在错误的算法背后请在写方向路径我

提前致谢

video-capture video-processing avfoundation core-video ios

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

UIWebView:当应用程序进入后台时,HTML5音频在iOS 6中暂停

美好的一天,

我的应用是一个音乐播放应用程序.我<audio>用Javascript 控制-Tag.到目前为止没有任何问题,播放,暂停,下一个和上一个按钮正在工作.当我在iOS 5中待机时,音乐会继续播放,但自动下一首歌不起作用.当它不处于待机状态时,它可以工作.在iOS 6中,只需按下按钮,音乐就会淡出.

锁定屏幕上的播放/暂停按钮适用于iOS 5,但不适用于iOS 6.

avfoundation uiwebview ios html5-audio ios6

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

CALayer - 将故障板放置在故事板UIButtons下面?

我的故事板中有一个带有几个UIButton的视图控制器.其中一个激活子图层中显示的AVFoundation相机预览图层:

captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
captureVideoPreviewLayer.frame = self.view.bounds;
[self.view.layer addSublayer:captureVideoPreviewLayer];
Run Code Online (Sandbox Code Playgroud)

这是正常工作,除了预览图层呈现在我的按钮之上,因此即使按钮仍然可点击,用户也无法看到它们.有没有一种简单的方法将子图层放在按钮下面?或者在图层中提升按钮的简单方法?非常感谢!

uibutton avfoundation calayer ios avcapturesession

27
推荐指数
1
解决办法
9890
查看次数

是否可以使用AVPlayer缓存HLS段?

根本问题

在iOS中搜索时,我们的视频会缓冲很多.它比我们的网络播放器缓冲得更多,它可以在临时存储中保存已经观看的片段的副本.

期望的解决方案

在设备的磁盘上本地缓存视频片段.我们很好地缓存单一质量并且总是重播它.

拦截器

我们找不到在AVFoundation/AVPlayer中执行缓存的方法.

我们尝试过什么

使用AVPlayer拦截网络请求的两种方法.

  1. 符合AVAssetResourceLoaderDelegate并手动处理媒体加载

不适用于HLS.您可以通过实现AVAssetResourceLoaderDelegate来加载m3u8文件,它允许您通过身份验证或解密响应,但无法加载.ts文件.这是我们尝试的代码:https: //gist.github.com/nathanhillyer/84e46152d7c4c88183b6

  1. 实现NSURLProtocol以捕获.ts文件请求.

AVURLAsset实际上避免被截获.不知何故,网络请求只是没有被捕获.(不知道为什么)

avfoundation video-streaming http-live-streaming ios avplayer

27
推荐指数
1
解决办法
8210
查看次数

ASSETWriterInput用于在Iphone问题上从UIImages制作视频

我尝试了以下两种方法来附加UIImages pixelbuffer ASSETWriterInput.除了视频文件中没有数据外,一切看起来都不错.怎么了?

1适配器类

AVAssetWriterInputPixelBufferAdaptor * avAdaptor = [AVAssetWriterInputPixelBufferAdaptor assetWriterInputPixelBufferAdaptorWithAssetWriterInput:writerInput sourcePixelBufferAttributes:NULL];

[avAdaptor appendPixelBufferixelBuffer withPresentationTime:CMTimeMake(1, 10)];
Run Code Online (Sandbox Code Playgroud)

2制作

// Create sample buffer.
CMSampleBufferRef sampleBuffer = NULL;
result = CMSampleBufferCreateForImageBuffer(kCFAllocatorDef ault, pixelBuffer, true, NULL, NULL, videoInfo, &timing, &sampleBuffer);

// Ship out the frame.
NSParameterAssert(CMSampleBufferDataIsReady(sample Buffer));
NSParameterAssert([writerInput isReadyForMoreMediaData]);
BOOL success = [writerInput appendSampleBuffer:sampleBuffer];
Run Code Online (Sandbox Code Playgroud)

iphone video image avfoundation

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

获取缩略图的视频快照

我正在使用Apple提供的AVCam代码从iPhone相机录制视频.

录制视频后,会将其保存到照片库中.

然后加载一个新视图,这里我需要有一个视频的图像缩略图.

我有一条视频路径:

file://localhost/private/var/mobile/Applications/ED45DEFC-ABF9-4A5E-9102-21680CC1448E/tmp/output.mov
Run Code Online (Sandbox Code Playgroud)

我似乎无法想象如何将视频的第一帧用作缩略图.

任何帮助将非常感谢,谢谢你的时间.


编辑

我最终使用了这个,我不确定为什么它将图像侧面返回?

- (UIImage*)loadImage {

    AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:vidURL options:nil];
    AVAssetImageGenerator *generate = [[AVAssetImageGenerator alloc] initWithAsset:asset];
    NSError *err = NULL;
    CMTime time = CMTimeMake(1, 60);
    CGImageRef imgRef = [generate copyCGImageAtTime:time actualTime:NULL error:&err];
    NSLog(@"err==%@, imageRef==%@", err, imgRef);

    return [[UIImage alloc] initWithCGImage:imgRef];

}
Run Code Online (Sandbox Code Playgroud)

video xcode avfoundation ios

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

iOS AVFoundation导出会话缺少音频

我正在使用iOS AVFoundation框架,我能够成功合并视频轨道,图像叠加和文本叠加.但是,我的输出文件不会保留原始源视频中的音频.

如何确保我的某个视频的音频源与我创建的新视频保持一致?

编辑

*使用此代码可以很好地说明如何创建视频(使用原始音频).在使用AVFoundation处理视频时,我需要单独包含音频轨道,这一点并不明显.希望这有助于其他人.

    AVAssetTrack *videoTrack = nil;
    AVAssetTrack *audioTrack = nil;
    CMTime insertionPoint = kCMTimeZero;

    if([[url tracksWithMediaType:AVMediaTypeVideo] count] != 0) {
        videoTrack = [url tracksWithMediaType:AVMediaTypeVideo][0];
    }

    if([[url tracksWithMediaType:AVMediaTypeAudio] count] != 0) {
        audioTrack = [url tracksWithMediaType:AVMediaTypeAudio][0];
    }

    // Insert the video and audio tracks from AVAsset
    if (videoTrack != nil) {
        AVMutableCompositionTrack *compositionVideoTrack = [videoComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
        [compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, [url duration]) ofTrack:videoTrack atTime:insertionPoint error:&error];
    }
    if (audioTrack != nil) {
        AVMutableCompositionTrack *compositionAudioTrack = [videoComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];
        [compositionAudioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, …
Run Code Online (Sandbox Code Playgroud)

audio video export avfoundation ios

26
推荐指数
1
解决办法
3473
查看次数

AVAudioPlayer停止声音并从头开始播放

我使用AVAudioPlayer播放10秒的wav文件,它工作正常.现在我在第4秒停止wav然后从第1秒再次播放.

这是我试过的代码:

NSString *ahhhPath = [[NSBundle mainBundle] pathForResource:@"Ahhh" ofType:@"wav"];
AVAudioPlayer *ahhhhhSound =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:ahhhPath] error:NULL];

[ahhhhhSound stop];
[ahhhhhSound play];
Run Code Online (Sandbox Code Playgroud)

我得到的是,wav在第4秒停止但是当我再次运行[XXX play]时,wav继续播放第5秒而不是从头开始播放.

我怎么能这样做?任何帮助将不胜感激.

cocoa-touch avfoundation avaudioplayer

25
推荐指数
2
解决办法
9304
查看次数

IOS上的WaveForm

我正在寻找如何绘制声音幅度.

我找到了http://supermegaultragroovy.com/2009/10/06/drawing-waveforms/但我遇到了一些问题.如何获取表示音频的浮点值列表?

cocoa-touch objective-c avfoundation ios

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

ios AVFoundation点击即可关注

我正在尝试创建一个相机应用程序,它或多或少会像默认的相机应用程序.目前对我不起作用的东西是重点关注.我希望相机能够对焦并在触摸点上做任何事情,就像真正的相机应用程序一样.

这是我的viewDidLoad

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Session
    _session = [[AVCaptureSession alloc] init];
    _session.sessionPreset = AVCaptureSessionPresetPhoto;

    // Input
    _videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    _videoInput = [AVCaptureDeviceInput deviceInputWithDevice:_videoDevice error:nil];

    // Output
    _frameOutput = [[AVCaptureVideoDataOutput alloc] init];
    _frameOutput.videoSettings = [NSDictionary dictionaryWithObject:AVVideoCodecJPEG forKey:AVVideoCodecKey];

    [_frameOutput setSampleBufferDelegate:self queue:dispatch_get_main_queue()];
    [_session addInput:_videoInput];
    [_session addOutput:_frameOutput];
    [_session startRunning];
};
Run Code Online (Sandbox Code Playgroud)

这里的方法应该让我的相机专注于点击.

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    [touches enumerateObjectsUsingBlock:^(id obj, BOOL *stop) {
        UITouch *touch = obj;
        CGPoint touchPoint = [touch locationInView:touch.view];
        focusLayer.frame = CGRectMake((touchPoint.x-25), (touchPoint.y-25), 50, 50);

        if ([_videoDevice isFocusPointOfInterestSupported]) …
Run Code Online (Sandbox Code Playgroud)

camera avfoundation ios

25
推荐指数
2
解决办法
2万
查看次数