0

I am trying to grab a frame from video.

But copyCGImageAtTime (in AVAssetImageGenerator) fails with this error:

The operation could not be completed

When I specify invalid path, it throws different error, so it looks like it's not path problem.

I am trying with a MP4 file. Maybe that is a problem?

import Cocoa
import AVFoundation

var asset = AVAsset.init(URL: NSURL.init(fileURLWithPath: "/Users/gippeumi/test.mp4"))
var assetGen = AVAssetImageGenerator(asset: asset)
assetGen.appliesPreferredTrackTransform = true
var tim = CMTimeMakeWithSeconds(0.0, 1)
do {
    var img = try assetGen.copyCGImageAtTime(tim, actualTime: nil)
} catch let error as NSError {
    // (Printing error here...)
}
Gippeumi
  • 251
  • 2
  • 18

1 Answers1

0

" The Error is probably due to use of URLWithString. I think you should use -fileURLWithPath instead of URLWithString."

You can check this link , maybe it helps you.

Extract thumbnail from video url

Community
  • 1
  • 1
Sososo
  • 19
  • 6
  • 1
    It didn't worked on playground but on actual project, it works. I tried a lot of times but it never failed yet. – Gippeumi Nov 26 '16 at 07:26