ios - 无法从视频网址生成缩略图
<p><p>我正在使用此代码从视频网址生成缩略图</p>
<pre><code>AVURLAsset *asset=[ initWithURL:videoUrl options:nil];
AVAssetImageGenerator *generator =
[ initWithAsset:asset];
generator.appliesPreferredTrackTransform=TRUE;
CMTime thumbTime = CMTimeMakeWithSeconds(0,30);
AVAssetImageGeneratorCompletionHandler handler = ^(CMTime requestedTime, CGImageRef imgRef, CMTime actualTime, AVAssetImageGeneratorResult result, NSError *error){
if (result != AVAssetImageGeneratorSucceeded) {
NSLog(@"Couldn't generate Thumbnail, error:%@", error);
}
UIImage *thumbnailImage = ;
};
] completionHandler:handler];
</code></pre>
<p>但我收到此错误。</p>
<pre><code>Couldn't generate Thumbnail, error:Error Domain=AVFoundationErrorDomain
Code=-11800 "The operation could not be completed" UserInfo=
{NSUnderlyingError=0x174251c40 {Error Domain=NSOSStatusErrorDomain Code=-308
"(null)"}, NSLocalizedFailureReason=An unknown error occurred (-308),
NSLocalizedDescription=The operation could not be completed}
</code></pre>
<p>我这样做对吗?有人可以帮我吗?谢谢</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><pre><code>import AVFoundation framework
</code></pre>
<p>然后,在.h中导入如下</p>
<pre><code>#import <AVFoundation/AVFoundation.h>
</code></pre>
<p>当你想从视频中生成缩略图时,最后写下面的代码</p>
<pre><code>AVURLAsset *assetObj = [ initWithURL:self.urlForConevW options:nil];
AVAssetImageGenerator *ImgObj = [ initWithAsset:assetObj];
NSError *error = NULL;
CMTime time = CMTimeMake(1, 65);
CGImageRef refImg = ;
NSLog(@"error==%@, Refimage==%@", error, refImg);
UIImage *finalImage= [ initWithCGImage:refImg];
</code></pre></p>
<p style="font-size: 20px;">关于ios - 无法从视频网址生成缩略图,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/39911122/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/39911122/
</a>
</p>
页:
[1]