首页 文章

m3u8文件AVAssetImageGenerator错误

提问于
浏览
15

我正在使用AVPlayer播放.m3u8文件 . 使用AVAssetImageGenerator使用以下代码从中提取图像:

AVURLAsset *asset1 = [[AVURLAsset alloc] initWithURL:mp.contentURL options:nil];
AVAssetImageGenerator *generate1 = [[AVAssetImageGenerator alloc] initWithAsset:asset1];
generate1.appliesPreferredTrackTransform = YES;
NSError *err = NULL;
CMTime time = CMTimeMake(1, 2);
CGImageRef oneRef = [generate1 copyCGImageAtTime:time actualTime:NULL error:&err];
img = [[UIImage alloc] initWithCGImage:oneRef];

它总是给我错误:

错误域= AVFoundationErrorDomain代码= -11800“操作无法完成”UserInfo = 0x7fb4e30cbfa0 {NSUnderlyingError = 0x7fb4e0e28530“操作无法完成 . (OSStatus error -12782 . )”,NSLocalizedFailureReason =发生未知错误( - 12782),NSLocalizedDescription =操作无法完成}

它适用于mp4,mov和所有主要视频扩展URL但不适用于m3u8 . 任何的想法??

3 回答

  • 8

    你的问题只是预料之中的 . .m3u8文件不是实际的资产文件,而是更类似于播放列表 . 它们用于HTTP实时流媒体,并根据可用带宽为“分段”提供位置 .

    这是一个.m3u8文件的示例(Apple's sample .m3u8 file

    #EXTM3U
    #EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=200000
    gear1/prog_index.m3u8
    #EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=311111
    gear2/prog_index.m3u8
    #EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=484444
    gear3/prog_index.m3u8
    #EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=737777
    gear4/prog_index.m3u8
    

    遗憾的是,您无法创建AVAsset或AVURLAsset来表示HTTP Live流中的媒体 . 参考:Apple's reference example of Asset Loading/playing

  • 0

    您将无法使用AVAssetImageGenerator获取实时流的静止图像 . 相反,你可以使用

    AVPlayerItemVideoOutput

    使用AVPlayerItemVideoOutput,您可以使用以下方法获取适合在给定.m3u8流的指定时间显示的图像: - (CVPixelBufferRef)copyPixelBufferForItemTime:(CMTime)itemTime itemTimeForDisplay:(CMTime *)outItemTimeForDisplay 然后,您可以将返回的CVPixelBufferRef转换为图像(或其他)以供显示 .

  • 7

    我们的发现是,如果您播放具有"I-Frame only playlist"的HLS流,例如流“https://tungsten.aaplimg.com/VOD/bipbop_adv_example_v2/master.m3u8”(仅具有I帧播放列表),AVAssetImageGenerator可以逐个生成所请求的图像 .

    但请注意“它在iOS8.X和iOS9.X上只能正常”,但在iOS10.X上失败了 .

    我已向Apple Bug Reporter提交了错误报告 .

相关问题