react-native-view-shot icon indicating copy to clipboard operation
react-native-view-shot copied to clipboard

captureRef a react-native-video view returns blank(white) image on iPhone devices

Open DonghaoLyu opened this issue 2 years ago • 5 comments

Bug report

In the code we have a react-native-video component wrapped by <ViewShot> like this:

<ViewShot
     style={viewShotStyle}
     ref={ref => {
     this.viewShot = ref;
     }}
    >
      <Video
        paused={!play}
        ref={ref => {
          this.player = ref;
        }}
        repeat
        source={source}
        resizeMode="contain"
      />
</ViewShot>

And we triggered the following function to use captureRef to generate a thumbnail image for the video.

async getThumbnail() {
    if (this.viewShot) {
      const thumb = await captureRef(this.viewShot, { format: 'png' });
      return thumb;
    }
    return null;
  }

But everytime the getThumbnail function gets called, it returns a blank/white image.

The issue is only happening on iPhone devices. We tested on simulators and Android devices and it worked as expected.

Also, from the interoperability table, it says view shot would not work with react native video, but I saw an example and a thread saying they should work. I'm kind of confused on this as well.

Version & Platform


├─┬ @react-native-async-storage/[email protected]
│ └── [email protected] deduped
├─┬ @react-native-community/[email protected]
│ └── [email protected] deduped
├─┬ @react-native-community/[email protected]
│ └── [email protected] deduped invalid: ">=0.57 <=0.62" from node_modules/@react-native-community/cameraroll
├─┬ @react-native-community/[email protected]
│ └── [email protected] deduped invalid: ">=0.57 <=0.62" from node_modules/@react-native-community/cameraroll
├─┬ @react-native-community/[email protected]
│ └── [email protected] deduped invalid: ">=0.57 <=0.62" from node_modules/@react-native-community/cameraroll, ">=0.57 <0.60" from node_modules/@react-native-community/image-editor
├─┬ @react-native-community/[email protected]
│ └── [email protected] deduped invalid: ">=0.57 <=0.62" from node_modules/@react-native-community/cameraroll, ">=0.57 <0.60" from node_modules/@react-native-community/image-editor
├─┬ @react-native-community/[email protected]
│ └── [email protected] deduped invalid: ">=0.57 <=0.62" from node_modules/@react-native-community/cameraroll, ">=0.57 <0.60" from node_modules/@react-native-community/image-editor
├─┬ @react-native-community/[email protected]
│ └── [email protected] deduped invalid: ">=0.57 <=0.62" from node_modules/@react-native-community/cameraroll, ">=0.57 <0.60" from node_modules/@react-native-community/image-editor
├─┬ @react-native-firebase/[email protected]
│ └── [email protected] deduped invalid: ">=0.57 <=0.62" from node_modules/@react-native-community/cameraroll, ">=0.57 <0.60" from node_modules/@react-native-community/image-editor
├─┬ [email protected]
│ └── [email protected] deduped invalid: ">=0.57 <=0.62" from node_modules/@react-native-community/cameraroll, ">=0.57 <0.60" from node_modules/@react-native-community/image-editor
├─┬ [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected] deduped invalid: ">=0.57 <=0.62" from node_modules/@react-native-community/cameraroll, ">=0.57 <0.60" from node_modules/@react-native-community/image-editor, ">=0.60 <0.64" from node_modules/react-native-webview
│ └── [email protected] deduped invalid: ">=0.57 <=0.62" from node_modules/@react-native-community/cameraroll, ">=0.57 <0.60" from node_modules/@react-native-community/image-editor
├─┬ [email protected]
│ └── [email protected] deduped invalid: ">=0.57 <=0.62" from node_modules/@react-native-community/cameraroll, ">=0.57 <0.60" from node_modules/@react-native-community/image-editor
├─┬ [email protected]
│ └── [email protected] deduped invalid: ">=0.57 <=0.62" from node_modules/@react-native-community/cameraroll, ">=0.57 <0.60" from node_modules/@react-native-community/image-editor
├─┬ [email protected]
│ └── [email protected] deduped invalid: ">=0.57 <=0.62" from node_modules/@react-native-community/cameraroll, ">=0.57 <0.60" from node_modules/@react-native-community/image-editor
├─┬ [email protected]
│ └── [email protected] deduped invalid: ">=0.57 <=0.62" from node_modules/@react-native-community/cameraroll, ">=0.57 <0.60" from node_modules/@react-native-community/image-editor
├─┬ [email protected]
│ └── [email protected] deduped invalid: ">=0.57 <=0.62" from node_modules/@react-native-community/cameraroll, ">=0.57 <0.60" from node_modules/@react-native-community/image-editor
├─┬ [email protected]
│ └── [email protected] deduped invalid: ">=0.57 <=0.62" from node_modules/@react-native-community/cameraroll, ">=0.57 <0.60" from node_modules/@react-native-community/image-editor
├─┬ [email protected]
│ └── [email protected] deduped invalid: ">=0.57 <=0.62" from node_modules/@react-native-community/cameraroll, ">=0.57 <0.60" from node_modules/@react-native-community/image-editor
├─┬ [email protected]
│ └── [email protected] deduped invalid: ">=0.57 <=0.62" from node_modules/@react-native-community/cameraroll, ">=0.57 <0.60" from node_modules/@react-native-community/image-editor
├─┬ [email protected]
│ └── [email protected] deduped invalid: ">=0.57 <=0.62" from node_modules/@react-native-community/cameraroll, ">=0.57 <0.60" from node_modules/@react-native-community/image-editor
├─┬ [email protected]
│ └── [email protected] deduped invalid: ">=0.57 <=0.62" from node_modules/@react-native-community/cameraroll, ">=0.57 <0.60" from node_modules/@react-native-community/image-editor
├─┬ [email protected]
│ └── [email protected] deduped invalid: ">=0.57 <=0.62" from node_modules/@react-native-community/cameraroll, ">=0.57 <0.60" from node_modules/@react-native-community/image-editor
├─┬ [email protected]
│ └── [email protected] deduped invalid: ">=0.57 <=0.62" from node_modules/@react-native-community/cameraroll, ">=0.57 <0.60" from node_modules/@react-native-community/image-editor
├─┬ [email protected]
│ └── [email protected] deduped invalid: ">=0.57 <=0.62" from node_modules/@react-native-community/cameraroll, ">=0.57 <0.60" from node_modules/@react-native-community/image-editor
├─┬ [email protected]
│ └── [email protected] deduped invalid: ">=0.57 <=0.62" from node_modules/@react-native-community/cameraroll, ">=0.57 <0.60" from node_modules/@react-native-community/image-editor
├─┬ [email protected]
│ └── [email protected] deduped invalid: ">=0.57 <=0.62" from node_modules/@react-native-community/cameraroll, ">=0.57 <0.60" from node_modules/@react-native-community/image-editor, ">=0.60 <0.64" from node_modules/react-native-webview
└─┬ [email protected] invalid: ">=0.57 <=0.62" from node_modules/@react-native-community/cameraroll, ">=0.57 <0.60" from node_modules/@react-native-community/image-editor, ">=0.60 <0.64" from node_modules/react-native-webview
  └─┬ @react-native-community/[email protected]
    └── [email protected] deduped invalid: ">=0.57 <=0.62" from node_modules/@react-native-community/cameraroll, ">=0.57 <0.60" from node_modules/@react-native-community/image-editor, ">=0.60 <0.64" from node_modules/react-native-webview

