菜鸟教程小白 发表于 2022-12-11 16:53:16

生成返回 0 字节 [] 的视频缩略图的 iOS 代码


                                            <p><p>我正在使用 CodenameOne 创建一个应用程序,并且必须使用 iosnative 界面来生成一些视频缩略图。这是我在 iOS 中使用的代码:</p>

<pre><code>-(NSData*)createThumbnailFromMp4:(NSString*)param{

   NSURL *mediaURL = ;
   AVAsset *asset = ;
   CMTime duration = ;
   CMTime snapshot = CMTimeMake(duration.value / 2, duration.timescale);

   AVAssetImageGenerator *imageGenerator = [ initWithAsset:asset];
   CGImageRef imageRef = ;
   UIImage *thumbnail = ;
   CGImageRelease(imageRef);

   return UIImagePNGRepresentation(thumbnail);
}
</code></pre>

<p>传入的参数是视频的完整路径,但是当我调用它时我得到的只是一个长度为 0 的字节 []。下面是 CodenameOne 的代码:</p>

<pre><code>byte[] thumbnailImage = tg.createThumbnailFromMp4(FileSystemStorage.getInstance().getAppHomePath() + movePath);
</code></pre>

<p>其中 movePath 只是本地存储视频的文件名。 </p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><pre><code> AVAsset *asset = ;
AVAssetImageGenerator *imageGenerator = [initWithAsset:asset];
CMTime time = ;
time.value = 1000 ;
CGImageRef imageRef = ;
image1 = ;
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于生成返回 0 字节 [] 的视频缩略图的 iOS 代码,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/38177114/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/38177114/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: 生成返回 0 字节 [] 的视频缩略图的 iOS 代码