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

NukeVideo: local video preview is not generated #811

Open
alexvasilkov opened this issue Aug 22, 2024 · 0 comments
Open

NukeVideo: local video preview is not generated #811

alexvasilkov opened this issue Aug 22, 2024 · 0 comments

Comments

@alexvasilkov
Copy link

I have several local video files and I need to display a grid of thumbnails.

I registered the video decoder like this:

ImageDecoderRegistry.shared.register(ImageDecoders.Video.init)

But it doesn't work, thumbnails are not loaded.

I noticed that decode(_ data: Data) function of the ImageDecoders.Video class always returns an empty image.
But decodePartiallyDownloadedData(_ data: Data) implementation looks just fine.

I ended up implementing a simple wrapper that fixes the issue:

private class VideoDecoderFixed: ImageDecoding, @unchecked Sendable {
  private let decoder: ImageDecoders.Video
  var isAsynchronous: Bool { decoder.isAsynchronous }

  init?(context: ImageDecodingContext) {
    guard let decoder = ImageDecoders.Video(context: context) else { return nil }
    self.decoder = decoder
  }

  func decode(_ data: Data) throws -> ImageContainer {
    if let image = decoder.decodePartiallyDownloadedData(data) { return image }
    return try decoder.decode(data)
  }

  func decodePartiallyDownloadedData(_ data: Data) -> ImageContainer? {
    decoder.decodePartiallyDownloadedData(data)
  }
}

Is it expected that decode(_ data: Data) function returns an empty image?
Do you think it could use the same logic as in decodePartiallyDownloadedData(_ data: Data)?
Does the workaround described above seem fine?

Thanks!

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

1 participant