rtsp://形式与AVPlayer直播视频

问题描述 投票:4回答:3

我要玩上直播,与iPhoneDevice AVPlayer。此外,我想从此流为下次使用得到CVPixelBufferRef

我用Apple guide创建播放器。目前正与本地存储videoFiles这个播放器工作得很好,还当我尝试玩这个AppleSampleStremURL - http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8 - 它的工作正弦了。

问题出现时,我想用RTSP播放流://像这样的:rtsp://192.192.168.1:8227/TTLS/Streaming/channels/2?videoCodecType=H.264

AN码 - 几乎全部完成使用苹果公司提供的GUID,但无论如何:

准备资产播放

- (void)initialSetupWithURL:(NSURL *)url
{
    NSDictionary *assetOptions = @{ AVURLAssetPreferPreciseDurationAndTimingKey : @YES,
                                    AVURLAssetReferenceRestrictionsKey : @(AVAssetReferenceRestrictionForbidNone)};
    self.urlAsset = [AVURLAsset URLAssetWithURL:url options:assetOptions];
}

准备播放器

- (void)prepareToPlay
{
    NSArray *keys = @[@"tracks"];
    __weak SPHVideoPlayer *weakSelf = self;
    [weakSelf.urlAsset loadValuesAsynchronouslyForKeys:keys completionHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            [weakSelf startLoading];
        });
    }];
}

- (void)startLoading
{
    NSError *error;
    AVKeyValueStatus status = [self.urlAsset statusOfValueForKey:@"tracks" error:&error];
    if (status == AVKeyValueStatusLoaded) {
        self.assetDuration = CMTimeGetSeconds(self.urlAsset.duration);
        NSDictionary* videoOutputOptions = @{ (id)kCVPixelBufferPixelFormatTypeKey : @(kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange)};
        self.videoOutput = [[AVPlayerItemVideoOutput alloc] initWithPixelBufferAttributes:videoOutputOptions];
        self.playerItem = [AVPlayerItem playerItemWithAsset: self.urlAsset];

        [self.playerItem addObserver:self
                          forKeyPath:@"status"
                             options:NSKeyValueObservingOptionInitial
                             context:&ItemStatusContext];
        [self.playerItem addObserver:self
                          forKeyPath:@"loadedTimeRanges"
                             options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld
                             context:&ItemStatusContext];
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(playerItemDidReachEnd:)
                                                     name:AVPlayerItemDidPlayToEndTimeNotification
                                                   object:self.playerItem];
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(didFailedToPlayToEnd)
                                                     name:AVPlayerItemFailedToPlayToEndTimeNotification
                                                   object:nil];

        [self.playerItem addOutput:self.videoOutput];

        self.assetPlayer = [AVPlayer playerWithPlayerItem:self.playerItem];

        [self addPeriodicalObserver];
        NSLog(@"Player created");
    } else {
        NSLog(@"The asset's tracks were not loaded:\n%@", error.localizedDescription);
    }
}

问题出现在这里 - AVKeyValueStatus status = [self.urlAsset statusOfValueForKey:@"tracks" error:&error]; - 这符合RTSP:// URL回报AVKeyValueStatusFailed

与错误:

Printing description of error:
Error Domain=AVFoundationErrorDomain Code=-11800 
"The operation could not be completed" 
UserInfo=0x7fd1ea5a8a10 {NSLocalizedFailureReason=An unknown error occurred (-12936), 
NSLocalizedDescription=The operation could not be completed,
NSURL=rtsp://192.168.1.168:8556/PSIA/Streaming/channels/2?videoCodecType=H.264,
NSUnderlyingError=0x7fd1ea53f830 "The operation couldn’t be completed.
(OSStatus error -12936.)"}

我也找了几个问题:

  1. FirstOne - 尝试使用从苹果该流的示例应用程序 - StitchedStreamPlayer - 但得到几个不同的错误,我想那里踢球流
  2. SecondOne - 尝试使用这两种建议 - fileURLWithPath返回不正确的网址,如:rtsp://192.168.1.168:8556/PSIA/Streaming/channels/2?videoCodecType=H.264 --file:/// - 所以这是我猜不正确
  3. 据AppleDev尝试与差异的方法创建AvPlayer:像[AVPlayer playerWithPlayerItem:playerItem]和像[AVPlayer playerWithURL:url] - 什么都没有改变。也可以尝试设置不同的设置对AVAsset - 在initialSetupWithURL(见上面的方法实现)。

所以,问题是AVPlayer支持播放rtsp://形式流?如果是的话,有人可以提供正确用法的样本?纳德我在做什么错误的代码?如果AvPlayer不支持rtsp://形式也许存在一定的替代解决方案?

iphone ios8 avfoundation avplayer rtsp
3个回答
© www.soinside.com 2019 - 2024. All rights reserved.