I am using the library to compress both videos and images. The compression behaviour is very inconsistent. Same image of size 2.10MB is compressed to 0.2MB sometimes, 1MB sometimes, and no compression at all and same size 2.10MB.
let compressedPath = "";
if (type === "Videos") {
compressedPath = await Video.compress(
attachment.path,
{
compressionMethod: "auto",
minimumFileSizeForCompress: 2,
maxSize: videoMax, //The maximum size can be height in case of portrait video or can be width in case of landscape video
},
progress => {
if (progressCallback) {
progressCallback(progress);
}
},
);
} else if (type === "Images") {
compressedPath = await Image.compress(attachment.path, {
compressionMethod: "auto",
maxWidth: imageMax, //The maximum width boundary used as the main boundary in resizing a landscape image
maxHeight: imageMax, //The maximum height boundary used as the main boundary in resizing a portrait image
quality: imageQuality / 100, //This package takes quality value from 0 to 1
});
I am using the library to compress both videos and images. The compression behaviour is very inconsistent. Same image of size 2.10MB is compressed to 0.2MB sometimes, 1MB sometimes, and no compression at all and same size 2.10MB.
Code snippet.
const imageResolution = JSON.parse(Config.get("IMAGE_RESOLUTION"));
const videoResolution = JSON.parse(Config.get("VIDEO_RESOLUTION"));
const imageQuality = Config.get("IMAGE_QUALITY");
const imageMax = Math.max(
Number(imageResolution.height),
Number(imageResolution.width),
);
const videoMax = Math.max(
Number(videoResolution.height),
Number(videoResolution.width),
);
let compressedPath = ""; if (type === "Videos") { compressedPath = await Video.compress( attachment.path, { compressionMethod: "auto", minimumFileSizeForCompress: 2, maxSize: videoMax, //The maximum size can be height in case of portrait video or can be width in case of landscape video }, progress => { if (progressCallback) { progressCallback(progress); } }, ); } else if (type === "Images") { compressedPath = await Image.compress(attachment.path, { compressionMethod: "auto", maxWidth: imageMax, //The maximum width boundary used as the main boundary in resizing a landscape image maxHeight: imageMax, //The maximum height boundary used as the main boundary in resizing a portrait image quality: imageQuality / 100, //This package takes quality value from 0 to 1 });
Platform
React Native Version: 0.72.6
React Native Compressor Version: 1.8.22