shahen94 / react-native-video-processing

Native Video editing/trimming/compressing :movie_camera: library for React-Native
https://shahen94.github.io/react-native-video-processing/
MIT License
1.25k stars 326 forks source link

getPreviewForSecond on android throwing error setDataSource failed #255

Open sidpauhal opened 4 years ago

sidpauhal commented 4 years ago

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 commented 4 years ago

@shahen94 can you help in this?

shahen94 commented 4 years ago

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

sidpauhal commented 4 years ago

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

shahen94 commented 4 years ago

Seems your URL is invalid

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

sidpauhal commented 4 years ago

@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

dittmarconsulting commented 4 years ago

@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.

adamawang commented 3 years ago

@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.

swadique commented 2 years ago

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