react-native-compressor icon indicating copy to clipboard operation
react-native-compressor copied to clipboard

Compressor no longer compress video, always returning original video size or corrupt path

Open Franklyn-luupli opened this issue 4 months ago • 4 comments

Current behavior

it doesn't compress video at all, Noticed this week when user started complaining

Expected behavior

it should compresses video properly as it was then

Platform

  • [X] Android
  • [X] iOS Both Android and IOS

React Native Version

0.73.6

React Native Compressor Version

latest (1.12.0 & 1.11.0), i tested on both

Reproducible Steps And Demo

React Native Info

System: OS: macOS 15.6 CPU: (8) arm64 Apple M1 Memory: 146.17 MB / 8.00 GB Shell: version: "5.9" path: /bin/zsh Binaries: Node: version: 18.19.1 path: /opt/homebrew/opt/node@18/bin/node Yarn: version: 1.22.22 path: /opt/homebrew/opt/node@18/bin/yarn npm: version: 7.24.2 path: ~/Desktop/companys-project/react-native/luupli/node_modules/.bin/npm Watchman: version: 2024.01.22.00 path: /opt/homebrew/bin/watchman Managers: CocoaPods: version: 1.15.2 path: /Users/mac/.rvm/gems/ruby-2.7.4/bin/pod SDKs: iOS SDK: Platforms: - DriverKit 24.2 - iOS 18.2 - macOS 15.2 - tvOS 18.2 - visionOS 2.2 - watchOS 11.2 Android SDK: API Levels: - "28" - "29" - "30" - "31" - "33" - "33" - "34" - "35" Build Tools: - 29.0.0 - 29.0.1 - 29.0.2 - 29.0.3 - 30.0.0 - 30.0.1 - 30.0.2 - 30.0.3 - 31.0.0 - 33.0.0 - 33.0.1 - 33.0.2 - 33.0.3 - 34.0.0 - 34.0.0 - 35.0.0 - 35.0.0 System Images: - android-30 | Google Play ARM 64 v8a - android-33 | Google Play ARM 64 v8a Android NDK: Not Found IDEs: Android Studio: 2024.2 AI-242.23726.103.2422.12816248 Xcode: version: 16.2/16C5032a path: /usr/bin/xcodebuild Languages: Java: version: 17.0.9 path: /usr/bin/javac Ruby: version: 2.7.4 path: /Users/mac/.rvm/rubies/ruby-2.7.4/bin/ruby npmPackages: "@react-native-community/cli": Not Found react: installed: 18.2.0 wanted: 18.2.0 react-native: installed: 0.73.6 wanted: 0.73.6 react-native-macos: Not Found npmGlobalPackages: "react-native": Not Found Android: hermesEnabled: true newArchEnabled: false iOS: hermesEnabled: true newArchEnabled: false

Franklyn-luupli avatar Aug 12 '25 14:08 Franklyn-luupli

Hello! I am experiencing the same issue. Sometimes it compresses the video, sometimes not, I have a simillar configuration to @Franklyn-luupli. Did you manage to figure out why?

melendus avatar Aug 14 '25 10:08 melendus

@melendus This is my config currently work fine on production, after a white i was getting report that video no compress

const videoCompress = async (
    path: string,
    height: number | undefined = 1280,
    width: number | undefined = 720,
  ) => {
    // Validate input file
    const fileExists = await RNFS.exists(path);
    if (!fileExists) throw new Error('Video file does not exist');
    const stats = await RNFS.stat(path);
    if (Number(stats.size) <= 0) throw new Error('Video file is empty');
  
    const brand = (await DeviceInfo.getBrand()).toLowerCase();
    const isPortrait = height >= width;
  
    // Base maxSize suggestion by brand
    let suggestedMaxSize = isPortrait ? 1280 : 720;
    if (brand.includes('samsung')) {
      suggestedMaxSize = isPortrait ? 1280 : 720;
    } else if (brand.includes('huawei')) {
      suggestedMaxSize = isPortrait ? 960 : 720;
    }
  
    // Allowed min & max
    const minAllowed = isPortrait ? 720 : 480;
    const maxAllowed = brand.includes('samsung')
      ? isPortrait
        ? 1920
        : 1280
      : brand.includes('huawei')
      ? isPortrait
        ? 1280
        : 960
      : isPortrait
      ? 1920
      : 1280;
  
    // Clamp maxSize between minAllowed and maxAllowed
    const maxSize = Math.max(minAllowed, Math.min(suggestedMaxSize, maxAllowed));
    await clearCache();
    const compressedPath = await Video.compress(
      path,
      {
        compressionMethod: 'manual',
        maxSize,
        bitrate: isPortrait ? 3_000_000 : 2_500_000, // Keep at least 1 Mbps
        minimumFileSizeForCompress: 5_000_000, // 5 MB threshold
      },
      progress => {
        logThis('Video compress progress', progress);
      },
    );
  
    logThis('compressedPath...', compressedPath, path);
  
    // Validate output file
    const compressedExists = await RNFS.exists(compressedPath);
    if (!compressedExists) throw new Error('Compression failed');
    const compressedStats = await RNFS.stat(compressedPath);
    if (Number(compressedStats.size) < 50000) {
      // <50 KB is suspicious
      throw new Error('Compressed file too small (possible corruption)');
    }
  
    return compressedPath;
  };

frankelly001 avatar Aug 19 '25 12:08 frankelly001

+1, no compression at all with the configs example from the docs

Santhosh-Umapathi avatar Sep 26 '25 19:09 Santhosh-Umapathi

On my end, it does compress the video, but ONLY if I use "compressionMethod" => auto. as soon as I try with manual, it just returns immediately but an empty file uncompressed.

pierroo avatar Sep 29 '25 15:09 pierroo