react-native-video-processing icon indicating copy to clipboard operation
react-native-video-processing copied to clipboard

getPreviewForSecond on android throwing error setDataSource failed

Open sidpauhal opened this issue 6 years ago • 8 comments

My package.json file

"dependencies": { "@react-native-firebase/app": "^6.0.0", "@react-native-firebase/ml-vision": "^6.0.0", "react": "16.9.0", "react-native": "0.61.1", "react-native-file-share-intent": "^1.1.2", "react-native-video-processing": "^1.20.0", "rn-fetch-blob": "^0.11.2" },

OS= Android

Not able to get image preview from video

My app.js file

let thumb_size = {width: 100, height: 100};
let video_source = video_file_source;
ProcessingManager.getPreviewForSecond(video_source, 30, thumb_size).then(
(data) => console.log(data)
);

Showing error setDataSourcefailed: status = 0xFFFFFFFF

Please help

I have tested with another code and it works

ProcessingManager.getVideoInfo(video_source).then((
{duration, size, frameRate, bitrate}) => this.setState({video_duration: duration})
);

sidpauhal avatar Oct 15 '19 16:10 sidpauhal

@shahen94 can you help in this?

sidpauhal avatar Oct 16 '19 07:10 sidpauhal

@sidpauhal can you please log your video_source and provide a full-stack of error logs?

shahen94 avatar Oct 17 '19 09:10 shahen94

@shahen94 here is the screenshot from real device Screenshot_20191017-174607

sidpauhal avatar Oct 17 '19 12:10 sidpauhal

Seems your URL is invalid

https://stackoverflow.com/a/33204891/5364436

shahen94 avatar Oct 18 '19 09:10 shahen94

@shahen94 url is correct

I have tested the same url with getVideoInfo method to get video duration which works fine

ProcessingManager.getVideoInfo(video_source).then(( {duration, size, frameRate, bitrate}) => console.log(duration) );

but the same video source is not working with getPreviewForSecond method

sidpauhal avatar Oct 18 '19 15:10 sidpauhal

@sidpauhal it seems the problem is not the URL but rather to find the exact frame for the given second.

If you have a look at the code of the Trimmer.java file on line 552 you will see this code for function getFrameAtTime()

FFmpegMediaMetadataRetriever.IN_PREFERRED_CONFIG = Bitmap.Config.ARGB_8888;
metadataRetriever.setDataSource(source);

bmp = metadataRetriever.getFrameAtTime((long) (sec * 1000000));
if(bmp == null){
  promise.reject("Failed to get preview at requested position.");
   return;
}

If there is no frame on that exact position the variable bmp will be null and hence, no image will be returned.

To overcome that a prop should be added to find the next available frame nearby.

bmp = metadataRetriever.getFrameAtTime((long) (sec * 1000000), FFmpegMediaMetadataRetriever.OPTION_CLOSEST);

I would open a PR @shahen94 but I have unfortunately no time right now.

I hope that helps.

dittmarconsulting avatar Dec 23 '19 22:12 dittmarconsulting

@sidpauhal it seems the problem is not the URL but rather to find the exact frame for the given second.

If you have a look at the code of the Trimmer.java file on line 552 you will see this code for function getFrameAtTime()

FFmpegMediaMetadataRetriever.IN_PREFERRED_CONFIG = Bitmap.Config.ARGB_8888;
metadataRetriever.setDataSource(source);

bmp = metadataRetriever.getFrameAtTime((long) (sec * 1000000));
if(bmp == null){
  promise.reject("Failed to get preview at requested position.");
   return;
}

If there is no frame on that exact position the variable bmp will be null and hence, no image will be returned.

To overcome that a prop should be added to find the next available frame nearby.

bmp = metadataRetriever.getFrameAtTime((long) (sec * 1000000), FFmpegMediaMetadataRetriever.OPTION_CLOSEST);

I would open a PR @shahen94 but I have unfortunately no time right now.

I hope that helps.

Can confirm adding the FFmpegMediaMetadataRetriever.OPTION_CLOSEST option fixes thumbnail generation for certain videos that may not have an image at that exact time.

adamawang avatar Sep 16 '20 19:09 adamawang

Hi , Still i got the issue "Error: Failed to get preview at requested position." , Anyone please help me

swadique avatar Dec 15 '21 14:12 swadique