javascript - How to compress a video in React Native - Stack Overflow

Tried using react-native-video-processing by Shahen:Below is the code:pressVideo(source) {const options

Tried using react-native-video-processing by Shahen:

Below is the code:

pressVideo(source) {
    const options = {
        width: 800,
        height: 800,
        bitrateMultiplier: 3,
        saveToCameraRoll: true, 
        saveWithCurrentDate: true, 
        removeAudio: true 
    };

    ProcessingManagerpress(source, options)
        .then(data => {
            console.log(data);
            this.setState({ base64String: data });
        })
        .catch(console.warn);
}

but it gives error in Android device.

{ [Error: press 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/DCIM/Camera/20180301_141708.mp4': Metadata: major_brand : mp42 minor_version : 0
patible_brands: isommp42 creation_time : 2018-03-01T08:47:13.000000Z .android.version: 7.0 Duration: 00:00:04.07, start: 0.000000, bitrate: 3366 kb/s Stream #0:0(eng): Video: h264 (avc1 / 0x31637661), yuv420p(tv, smpte170m/smpte170m/bt709), 640x480, 3091 kb/s, SAR 1:1 DAR 4:3, 29.88 fps, 30 tbr, 90k tbn, 180k tbc (default) Metadata: rotate
: 90 creation_time : 2018-03-01T08:47:13.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 : 2018-03-01T08:47:13.000000Z handler_name : SoundHandleStream mapping: Stream #0:0-> #0:0 (h264 (native) -> h264 (libx264))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:0Conversion failed!] framesToPop: 1, code: 'EUNSPECIFIED' } 03-01 15:40:05.658 29497 29772 I ReactNativeJS: 4, { height: 640, width: 480 } 03-01 15:40:05.757 29497 29772 W ReactNativeJS: { [Error: press 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/DCIM/Camera/20180301_141708.mp4': Metadata: major_brand : mp42 minor_version : 0
patible_brands: isommp42 creation_time : 2018-03-01T08:47:13.000000Z .android.version: 7.0 Duration: 00:00:04.07, start: 0.000000, bitrate: 3366 kb/s Stream #0:0(eng): Video: h264 (avc1 / 0x31637661), yuv420p(tv, smpte170m/smpte170m/bt709), 640x480, 3091 kb/s, SAR 1:1 DAR 4:3, 29.88 fps, 30 tbr, 90k tbn, 180k tbc (default) Metadata: rotate
: 90 creation_time : 2018-03-01T08:47:13.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 : 2018-03-01T08:47:13.000000Z handler_name : SoundHandleStream mapping: Stream #0:0-> #0:0 (h264 (native) -> h264 (libx264))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:0Conversion failed!] framesToPop: 1, code: 'EUNSPECIFIED' }

Any solution for this issue or any other method to press the video before uploading.

Tried using react-native-video-processing by Shahen:

Below is the code:

pressVideo(source) {
    const options = {
        width: 800,
        height: 800,
        bitrateMultiplier: 3,
        saveToCameraRoll: true, 
        saveWithCurrentDate: true, 
        removeAudio: true 
    };

    ProcessingManager.press(source, options)
        .then(data => {
            console.log(data);
            this.setState({ base64String: data });
        })
        .catch(console.warn);
}

but it gives error in Android device.

{ [Error: press 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/DCIM/Camera/20180301_141708.mp4': Metadata: major_brand : mp42 minor_version : 0
patible_brands: isommp42 creation_time : 2018-03-01T08:47:13.000000Z .android.version: 7.0 Duration: 00:00:04.07, start: 0.000000, bitrate: 3366 kb/s Stream #0:0(eng): Video: h264 (avc1 / 0x31637661), yuv420p(tv, smpte170m/smpte170m/bt709), 640x480, 3091 kb/s, SAR 1:1 DAR 4:3, 29.88 fps, 30 tbr, 90k tbn, 180k tbc (default) Metadata: rotate
: 90 creation_time : 2018-03-01T08:47:13.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 : 2018-03-01T08:47:13.000000Z handler_name : SoundHandleStream mapping: Stream #0:0-> #0:0 (h264 (native) -> h264 (libx264))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:0Conversion failed!] framesToPop: 1, code: 'EUNSPECIFIED' } 03-01 15:40:05.658 29497 29772 I ReactNativeJS: 4, { height: 640, width: 480 } 03-01 15:40:05.757 29497 29772 W ReactNativeJS: { [Error: press 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/DCIM/Camera/20180301_141708.mp4': Metadata: major_brand : mp42 minor_version : 0
patible_brands: isommp42 creation_time : 2018-03-01T08:47:13.000000Z .android.version: 7.0 Duration: 00:00:04.07, start: 0.000000, bitrate: 3366 kb/s Stream #0:0(eng): Video: h264 (avc1 / 0x31637661), yuv420p(tv, smpte170m/smpte170m/bt709), 640x480, 3091 kb/s, SAR 1:1 DAR 4:3, 29.88 fps, 30 tbr, 90k tbn, 180k tbc (default) Metadata: rotate
: 90 creation_time : 2018-03-01T08:47:13.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 : 2018-03-01T08:47:13.000000Z handler_name : SoundHandleStream mapping: Stream #0:0-> #0:0 (h264 (native) -> h264 (libx264))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:0Conversion failed!] framesToPop: 1, code: 'EUNSPECIFIED' }

Any solution for this issue or any other method to press the video before uploading.

Share Improve this question edited Mar 1, 2018 at 13:58 Tomasz Mularczyk 36.3k19 gold badges118 silver badges174 bronze badges asked Mar 1, 2018 at 12:02 NivedithaNiveditha 1481 silver badge8 bronze badges 1
  • 2 Did you find any solution for video pression? – David Commented Jul 1, 2019 at 11:28
Add a ment  | 

2 Answers 2

Reset to default 2

Have a try on the following code to successfully press videos in react-native. My pressing result => 7.5mb into 1.48mb. This mand require full-gpl package

import { Platform } from 'react-native';
import {RNFFmpeg} from "react-native-ffmpeg"
import RNFS from 'react-native-fs';

function processVideo(videoUrl, callback) {
  const finalVideo = `${RNFS.CachesDirectoryPath}/audioVideoFinal.mp4`;

  cacheResourcePath(videoUrl).then((rVideoUrl) => {
   const str_cmd = `-y -i ${rVideoUrl} -c:v libx264 -crf 28 -preset ultrafast  ${finalVideo}`;
   
    RNFFmpeg.execute(
      str_cmd,
    ).then((result) => {
      if (result === 0) {
        RNFS.unlink(rVideoUrl);

        callback({
          videoPath:
            Platform.OS === 'android' ? 'file://' + finalVideo : finalVideo,
        });
      }
    });
  });
};

async function cacheResourcePath(sourcePath) {
  const uriComponents = sourcePath.split('/');
  const fileNameAndExtension = uriComponents[uriComponents.length - 1].replaceAll(' ','');

  const destPath = `${RNFS.CachesDirectoryPath}/${fileNameAndExtension}`;

  await RNFS.copyFile(sourcePath, destPath);
  return destPath;
}

Use rn-fetch-blob for android to convert the path first as the URI you get is temporary in the case of android and can't be found in the directory,

const res = await RNFetchBlob.fs.stat(SOURCE_URI);
src = "file://" + res.path;

ProcessingManager.press(src, options)
    .then(data => {
        console.log(data);
        this.setState({ base64String: data });
    })
    .catch(console.warn);

This will resolve the path issue.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745281405a4620297.html

相关推荐

  • javascript - How to compress a video in React Native - Stack Overflow

    Tried using react-native-video-processing by Shahen:Below is the code:pressVideo(source) {const options

    4小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信