capacitor-native-video-compressor 0.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,7 @@
1
1
  package com.atomic.videocompressor;
2
2
 
3
+ import android.util.Log;
4
+
3
5
  import android.net.Uri;
4
6
  import java.util.Collections;
5
7
  import com.abedelazizshe.lightcompressorlibrary.CompressionListener;
@@ -46,21 +48,30 @@ public class NativeVideoCompressorPlugin extends Plugin {
46
48
 
47
49
  // Đọc quality từ Javascript (Mặc định là MEDIUM)
48
50
  String qualityString = call.getString("quality", "MEDIUM");
51
+
49
52
  VideoQuality videoQuality = VideoQuality.MEDIUM;
50
53
  if (qualityString != null) {
51
- try {
52
- videoQuality = VideoQuality.valueOf(qualityString);
53
- } catch (IllegalArgumentException e) {
54
- videoQuality = VideoQuality.MEDIUM;
54
+ if (qualityString.equals("360P")) {
55
+ videoQuality = VideoQuality.LOW; // Map 360p to LOW quality on Android
56
+ } else if (qualityString.equals("LOW")) {
57
+ videoQuality = VideoQuality.VERY_LOW; // Adjusting others dynamically if needed
58
+ } else {
59
+ try {
60
+ videoQuality = VideoQuality.valueOf(qualityString);
61
+ } catch (IllegalArgumentException e) {
62
+ videoQuality = VideoQuality.MEDIUM;
63
+ }
55
64
  }
56
65
  }
57
66
 
67
+ Log.d("NativeVideoCompressor", "====== VIDEO COMPRESSION QUALITY RECEIVED: " + qualityString + "+ video quality: " + videoQuality + " ======");
68
+
58
69
  // 2. Cấu hình thông số nén (Dành riêng cho LightCompressor 1.3.2)
59
70
  // Lưu ý: Java phải truyền đủ 9 tham số do thư viện gốc viết bằng Kotlin
60
71
  Configuration configuration = new Configuration(
61
72
  videoQuality, // Chất lượng nén
62
- false, // isMinBitrateCheckEnabled
63
- null, // videoBitrateInMbps
73
+ false, // tắt tính năng giới hạn Bitrate tối thiểu của file gốc
74
+ null, // videoBitrateInMbps (Ép buộc giá trị Bitrate để đảm bảo file luôn nhẹ đi)
64
75
  false, // disableAudio
65
76
  false, // keepOriginalResolution
66
77
  null, // videoWidth
@@ -28,10 +28,33 @@ public class NativeVideoCompressorPlugin: CAPPlugin, CAPBridgedPlugin {
28
28
  // Tạo file đầu ra lưu ở thư mục Temp
29
29
  let outputURL = FileManager.default.temporaryDirectory.appendingPathComponent("compressed_\(UUID().uuidString).mp4")
30
30
 
31
+ // Lấy thông số chất lượng truyền từ giao diện (Mặc định là MEDIUM nếu không có)
32
+ let qualityStr = call.getString("quality") ?? "MEDIUM"
33
+ var presetName: String
34
+
35
+ print("====== VIDEO COMPRESSION QUALITY RECEIVED: \(qualityStr) ======")
36
+
37
+ switch qualityStr {
38
+ case "VERY_HIGH":
39
+ presetName = AVAssetExportPresetHighestQuality
40
+ case "HIGH":
41
+ presetName = AVAssetExportPreset1280x720 // 720p cho mức High để nhận thấy sự giảm dung lượng rõ rệt
42
+ case "MEDIUM":
43
+ presetName = AVAssetExportPreset960x540 // 540p cho mức Medium
44
+ case "LOW":
45
+ presetName = AVAssetExportPreset640x480 // 480p cho mức Low
46
+ case "360P" :
47
+ presetName = AVAssetExportPresetMediumQuality // 360p cho mức
48
+ case "VERY_LOW":
49
+ presetName = AVAssetExportPresetLowQuality // 124 cho mức Very Low
50
+ default:
51
+ presetName = AVAssetExportPreset960x540
52
+ }
53
+
31
54
  let asset = AVAsset(url: videoURL)
32
55
 
33
- // 3. Khởi tạo bộ nén phần cứng (Chọn chất lượng MediumQuality hoặc 1280x720)
34
- guard let exportSession = AVAssetExportSession(asset: asset, presetName: AVAssetExportPresetMediumQuality) else {
56
+ // 3. Khởi tạo bộ nén phần cứng với preset tương ứng
57
+ guard let exportSession = AVAssetExportSession(asset: asset, presetName: presetName) else {
35
58
  call.reject("Không thể khởi tạo bộ nén iOS")
36
59
  return
37
60
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-native-video-compressor",
3
- "version": "0.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Native video compressor using LightCompressor and AVFoundation",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",