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 325 forks source link

Out of Memory in Android when calling ProcessManager.compress #134

Open ghost opened 7 years ago

ghost commented 7 years ago

I cant seem to compress a 10 sec video using ProcessManager.compress in android.,

This is how I am trying to do it:

componentWillMount() {
>  const options = {
>             width: 500,
>             height: 500,
>             bitrateMultiplier: 3, // iOS only
>             saveToCameraRoll: true, // default is false, iOS only
>             saveWithCurrentDate: true, // default is false, iOS only
>             minimumBitrate: 300000, // iOS only
>             removeAudio: false, // default is false
>         };
>         console.log(this.props.navigation.state.params.videoData.path);
> 
>          const me = ProcessingManager.compress(this.props.navigation.state.params.videoData.path, options);
>          console.log(me);
}

this.props.navigation.state.params.videoData.path is a string of value 'file:///storage/emulated/0/Movies/VID_20171110_191714.mp4'

This is the error I get:

Error: compress error: failed. ffmpeg version 3.3.5 Copyright (c) 2000-2017 the FFmpeg developers built with gcc 4.8 (GCC) configuration: --target-os=linux --cross-prefix=/Users/kesha/Projects/ffmpeg-android/toolchain-android/bin/arm-linux-androideabi- --arch=arm --cpu=cortex-a8 --enable-runtime-cpudetect --sysroot=/Users/kesha/Projects/ffmpeg-android/toolchain-android/sysroot --enable-libx264 --enable-pthreads --disable-debug --disable-ffserver --enable-version3 --enable-hardcoded-tables --disable-ffplay --disable-ffprobe --enable-yasm --disable-doc --disable-shared --enable-static --enable-nonfree --disable-network --enable-gpl --enable-ffmpeg --enable-small --disable-filters --enable-filter=copy --enable-filter=trim --enable-filter=crop --enable-filter=scale --enable-filter=format --pkg-config=/Users/kesha/Projects/ffmpeg-android/ffmpeg-3.3-pkg-config --prefix=/Users/kesha/Projects/ffmpeg-android/build/armeabi-v7a --extra-cflags='-I/Users/kesha/Projects/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all' --extra-ldflags='-L/Users/kesha/Projects/ffmpeg-android/toolchain-android/lib -Wl,-z,relro -Wl,-z,now -pie' --extra-cxxflags= --extra-libs='-lx264 -lm' libavutil 55. 58.100 / 55. 58.100 libavcodec 57. 89.100 / 57. 89.100 libavformat 57. 71.100 / 57. 71.100 libavdevice 57. 6.100 / 57. 6.100 libavfilter 6. 82.100 / 6. 82.100 libswscale 4. 6.100 / 4. 6.100 libswresample 2. 7.100 / 2. 7.100 libpostproc 54. 5.100 / 54. 5.100Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'file:///storage/emulated/0/Movies/VID_20171110_191714.mp4': Metadata: major_brand : mp42 minor_version : 0 compatible_brands: isommp42 creation_time : 2017-11-10T16:17:19.000000Z com.android.version: 6.0.1 Duration: 00:00:04.80, start: 0.000000, bitrate: 2120 kb/s Stream #0:0(eng): Video: h264 (avc1 / 0x31637661), yuv420p, 800x450, 1906 kb/s, 16.46 fps, 16.58 tbr, 90k tbn, 180k tbc (default) Metadata: rotate : 270 creation_time : 2017-11-10T16:17:19.000000Z handler_name : VideoHandle Side data: displaymatrix: rotation of 90.00 degrees Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 256 kb/s (default) Metadata: creation_time : 2017-11-10T16:17:19.000000Z handler_name : SoundHandleStream mapping: Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264)) Stream #0:1 -> #0:1 (aac (native) -> aac (native))Press [q] to stop, [?] for helpframe= 0 fps=0.0 q=0.0 size= 0kB time=-577014:32:22.77 bitrate= -0.0kbits/s speed=N/A Error reinitializing filters!Failed to inject frame into filter network: Out of memoryError while processing the decoded data for stream #0:0[aac @ 0xb60c5c00] Qavg: 22480.779[aac @ 0xb60c5c00] 2 frames left in the queue on closingConversion failed! at createErrorFromErrorData (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:1807:15) at http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:1760:25 at MessageQueue.__invokeCallback (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2118:16) at http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:1935:16 at MessageQueue.__guard (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2053:9) at MessageQueue.invokeCallbackAndReturnFlushedQueue (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:1934:12) at http://localhost:8081/debugger-ui/debuggerWorker.js:72:58
code
:
"EUNSPECIFIED"
framesToPop
:
1
message
:
"compress error: failed. ffmpeg version 3.3.5 Copyright (c) 2000-2017 the FFmpeg developers  built with gcc 4.8 (GCC)  configuration: --target-os=linux --cross-prefix=/Users/kesha/Projects/ffmpeg-android/toolchain-android/bin/arm-linux-androideabi- --arch=arm --cpu=cortex-a8 --enable-runtime-cpudetect --sysroot=/Users/kesha/Projects/ffmpeg-android/toolchain-android/sysroot --enable-libx264 --enable-pthreads --disable-debug --disable-ffserver --enable-version3 --enable-hardcoded-tables --disable-ffplay --disable-ffprobe --enable-yasm --disable-doc --disable-shared --enable-static --enable-nonfree --disable-network --enable-gpl --enable-ffmpeg --enable-small --disable-filters --enable-filter=copy --enable-filter=trim --enable-filter=crop --enable-filter=scale --enable-filter=format --pkg-config=/Users/kesha/Projects/ffmpeg-android/ffmpeg-3.3-pkg-config --prefix=/Users/kesha/Projects/ffmpeg-android/build/armeabi-v7a --extra-cflags='-I/Users/kesha/Projects/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all' --extra-ldflags='-L/Users/kesha/Projects/ffmpeg-android/toolchain-android/lib -Wl,-z,relro -Wl,-z,now -pie' --extra-cxxflags= --extra-libs='-lx264 -lm'  libavutil      55. 58.100 / 55. 58.100  libavcodec     57. 89.100 / 57. 89.100  libavformat    57. 71.100 / 57. 71.100  libavdevice    57.  6.100 / 57.  6.100  libavfilter     6. 82.100 /  6. 82.100  libswscale      4.  6.100 /  4.  6.100  libswresample   2.  7.100 /  2.  7.100  libpostproc    54.  5.100 / 54.  5.100Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'file:///storage/emulated/0/Movies/VID_20171110_191714.mp4':  Metadata:    major_brand     : mp42    minor_version   : 0    compatible_brands: isommp42    creation_time   : 2017-11-10T16:17:19.000000Z    com.android.version: 6.0.1  Duration: 00:00:04.80, start: 0.000000, bitrate: 2120 kb/s    Stream #0:0(eng): Video: h264 (avc1 / 0x31637661), yuv420p, 800x450, 1906 kb/s, 16.46 fps, 16.58 tbr, 90k tbn, 180k tbc (default)    Metadata:      rotate          : 270      creation_time   : 2017-11-10T16:17:19.000000Z      handler_name    : VideoHandle    Side data:      displaymatrix: rotation of 90.00 degrees    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 256 kb/s (default)    Metadata:      creation_time   : 2017-11-10T16:17:19.000000Z      handler_name    : SoundHandleStream mapping:  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))  Stream #0:1 -> #0:1 (aac (native) -> aac (native))Press [q] to stop, [?] for helpframe=    0 fps=0.0 q=0.0 size=       0kB time=-577014:32:22.77 bitrate=  -0.0kbits/s speed=N/A    Error reinitializing filters!Failed to inject frame into filter network: Out of memoryError while processing the decoded data for stream #0:0[aac @ 0xb60c5c00] Qavg: 22480.779[aac @ 0xb60c5c00] 2 frames left in the queue on closingConversion failed!"
stack
:
"Error: compress error: failed. ffmpeg version 3.3.5 Copyright (c) 2000-2017 the FFmpeg developers  built with gcc 4.8 (GCC)  configuration: --target-os=linux --cross-prefix=/Users/kesha/Projects/ffmpeg-android/toolchain-android/bin/arm-linux-androideabi- --arch=arm --cpu=cortex-a8 --enable-runtime-cpudetect --sysroot=/Users/kesha/Projects/ffmpeg-android/toolchain-android/sysroot --enable-libx264 --enable-pthreads --disable-debug --disable-ffserver --enable-version3 --enable-hardcoded-tables --disable-ffplay --disable-ffprobe --enable-yasm --disable-doc --disable-shared --enable-static --enable-nonfree --disable-network --enable-gpl --enable-ffmpeg --enable-small --disable-filters --enable-filter=copy --enable-filter=trim --enable-filter=crop --enable-filter=scale --enable-filter=format --pkg-config=/Users/kesha/Projects/ffmpeg-android/ffmpeg-3.3-pkg-config --prefix=/Users/kesha/Projects/ffmpeg-android/build/armeabi-v7a --extra-cflags='-I/Users/kesha/Projects/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all' --extra-ldflags='-L/Users/kesha/Projects/ffmpeg-android/toolchain-android/lib -Wl,-z,relro -Wl,-z,now -pie' --extra-cxxflags= --extra-libs='-lx264 -lm'  libavutil      55. 58.100 / 55. 58.100  libavcodec     57. 89.100 / 57. 89.100  libavformat    57. 71.100 / 57. 71.100  libavdevice    57.  6.100 / 57.  6.100  libavfilter     6. 82.100 /  6. 82.100  libswscale      4.  6.100 /  4.  6.100  libswresample   2.  7.100 /  2.  7.100  libpostproc    54.  5.100 / 54.  5.100Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'file:///storage/emulated/0/Movies/VID_20171110_191714.mp4':  Metadata:    major_brand     : mp42    minor_version   : 0    compatible_brands: isommp42    creation_time   : 2017-11-10T16:17:19.000000Z    com.android.version: 6.0.1  Duration: 00:00:04.80, start: 0.000000, bitrate: 2120 kb/s    Stream #0:0(eng): Video: h264 (avc1 / 0x31637661), yuv420p, 800x450, 1906 kb/s, 16.46 fps, 16.58 tbr, 90k tbn, 180k tbc (default)    Metadata:      rotate          : 270      creation_time   : 2017-11-10T16:17:19.000000Z      handler_name    : VideoHandle    Side data:      displaymatrix: rotation of 90.00 degrees    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 256 kb/s (default)    Metadata:      creation_time   : 2017-11-10T16:17:19.000000Z      handler_name    : SoundHandleStream mapping:  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))  Stream #0:1 -> #0:1 (aac (native) -> aac (native))Press [q] to stop, [?] for helpframe=    0 fps=0.0 q=0.0 size=       0kB time=-577014:32:22.77 bitrate=  -0.0kbits/s speed=N/A    Error reinitializing filters!Failed to inject frame into filter network: Out of memoryError while processing the decoded data for stream #0:0[aac @ 0xb60c5c00] Qavg: 22480.779[aac @ 0xb60c5c00] 2 frames left in the queue on closingConversion failed!↵    at createErrorFromErrorData (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:1807:15)↵    at http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:1760:25↵    at MessageQueue.__invokeCallback (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2118:16)↵    at http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:1935:16↵    at MessageQueue.__guard (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2053:9)↵    at MessageQueue.invokeCallbackAndReturnFlushedQueue (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:1934:12)↵    at http://localhost:8081/debugger-ui/debuggerWorker.js:72:58"
shahen94 commented 7 years ago

