Aviram Netanel
Aviram Netanel

Reputation: 13625

Swift - generating image thumbnail from a local video

I'm trying to create a Thumbnail image from a video:

    func getImageFromUrl(url:URL) -> UIImage?{
    print(url)
    let video = AVURLAsset(url: url)
        let thumbnailGenerator = AVAssetImageGenerator(asset: video)

        do
        {
            let cgImage = try thumbnailGenerator.copyCGImage(at: CMTimeMake(value: 0, timescale: 1), actualTime: nil)
            let UiImage = UIImage(cgImage: cgImage)
            return UiImage
        }
        catch
        { print(error) }
    return nil
}

and I'm getting this Error:

Error Domain=AVFoundationErrorDomain Code=-11850 "Operation Stopped" UserInfo={NSLocalizedFailureReason=The server is not correctly configured., NSLocalizedDescription=Operation Stopped, NSUnderlyingError=0x2804c50b0 {Error Domain=NSOSStatusErrorDomain Code=-12939 "(null)"}}

HELP ANYONE ?

Upvotes: 0

Views: 851

Answers (3)

Dima G
Dima G

Reputation: 2025

Also, copyCGImage is Deprecated

Try using image(at:) instead.

Upvotes: 0

Abedalkareem Omreyh
Abedalkareem Omreyh

Reputation: 2329

It looks like a server issue as peer apple documentation

case serverIncorrectlyConfigured = -11850

This error might indicate that the server doesn’t support byte-range requests.

You can try this video URL to check if your code actually works:

https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4

Will you be able to share the video URL to check?

Upvotes: 0

EJZ
EJZ

Reputation: 1256

That error tells us that this is an HTTP, not local issue. The Apple Developer Documentation says "This error might indicate that the HTTP server doesn’t support byte range requests." and or that "The HTTP server sending the media resource is not configured as expected." Check to make sure the HTTP server is configured properly and allows this type of query.

Upvotes: 1

Related Questions