Skip to content
shixuemei edited this page Sep 29, 2016 · 12 revisions

探测视频信息与获取视频缩略图功能

功能描述

  • 无需启动播放即可得到文件的音视频信息描述,如文件封装格式、视频编码格式、视频宽高、音频编码格式、采样率、声道数等信息
  • 获取本地缩略图,可设定输出缩略图的宽高以及所需具体时间点的缩略图

版本要求

  • 探测音视频信息: v1.5.3 及以上
  • 获取缩略图: v1.8.2 及以上

功能实现

示例代码

文件格式探测

@property (nonatomic, strong) KSYMediaInfo *ksyMediaInfo

NSURL *url = [NSURL URLWithString:@"http://maichang.kssws.ks-cdn.com/upload20150716161913.mp4"];
KSYMediaInfoProber *prober = [[KSYMediaInfoProber alloc] initWithContentURL: url];
KSYMediaInfo *mediaInfo = prober.ksyMediaInfo;
if(mediaInfo)
{
    NSLog(@"mux type:%d", mediaInfo.type);
    NSLog(@"bitrate:%lld", mediaInfo.bitrate);

    for (KSYVideoInfo  *videoInfo in mediaInfo.videos) {
        NSLog(@"video codec:%d", videoInfo.vcodec);
        NSLog(@"video frame width:%d", videoInfo.frame_width);
        NSLog(@"video frame height:%d", videoInfo.frame_height);
    }
        
    for(KSYAudioInfo  *audioInfo in mediaInfo.audios)
    {
        NSLog(@"audio codec:%d", audioInfo.acodec);
        NSLog(@"audio language:%@", audioInfo.language);
        NSLog(@"audio bitrate:%lld", audioInfo.bitrate);
        NSLog(@"audio channels:%d", audioInfo.channels);
        NSLog(@"audio frame_size:%d", audioInfo.framesize);
        NSLog(@"audio sample_format:%d", audioInfo.sample_format);
        NSLog(@"audio samplerate:%d", audioInfo.samplerate);
    }
}

获取缩略图

备注:v1.8.2.0版本要求缩略图的宽高参数必须大于0

NSURL *url = [NSURL URLWithString:@"http://maichang.kssws.ks-cdn.com/upload20150716161913.mp4"];
KSYMediaInfoProber *prober = [[KSYMediaInfoProber alloc] initWithContentURL: url];
UIImage *thumbnailImage = [prober getVideoThumbnailImageAtTime:0 width:640 height:480];
Clone this wiki locally