• (腾讯视频)iOS开发之视频根据url获取第一帧图片,获取任一帧图片


    #import <AVFoundation/AVFoundation.h>

    + (UIImage*) thumbnailImageForVideo:(NSURL *)videoURL atTime:(NSTimeInterval)time {  AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:videoURL options:nil];  

        NSParameterAssert(asset);  

      AVAssetImageGenerator *assetImageGenerator =[[AVAssetImageGenerator alloc] initWithAsset:asset];  

         assetImageGenerator.appliesPreferredTrackTransform = YES;  

       assetImageGenerator.apertureMode = AVAssetImageGeneratorApertureModeEncodedPixels;  

          CGImageRef thumbnailImageRef = NULL;  

      CFTimeInterval thumbnailImageTime = time;  

      NSError *thumbnailImageGenerationError = nil;  

         thumbnailImageRef = [assetImageGenerator copyCGImageAtTime:CMTimeMake(thumbnailImageTime, 60)actualTime:NULL error:&thumbnailImageGenerationError];  

      if(!thumbnailImageRef)  

          NSLog(@"thumbnailImageGenerationError %@",thumbnailImageGenerationError);  

          UIImage*thumbnailImage = thumbnailImageRef ? [[UIImage alloc]initWithCGImage: thumbnailImageRef] : nil;  

        return thumbnailImage;  

    -(void)setADvideoUrl:(NSString *)urlstr

    {

        urlstr = urlstr;

        NSLog(@"%@",urlstr);

        //http://v.qq.com/iframe/player.html?vid=k0511h0fvay&tiny=1&auto=0  大图

        NSURL * url = [NSURLURLWithString:urlstr];

        NSString * hostStr = [url host];

        NSString * tXURL = @"v.qq.com";

        //https://puui.qpic.cn/qqvideo_ori/0/k0511h0fvay_228_128/0  小图

        NSString * videoPrewURL = nil;

        if([tXURL isEqualToString:hostStr]){ //如果是腾讯视频

            NSDictionary * dic = [urlstr getURLParameters];

            NSString * videoIDStr = [dic objectForKey:@"vid"];

            if(videoIDStr){

                videoPrewURL = [NSStringstringWithFormat:@"https://puui.qpic.cn/qqvideo_ori/0/%@_228_128/0",videoIDStr];

                NSLog(@"videoIDStr is %@",videoPrewURL);

            }

    }

    }

  • 相关阅读:
    Release和Debug的区别[转]
    SVM运用到多分类[引]
    HMM
    [转] 数据挖掘 机器学习 模式识别的关系
    [转]mysql 数据导入
    java 获取当前时间戳
    二叉树遍历建树[zhuan]
    关于c指针[转]
    词法分析
    组合数据类型练习,综合练习
  • 原文地址:https://www.cnblogs.com/tangyuanby2/p/6837532.html
Copyright © 2020-2023  润新知