Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Video support for LazyImage or FetchImage #495

Closed
larryonoff opened this issue Jul 13, 2021 · 7 comments
Closed

Video support for LazyImage or FetchImage #495

larryonoff opened this issue Jul 13, 2021 · 7 comments

Comments

@larryonoff
Copy link
Contributor

larryonoff commented Jul 13, 2021

Hello!

I didn't find any ways to load data (generally I need video support) with LazyImage or FetchImage. I think that the first step is adding loadData support to FetchImage.

FYI. My video url doesn't have file extension like https://kean.github.io/videos/cat_video.mp4.

What's your thoughts?

@kean
Copy link
Owner

kean commented Jul 15, 2021

FetchImage and LazyImage already support video. You can see how it's implemented in https://github.com/kean/NukeUI/blob/b3f04143bd137c7403aedb0a39498decd63faf63/Sources/ImageView.swift#L158 and https://github.com/kean/NukeUI/blob/b3f04143bd137c7403aedb0a39498decd63faf63/Sources/VideoImageDecoder.swift.

The general idea is to:

  1. Register a custom image decoder that for video files would generate a preview image and attach data to the image container (ImageContainer)
  2. When FetchImage finishes loading it gives you an ImageContainer with you data attached
  3. Use data to play the content

GIF rendering is implemented in a very similar way.

@larryonoff
Copy link
Contributor Author

FetchImage and LazyImage already support video. You can see how it's implemented in https://github.com/kean/NukeUI/blob/b3f04143bd137c7403aedb0a39498decd63faf63/Sources/ImageView.swift#L158 and https://github.com/kean/NukeUI/blob/b3f04143bd137c7403aedb0a39498decd63faf63/Sources/VideoImageDecoder.swift.

The general idea is to:

  1. Register a custom image decoder that for video files would generate a preview image and attach data to the image container (ImageContainer)
  2. When FetchImage finishes loading it gives you an ImageContainer with you data attached
  3. Use data to play the content

GIF rendering is implemented in a very similar way.

This's what I've expected. I've tried to load the following video, but it doesn't work.

I wasn't able to find how Nuke detects when load data (video) instead of image. It never tried to load data.

@kean
Copy link
Owner

kean commented Jul 15, 2021

Here is how it does it https://github.com/kean/NukeUI/blob/b3f04143bd137c7403aedb0a39498decd63faf63/Sources/VideoImageDecoder.swift#L80. It's based on the file "magic numbers". It might be incomplete.

@larryonoff
Copy link
Contributor Author

larryonoff commented Jul 15, 2021

Here is how it does it https://github.com/kean/NukeUI/blob/b3f04143bd137c7403aedb0a39498decd63faf63/Sources/VideoImageDecoder.swift#L80. It's based on "magic numbers". It might be incomplete.

thanks! I need to analyse this. It looks that It covers several types.

@larryonoff
Copy link
Contributor Author

@kean looking at Nuke source code now.

LazyImageView executes ImageDecoders.Video.register() on isVideoRenderingEnabled = true, see https://github.com/kean/NukeUI/blob/main/Sources/LazyImageView.swift#L254

LazyImage doesn't execute ImageDecoders.Video.register(), so ImageDecoding unable to decode video -> so data is not loaded for LazyImage

@kean
Copy link
Owner

kean commented Jul 18, 2021

Right, that's my bad. I changed LazyImage in one of the recent releases so that it no longer uses LazyImageView under the hood by forgot to move the decoder registration.

@kean
Copy link
Owner

kean commented Jul 18, 2021

Should be fixed in NukeUI 0.6.4

@kean kean closed this as completed Jul 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants