七牛上傳視頻之后,獲取對(duì)應(yīng)秒數(shù)的視頻截圖

項(xiàng)目需求要獲取多個(gè)視頻的第十秒截圖

百度了一個(gè)方法

// 獲取視頻第一幀
- (UIImage*) getVideoPreViewImage:(NSURL *)path
{
    AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:path options:nil];
    AVAssetImageGenerator *assetGen = [[AVAssetImageGenerator alloc] initWithAsset:asset];
    
    assetGen.appliesPreferredTrackTransform = YES;
    CMTime time = CMTimeMakeWithSeconds(0.0, 600);
    NSError *error = nil;
    CMTime actualTime;
    CGImageRef image = [assetGen copyCGImageAtTime:time actualTime:&actualTime error:&error];
    UIImage *videoImage = [[UIImage alloc] initWithCGImage:image];
    CGImageRelease(image);
    return videoImage;
}

想當(dāng)然地把CMTime time = CMTimeMakeWithSeconds(0.0, 600);改成CMTime time = CMTimeMakeWithSeconds(10.0, 600);

發(fā)現(xiàn)效率很低
廢了很多時(shí)間去做優(yōu)化,開(kāi)線程,回主線程刷界面,巴拉巴拉

之后查閱了七牛開(kāi)發(fā)文檔之后,才發(fā)現(xiàn),七牛給了獲取視頻截圖的接口,
用文件地址 + vframe/jpg/offset/0 就是取 0秒的截圖 。 后邊0是秒的單位
瞬間XXXXX

[imageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@?vframe/jpg/offset/10",model.url]]];

這樣就OK了??!


小白總結(jié),歡迎打臉指正

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容