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

ProcessingManager.trim() don't trim correctly on IOS #297

Open khattab93 opened 4 years ago

khattab93 commented 4 years ago

Current Behavior

ProcessingManager.trim() doesn't trim video correctly on IOS.

When I pass a startTime which isn't equal zero, the video is trimmed incorrectly. The trimmed video was always less than expected. The end time of the trimmed video was the same as what I passed but the start time was larger.

If I tried to trim the video with the same startTime and endTime multiple times, I got different videos of different durations.

Example:

const resultUri = await ProcessingManager.trim(uri, { startTime: 2.154613, endTime: 8.465112 })

After saving the trimmed video, I found that the saved video was 3 seconds long. I tried to trim again with the same values and I got a video of 4 seconds long.

Expected Behavior

I expect the trimmed video to be as what I define in the options.

Your Environment

software version
react-native-video-processing I use this
react-native 0.61.5
node v10.16.3
khattab93 commented 4 years ago

@shahen94 Could you help me with my issue?

tiennm16 commented 3 years ago

I had the same issue. Did you solve this problem @khattab93 ?

IlyaPyatkin commented 3 years ago

@khattab93 @tiennm16 @santiagovazquez This seems to have been broken by #264. Since the time range is set on the AVMutableComposition, it no longer needs to be set on the AVAssetExportSession. Setting it in both cases results in startTime being doubled (e.g. you want trim a 10 seconds video with startTime: 1 and endTime: 10. You expect a 9 second video in result, but the resulting video is 8 seconds long. The real startTime is 2) I did not encounter varying resulting lengths as mentioned by @khattab93, so there might be something else at play as well.

This is fixed by simply removing this line from RNVideoTrimmer.swift: exportSession.timeRange = timeRange An alternative way is to halve your startTime when invoking ProcessingManager.trim() in iOS, if you want to avoid changing module files.

mshehrozsajjad commented 3 years ago

Keeping a track for when it is fixed in the library and code can be returned to normal.

eric-dev-master commented 3 years ago

@IlyaPyatkin Thanks. halving start time is working.