@kk1429 can you please build example app that I can reproduce it ?

vvavepacket commented 6 years ago

I also encounter the same in Android. My phone is Note 8 and I'm just trying to compress a 2 seconds video file and it throws same error as above.

vvavepacket commented 6 years ago

i fixed the issue by removing running programs.

gusgoose commented 6 years ago

I'm having the same issue (Note 4) with the same error message. Removing other programmes doesn't fix the problem. If anybody has any ideas I'd be grateful.

Error reinitializing filters!Failed to inject frame into filter network: Out of memoryError while processing the decoded data for stream #0:0[aac @ 0xb5dbf000] Qavg: 23986.367[aac @ 0xb5dbf000] 2 frames left in the queue on closingConversion failed!

EDIT: Just established that this is a bug in the newest release -1.12.7 works fine! Would help you fix it but sadly it's beyond my ability. Hope this helps.

jiyarong commented 6 years ago

I got the same problem

vvavepacket commented 6 years ago

i also encounter the same issue on note 4, with bigger files (100mb). I tried a 7mb file, and it works fine. I believe this module is loading the whole video file in RAM? is it the most efficient way?

kesha-antonov commented 6 years ago

👍 +1

Any guesses?

kesha-antonov commented 6 years ago

Seems like it's something with the build https://github.com/shahen94/react-native-video-processing/commit/ea10cff3df89b5367d80d1749768458b5253c9e8 I'll try to fix

