zoukankan      html  css  js  c++  java
  • (腾讯视频)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);

            }

    }

    }

  • 相关阅读:
    python斐波那契数列
    python装饰器
    Python文件操作
    python 第三方库的安装方法
    Ajax 基本使用学习记录
    微分方程概述
    Typora中的数学公式
    Ubuntu20.04 安装 mysql8.0 之后 root 账户无法登录
    Ubuntu20.04换源之后依旧慢?如何更有效的换源
    Ubuntu18.04更新python版本
  • 原文地址:https://www.cnblogs.com/tangyuanby2/p/6837532.html
Copyright © 2011-2022 走看看