我想用AVPlayer在iPhoneDevice上播放liveStream.此外,我想从此流中获取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
一个代码 – 几乎所有使用Apple提供的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:@“track”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.)"}
我也在寻找问题:
> FirstOne – 尝试使用来自Apple – StitchedStreamPlayer的这个流示例应用程序 – 但是对于我想在那里播放的流获得几个不同的错误
> SecondOne – 尝试同时使用这两个建议 – fileURLWithPath返回错误的URL,如:rtsp://192.168.1.168:8556 / PSIA / Streaming / channels / 2?videoCodecType = H.264 –file:/// – 所以我猜不正确
>根据AppleDev尝试使用diff方法创建AvPlayer:如[AVPlayer playerWithPlayerItem:playerItem]和[AVPlayer playerWithURL:url] – 没有任何改变.还尝试为AVAsset设置不同的设置 – 在initialSetupWithURL中(参见上面的方法实现).
那么,问题是AVPlayer支持播放rtsp:// stream?
如果是,有人可以提供正确使用的样本吗? Nad我在代码中做错了什么?
如果AvPlayer不支持rtsp://可能存在一些替代解决方案?
最佳答案 我没有找到如何通过AVURLAsset进行rtsp流的方法,但可以找到良好的起点
here.也许它对someOne有用