kesha-antonov commented 6 years ago

I think we should write some tests for ffmpeg to prevent bugs like this.

kesha-antonov commented 6 years ago

I've fixed the issue. @shahen94 Add me to colaborators or ping me when issues like this arise. Since I'm using this lib I want to know if something goes wrong before users do.

kesha-antonov commented 6 years ago

Ok guys. This is the PR https://github.com/shahen94/react-native-video-processing/pull/141

Please check and confirm that it fixes your problems 👍

amberv0 commented 6 years ago

I just stumbled upon this issue. Installed the lib from npm today. Have the changes been published to npm? In my case it's a 2 sec long video. And I also checked, and the 1.12.7 version works without problems

shahen94 commented 6 years ago

@amberv0 please use sources from the master branch

amberv0 commented 6 years ago

@shahen94 , confirming that it works properly with the version from master :)

vvavepacket commented 6 years ago

version 1.13.0 does not contain the fix, how do we move the fix to version 1.14.0

vvavepacket commented 6 years ago

issue still persists on Android Jellybean

9.556 2947-3001/? I/ReactNativeJS: { [Error: compress error: failed. /data/data/com.sample.prod/files/ffmpeg[1]: syntax error: '�� 4��4' unexpected] framesToPop: 1, code: 'EUNSPECIFIED' }

