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

Configurable time tolerance precision for preview images #321

Open discretepackets opened 3 years ago

discretepackets commented 3 years ago

👋 I noticed that ProcessingManager.getPreviewImageAtPosition() does not specify a time tolerance for the AVAssetImageGenerator object. This means that the time parameter provided to the function is only an approximate guideline, and iOS may return an image frame slightly before or after the specified time.

It will be helpful if getPreviewImageAtPosition() provides a configurable time tolerance parameter.

Specifically, to get strict tolerance, where the preview image is obtained exactly at the time specified, the change would be to include right after this line here

https://github.com/shahen94/react-native-video-processing/blob/1a5ebbfedf2a0f1149c8a27d3db0241b5537571b/ios/RNVideoProcessing/RNVideoTrimmer/RNVideoTrimmer.swift#L587

these two lines:

imageGenerator.requestedTimeToleranceAfter = CMTime.zero
imageGenerator.requestedTimeToleranceBefore = CMTime.zero

Documentation reference: https://developer.apple.com/documentation/avfoundation/avassetimagegenerator/1390571-requestedtimetolerancebefore https://developer.apple.com/documentation/avfoundation/avassetimagegenerator/1387751-requestedtimetoleranceafter

shahen94 commented 3 years ago

@discretepackets Thank you for raising this opportunity. That would be great if you can open a PR - I'll review & merge/release immediately.

Thanks.