getPreviewForSecond on android throwing error setDataSource failed
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})
);
@shahen94 can you help in this?
@sidpauhal
can you please log your video_source and provide a full-stack of error logs?
@shahen94
here is the screenshot from real device

Seems your URL is invalid
https://stackoverflow.com/a/33204891/5364436
@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 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.
@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
bmpwill 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.
Hi , Still i got the issue "Error: Failed to get preview at requested position." , Anyone please help me