jln-dk commented 6 years ago

Facing the same issue. Tried out the master branch, as @shahen94 mentions a few comments up, (latest commit as of writing: f57addffcf94c97255f7622bfc18ceec53d644ed) and bug is still there: app is crashing on Android with an "out of memory" exception.

Full crash log:

Error: compressing image - compress error: failed. ffmpeg version 3.3.5 Copyright (c) 2000-2017 the FFmpeg developers built with gcc 4.8 (GCC) configuration: --target-os=linux --cross-prefix=/Users/kesha/Projects/ffmpeg-android/toolchain-android/bin/arm-linux-androideabi- --arch=arm --cpu=cortex-a8 --enable-runtime-cpudetect --sysroot=/Users/kesha/Projects/ffmpeg-android/toolchain-android/sysroot --enable-libx264 --enable-pthreads --disable-debug --disable-ffserver --enable-version3 --enable-hardcoded-tables --disable-ffplay --disable-ffprobe --enable-yasm --disable-doc --disable-shared --enable-static --enable-nonfree --disable-network --enable-gpl --enable-ffmpeg --enable-small --disable-filters --enable-filter=copy --enable-filter=trim --enable-filter=crop --enable-filter=scale --enable-filter=format --pkg-config=/Users/kesha/Projects/ffmpeg-android/ffmpeg-3.3-pkg-config --prefix=/Users/kesha/Projects/ffmpeg-android/build/armeabi-v7a --extra-cflags='-I/Users/kesha/Projects/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all' --extra-ldflags='-L/Users/kesha/Projects/ffmpeg-android/toolchain-android/lib -Wl,-z,relro -Wl,-z,now -pie' --extra-cxxflags= --extra-libs='-lx264 -lm' libavutil 55. 58.100 / 55. 58.100 libavcodec 57. 89.100 / 57. 89.100 libavformat 57. 71.100 / 57. 71.100 libavdevice 57. 6.100 / 57. 6.100 libavfilter 6. 82.100 / 6. 82.100 libswscale 4. 6.100 / 4. 6.100 libswresample 2. 7.100 / 2. 7.100 libpostproc 54. 5.100 / 54. 5.100Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/storage/emulated/0/DCIM/Camera/VID_20180205_081711.mp4': Metadata: major_brand : mp42 minor_version : 0 compatible_brands: isommp42 creation_time : 2018-02-05T04:17:11.000000Z location : +00.0000+000.0000/ location-eng : +00.0000+000.0000/ com.android.version: 8.1.0 Duration: 00:00:30.57, start: 0.000000, bitrate: 21770 kb/s Stream #0:0(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 96 kb/s (default) Metadata: creation_time : 2018-02-05T04:17:11.000000Z handler_name : SoundHandle Stream #0:1(eng): Video: h264 (avc1 / 0x31637661), yuvj420p(pc, smpte170m), 1920x1080, 21889 kb/s, SAR 1:1 DAR 16:9, 29.90 fps, 30 tbr, 90k tbn, 180k tbc (default) Metadata: rotate : 90 creation_time : 2018-02-05T04:17:11.000000Z handler_name : VideoHandle Side data: displaymatrix: rotation of -90.00 degreesStream mapping: Stream #0:1 -> #0:0 (h264 (native) -> h264 (libx264)) Stream #0:0 -> #0:1 (aac (native) -> aac (native))Press [q] to stop, [?] for helpError reinitializing filters!Failed to inject frame into filter network: Out of memoryError while processing the decoded data for stream #0:1[aac @ 0xefc8ec00] Qavg: 4409.910[aac @ 0xefc8ec00] 2 frames left in the queue on closingConversion failed!

I believe the important lines are these:

Failed to inject frame into filter network: Out of memoryError while processing the decoded data for stream #0:1[aac @ 0xefc8ec00] Qavg: 4409.910[aac @ 0xefc8ec00] 2 frames left in the queue on closingConversion failed!

jln-dk commented 6 years ago

@shahen94 @kesha-antonov maybe this issue should be reopened?

kesha-antonov commented 6 years ago

Hey guys. Don't have time for this now. You can try build new ffmpeg with https://github.com/kesha-antonov/ffmpeg-android

See my latest PRs to this repo: https://github.com/shahen94/react-native-video-processing/pull/141/files

sunaryohadi commented 6 years ago

Current ffmpeg only working with ARM, but it's fail on X86 (emulator).

As in https://github.com/kesha-antonov/ffmpeg-android ... there is 3 different type of prebuilt ffmpeg.

Should it use according to our App Arch target (Arm or X86) ?

shahen94 commented 6 years ago

@kesha-antonov

kesha-antonov commented 6 years ago

Hey guys! Sorry, I don't use emulator so cannot help here. We've discussed this somewhere in issues