Platform: iOS (more specifically, iPhone physical devices)

Expected behavior

Should correctly captures the snapshot of the video.

Actual behavior

Returns an empty image for iPhone devices.

Steps to reproduce the behavior

DonghaoLyu avatar Jul 05 '22 15:07 DonghaoLyu

@DonghaoLyu any work arounds for this? I would like to use this in my application but having the same issues.

himrocks33 avatar Jul 11 '22 17:07 himrocks33

@DonghaoLyu any work arounds for this? I would like to use this in my application but having the same issues.

No work around on this yet..

DonghaoLyu avatar Jul 12 '22 14:07 DonghaoLyu

having the same issue

master-eugene avatar Jul 19 '22 08:07 master-eugene

Yeah same here... @gre any ideas?

Gavsum avatar Jul 20 '22 12:07 Gavsum

Any insights? Still having issues. @gre

DonghaoLyu avatar Jul 26 '22 12:07 DonghaoLyu

+1

vuongqtvn avatar Sep 29 '22 02:09 vuongqtvn

+1

adriandiaz avatar Oct 16 '22 21:10 adriandiaz

+1

dequidv avatar Dec 07 '22 13:12 dequidv

same here for image in view. It works in test not in production!

babyrusa avatar Jan 07 '23 18:01 babyrusa

+1

iita71737 avatar Mar 24 '23 04:03 iita71737

react-native-view-shot is probably not the best library to look for if you need to capture a frame from a video. this is a feature to ask the video library instead because ViewShot is only here to capture a view, like take a snapshot of the elements, not get an image from a video, there are very likely more efficient and more quality ways to do this. I'm going to close this issue for now and have a clearer warning on the main README about this but unlike there is a solution that someone find and send a PR for it, there is likely no technical solution for this, like if we can't capture the image from the video at the element level it is a os limitation too.

gre avatar Mar 24 '23 20:03 gre

well it actually was documented already

Screenshot 2023-03-24 at 21 07 17

gre avatar Mar 24 '23 20:03 gre