react-native-compressor 1.17.0 → 1.18.1
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.
- package/android/src/main/java/com/reactnativecompressor/Utils/Utils.kt +2 -2
- package/android/src/main/java/com/reactnativecompressor/Video/AutoVideoCompression.kt +1 -0
- package/android/src/main/java/com/reactnativecompressor/Video/VideoCompressor/VideoCompressorClass.kt +6 -0
- package/android/src/main/java/com/reactnativecompressor/Video/VideoCompressor/compressor/Compressor.kt +2 -1
- package/android/src/main/java/com/reactnativecompressor/Video/VideoCompressorHelper.kt +3 -0
- package/ios/Video/NextLevelSessionExporter.swift +7 -2
- package/ios/Video/VideoMain.swift +68 -63
- package/lib/commonjs/Video/index.js +3 -0
- package/lib/commonjs/Video/index.js.map +1 -1
- package/lib/module/Video/index.js +3 -0
- package/lib/module/Video/index.js.map +1 -1
- package/lib/typescript/src/Video/index.d.ts +5 -0
- package/lib/typescript/src/Video/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/Video/index.tsx +9 -0
|
@@ -29,12 +29,12 @@ object Utils {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
@JvmStatic
|
|
32
|
-
fun compressVideo(srcPath: String, destinationPath: String, resultWidth: Int, resultHeight: Int, videoBitRate: Float, frameRate: Int, uuid: String,progressDivider:Int, promise: Promise, reactContext: ReactApplicationContext) {
|
|
32
|
+
fun compressVideo(srcPath: String, destinationPath: String, resultWidth: Int, resultHeight: Int, videoBitRate: Float, frameRate: Int, uuid: String,progressDivider:Int, stripAudio: Boolean = false, promise: Promise, reactContext: ReactApplicationContext) {
|
|
33
33
|
val currentVideoCompression = intArrayOf(0)
|
|
34
34
|
val videoCompressorClass: VideoCompressorClass? = VideoCompressorClass(reactContext);
|
|
35
35
|
compressorExports[uuid] = videoCompressorClass
|
|
36
36
|
videoCompressorClass?.start(
|
|
37
|
-
srcPath, destinationPath, resultWidth, resultHeight, videoBitRate.toInt(), frameRate,
|
|
37
|
+
srcPath, destinationPath, resultWidth, resultHeight, videoBitRate.toInt(), frameRate, stripAudio,
|
|
38
38
|
listener = object : CompressionListener {
|
|
39
39
|
override fun onProgress(index: Int, percent: Float) {
|
|
40
40
|
if (percent <= 100) {
|
|
@@ -25,6 +25,7 @@ class VideoCompressorClass(private val context: ReactApplicationContext) {
|
|
|
25
25
|
outputHeight: Int,
|
|
26
26
|
bitrate: Int,
|
|
27
27
|
frameRate: Int,
|
|
28
|
+
stripAudio: Boolean = false,
|
|
28
29
|
listener: CompressionListener,
|
|
29
30
|
) {
|
|
30
31
|
val uris = mutableListOf<Uri>()
|
|
@@ -38,6 +39,7 @@ class VideoCompressorClass(private val context: ReactApplicationContext) {
|
|
|
38
39
|
outputHeight,
|
|
39
40
|
bitrate,
|
|
40
41
|
frameRate,
|
|
42
|
+
stripAudio,
|
|
41
43
|
listener,
|
|
42
44
|
destPath
|
|
43
45
|
)
|
|
@@ -55,6 +57,7 @@ class VideoCompressorClass(private val context: ReactApplicationContext) {
|
|
|
55
57
|
outputHeight: Int,
|
|
56
58
|
bitrate: Int,
|
|
57
59
|
frameRate: Int,
|
|
60
|
+
stripAudio: Boolean,
|
|
58
61
|
listener: CompressionListener,
|
|
59
62
|
destPath: String
|
|
60
63
|
) {
|
|
@@ -78,6 +81,7 @@ class VideoCompressorClass(private val context: ReactApplicationContext) {
|
|
|
78
81
|
outputHeight,
|
|
79
82
|
bitrate,
|
|
80
83
|
frameRate,
|
|
84
|
+
stripAudio,
|
|
81
85
|
listener,
|
|
82
86
|
)
|
|
83
87
|
|
|
@@ -101,6 +105,7 @@ class VideoCompressorClass(private val context: ReactApplicationContext) {
|
|
|
101
105
|
outputHeight: Int,
|
|
102
106
|
bitrate: Int,
|
|
103
107
|
frameRate: Int,
|
|
108
|
+
disableAudio: Boolean = false,
|
|
104
109
|
listener: CompressionListener,
|
|
105
110
|
): Result = withContext(Dispatchers.Default) {
|
|
106
111
|
return@withContext compressVideo(
|
|
@@ -113,6 +118,7 @@ class VideoCompressorClass(private val context: ReactApplicationContext) {
|
|
|
113
118
|
outputHeight,
|
|
114
119
|
bitrate,
|
|
115
120
|
frameRate,
|
|
121
|
+
disableAudio,
|
|
116
122
|
object : CompressionProgressListener {
|
|
117
123
|
override fun onProgressChanged(index: Int, percent: Float) {
|
|
118
124
|
listener.onProgress(index, percent)
|
|
@@ -55,6 +55,7 @@ object Compressor {
|
|
|
55
55
|
outputHeight: Int,
|
|
56
56
|
outputBitrate: Int,
|
|
57
57
|
outputFrameRate: Int,
|
|
58
|
+
disableAudio: Boolean = false,
|
|
58
59
|
listener: CompressionProgressListener,
|
|
59
60
|
): Result = withContext(Dispatchers.Default) {
|
|
60
61
|
|
|
@@ -126,7 +127,7 @@ object Compressor {
|
|
|
126
127
|
newBitrate,
|
|
127
128
|
outputFrameRate,
|
|
128
129
|
streamableFile,
|
|
129
|
-
|
|
130
|
+
disableAudio,
|
|
130
131
|
extractor,
|
|
131
132
|
listener,
|
|
132
133
|
duration,
|
|
@@ -27,6 +27,7 @@ class VideoCompressorHelper {
|
|
|
27
27
|
var maxSize = 640.0f
|
|
28
28
|
var progressDivider: Int? = 0
|
|
29
29
|
var minimumFileSizeForCompress = 0.0f
|
|
30
|
+
var stripAudio = false
|
|
30
31
|
|
|
31
32
|
companion object {
|
|
32
33
|
private var _reactContext: ReactApplicationContext? = null
|
|
@@ -84,6 +85,7 @@ class VideoCompressorHelper {
|
|
|
84
85
|
"minimumFileSizeForCompress" -> options.minimumFileSizeForCompress = map.getDouble(key).toFloat()
|
|
85
86
|
"bitrate" -> options.bitrate = map.getDouble(key).toFloat()
|
|
86
87
|
"progressDivider" -> options.progressDivider = map.getInt(key)
|
|
88
|
+
"stripAudio" -> options.stripAudio = map.getBoolean(key)
|
|
87
89
|
}
|
|
88
90
|
}
|
|
89
91
|
return options
|
|
@@ -130,6 +132,7 @@ class VideoCompressorHelper {
|
|
|
130
132
|
profile.frameRate,
|
|
131
133
|
options.uuid!!,
|
|
132
134
|
options.progressDivider!!,
|
|
135
|
+
options.stripAudio,
|
|
133
136
|
promise,
|
|
134
137
|
reactContext,
|
|
135
138
|
)
|
|
@@ -70,6 +70,9 @@ open class NextLevelSessionExporter: NSObject {
|
|
|
70
70
|
|
|
71
71
|
/// Audio output configuration dictionary, using keys defined in `<AVFoundation/AVAudioSettings.h>`
|
|
72
72
|
public var audioOutputConfiguration: [String : Any]?
|
|
73
|
+
|
|
74
|
+
/// When true, audio tracks are excluded from the export entirely.
|
|
75
|
+
public var stripAudio: Bool = false
|
|
73
76
|
|
|
74
77
|
/// Export session status state.
|
|
75
78
|
public var status: AVAssetExportSession.Status {
|
|
@@ -247,8 +250,10 @@ extension NextLevelSessionExporter {
|
|
|
247
250
|
}
|
|
248
251
|
|
|
249
252
|
self.setupVideoOutput(withAsset: asset)
|
|
250
|
-
self.
|
|
251
|
-
|
|
253
|
+
if !self.stripAudio {
|
|
254
|
+
self.setupAudioOutput(withAsset: asset)
|
|
255
|
+
self.setupAudioInput()
|
|
256
|
+
}
|
|
252
257
|
|
|
253
258
|
// export
|
|
254
259
|
|
|
@@ -258,6 +258,7 @@ class VideoCompressor {
|
|
|
258
258
|
let maxSize = (options["maxSize"] as? NSNumber)?.floatValue ?? 640
|
|
259
259
|
let uuid:String = options["uuid"] as! String
|
|
260
260
|
let progressDivider=options["progressDivider"] as? Int ?? 0
|
|
261
|
+
let stripAudio=options["stripAudio"] as? Bool ?? false
|
|
261
262
|
|
|
262
263
|
let asset = AVAsset(url: url)
|
|
263
264
|
guard let track = getVideoTrack(asset: asset) else {
|
|
@@ -267,7 +268,7 @@ class VideoCompressor {
|
|
|
267
268
|
}
|
|
268
269
|
let profile = createCompressionProfile(track: track, maxSize: CGFloat(maxSize), requestedBitrate: nil)
|
|
269
270
|
|
|
270
|
-
exportVideoHelper(url: url, asset: asset, bitRate: profile.bitrate, frameRate: profile.frameRate, resultWidth: profile.width, resultHeight: profile.height,uuid: uuid,progressDivider: progressDivider) { progress in
|
|
271
|
+
exportVideoHelper(url: url, asset: asset, bitRate: profile.bitrate, frameRate: profile.frameRate, resultWidth: profile.width, resultHeight: profile.height,uuid: uuid,progressDivider: progressDivider, stripAudio: stripAudio) { progress in
|
|
271
272
|
onProgress(progress)
|
|
272
273
|
} onCompletion: { outputURL in
|
|
273
274
|
onCompletion(outputURL)
|
|
@@ -280,6 +281,7 @@ class VideoCompressor {
|
|
|
280
281
|
let uuid:String = options["uuid"] as! String
|
|
281
282
|
let bitRate = (options["bitrate"] as? NSNumber)?.intValue
|
|
282
283
|
let progressDivider=options["progressDivider"] as? Int ?? 0
|
|
284
|
+
let stripAudio=options["stripAudio"] as? Bool ?? false
|
|
283
285
|
let asset = AVAsset(url: url)
|
|
284
286
|
guard let track = getVideoTrack(asset: asset) else {
|
|
285
287
|
let error = CompressionError(message: "Invalid video URL, no track found")
|
|
@@ -289,7 +291,7 @@ class VideoCompressor {
|
|
|
289
291
|
let maxSize = (options["maxSize"] as? NSNumber)?.floatValue ?? Float(1920)
|
|
290
292
|
let profile = createCompressionProfile(track: track, maxSize: CGFloat(maxSize), requestedBitrate: bitRate)
|
|
291
293
|
|
|
292
|
-
exportVideoHelper(url: url, asset: asset, bitRate: profile.bitrate, frameRate: profile.frameRate, resultWidth: profile.width, resultHeight: profile.height,uuid: uuid,progressDivider: progressDivider) { progress in
|
|
294
|
+
exportVideoHelper(url: url, asset: asset, bitRate: profile.bitrate, frameRate: profile.frameRate, resultWidth: profile.width, resultHeight: profile.height,uuid: uuid,progressDivider: progressDivider, stripAudio: stripAudio) { progress in
|
|
293
295
|
onProgress(progress)
|
|
294
296
|
} onCompletion: { outputURL in
|
|
295
297
|
onCompletion(outputURL)
|
|
@@ -298,7 +300,7 @@ class VideoCompressor {
|
|
|
298
300
|
}
|
|
299
301
|
}
|
|
300
302
|
|
|
301
|
-
func exportVideoHelper(url: URL,asset: AVAsset, bitRate: Int, frameRate: Int, resultWidth:Int,resultHeight:Int,uuid:String,progressDivider: Int, onProgress: @escaping (Float) -> Void, onCompletion: @escaping (URL) -> Void, onFailure: @escaping (Error) -> Void){
|
|
303
|
+
func exportVideoHelper(url: URL,asset: AVAsset, bitRate: Int, frameRate: Int, resultWidth:Int,resultHeight:Int,uuid:String,progressDivider: Int, stripAudio: Bool = false, onProgress: @escaping (Float) -> Void, onCompletion: @escaping (URL) -> Void, onFailure: @escaping (Error) -> Void){
|
|
302
304
|
var currentVideoCompression:Int=0
|
|
303
305
|
|
|
304
306
|
var tmpURL = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
|
|
@@ -324,12 +326,15 @@ class VideoCompressor {
|
|
|
324
326
|
AVVideoScalingModeKey: AVVideoScalingModeResizeAspect,
|
|
325
327
|
AVVideoCompressionPropertiesKey: compressionDict
|
|
326
328
|
]
|
|
327
|
-
exporter.
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
329
|
+
exporter.stripAudio = stripAudio
|
|
330
|
+
if !stripAudio {
|
|
331
|
+
exporter.audioOutputConfiguration = [
|
|
332
|
+
AVFormatIDKey: kAudioFormatMPEG4AAC,
|
|
333
|
+
AVEncoderBitRateKey: NSNumber(integerLiteral: 128000),
|
|
334
|
+
AVNumberOfChannelsKey: NSNumber(integerLiteral: 2),
|
|
335
|
+
AVSampleRateKey: NSNumber(value: Float(44100))
|
|
336
|
+
]
|
|
337
|
+
}
|
|
333
338
|
|
|
334
339
|
compressorExports[uuid] = exporter
|
|
335
340
|
exporter.export(progressHandler: { (progress) in
|
|
@@ -342,18 +347,22 @@ class VideoCompressor {
|
|
|
342
347
|
}, completionHandler: { result in
|
|
343
348
|
currentVideoCompression=0;
|
|
344
349
|
self.compressorExports[uuid] = nil
|
|
345
|
-
switch
|
|
346
|
-
case .
|
|
347
|
-
|
|
350
|
+
switch result {
|
|
351
|
+
case .success:
|
|
352
|
+
if let outputURL = exporter.outputURL {
|
|
353
|
+
onCompletion(outputURL)
|
|
354
|
+
} else {
|
|
355
|
+
onFailure(CompressionError(message: "Compression succeeded but output URL is unavailable"))
|
|
356
|
+
}
|
|
348
357
|
break
|
|
349
|
-
case .
|
|
350
|
-
|
|
358
|
+
case .failure(let error):
|
|
359
|
+
if let nexterError = error as? NextLevelSessionExporterError, case .cancelled = nexterError {
|
|
360
|
+
onFailure(CompressionError(message: "Compression has cancelled"))
|
|
361
|
+
} else {
|
|
351
362
|
onFailure(error)
|
|
352
|
-
|
|
353
|
-
default:
|
|
354
|
-
onFailure(exporter.error ?? CompressionError(message: "Compression failed"))
|
|
363
|
+
}
|
|
355
364
|
break
|
|
356
|
-
|
|
365
|
+
}
|
|
357
366
|
})
|
|
358
367
|
}
|
|
359
368
|
|
|
@@ -368,58 +377,54 @@ class VideoCompressor {
|
|
|
368
377
|
|
|
369
378
|
|
|
370
379
|
func getVideoMetaData(_ filePath: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
if absoluteImagePath.hasPrefix("file://") {
|
|
374
|
-
|
|
375
|
-
let absoluteImagePath = URL(string: absoluteImagePath)!.path
|
|
376
|
-
let fileManager = FileManager.default
|
|
377
|
-
var isDir: ObjCBool = false
|
|
378
|
-
|
|
379
|
-
if !fileManager.fileExists(atPath: absoluteImagePath, isDirectory: &isDir) || isDir.boolValue {
|
|
380
|
-
let err = NSError(domain: "file not found", code: -15, userInfo: nil)
|
|
381
|
-
reject(String(err.code), err.localizedDescription, err)
|
|
382
|
-
return
|
|
383
|
-
}
|
|
380
|
+
VideoCompressor.getAbsoluteVideoPath(filePath, options: [:]) { absoluteImagePath in
|
|
381
|
+
if absoluteImagePath.hasPrefix("file://") {
|
|
384
382
|
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
var result: [String: Any] = [:]
|
|
390
|
-
let assetOptions: [String: Any] = [AVURLAssetPreferPreciseDurationAndTimingKey: true]
|
|
391
|
-
let asset = AVURLAsset(url: URL(fileURLWithPath: absoluteImagePath), options: assetOptions)
|
|
392
|
-
if let avAsset = asset.tracks(withMediaType: .video).first {
|
|
393
|
-
let size = avAsset.naturalSize
|
|
394
|
-
let _extension = (absoluteImagePath as NSString).pathExtension
|
|
395
|
-
let time = asset.duration
|
|
396
|
-
let seconds = Double(time.value) / Double(time.timescale)
|
|
397
|
-
|
|
398
|
-
result["width"] = size.width
|
|
399
|
-
result["height"] = size.height
|
|
400
|
-
result["extension"] = _extension
|
|
401
|
-
result["size"] = fileSizeString
|
|
402
|
-
result["duration"] = seconds
|
|
403
|
-
|
|
404
|
-
var commonMetadata: [AVMetadataItem] = []
|
|
405
|
-
for key in self.metadatas {
|
|
406
|
-
let items = AVMetadataItem.metadataItems(from: asset.commonMetadata, withKey: key, keySpace: AVMetadataKeySpace.common)
|
|
407
|
-
commonMetadata.append(contentsOf: items)
|
|
408
|
-
}
|
|
383
|
+
let absoluteImagePath = URL(string: absoluteImagePath)!.path
|
|
384
|
+
let fileManager = FileManager.default
|
|
385
|
+
var isDir: ObjCBool = false
|
|
409
386
|
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
387
|
+
if !fileManager.fileExists(atPath: absoluteImagePath, isDirectory: &isDir) || isDir.boolValue {
|
|
388
|
+
let err = NSError(domain: "file not found", code: -15, userInfo: nil)
|
|
389
|
+
reject(String(err.code), err.localizedDescription, err)
|
|
390
|
+
return
|
|
391
|
+
}
|
|
415
392
|
|
|
416
|
-
|
|
393
|
+
let attrs = try? fileManager.attributesOfItem(atPath: absoluteImagePath)
|
|
394
|
+
if let fileSize = attrs?[FileAttributeKey.size] as? UInt64 {
|
|
395
|
+
let fileSizeString = fileSize
|
|
396
|
+
|
|
397
|
+
var result: [String: Any] = [:]
|
|
398
|
+
let assetOptions: [String: Any] = [AVURLAssetPreferPreciseDurationAndTimingKey: true]
|
|
399
|
+
let asset = AVURLAsset(url: URL(fileURLWithPath: absoluteImagePath), options: assetOptions)
|
|
400
|
+
if let avAsset = asset.tracks(withMediaType: .video).first {
|
|
401
|
+
let size = avAsset.naturalSize
|
|
402
|
+
let _extension = (absoluteImagePath as NSString).pathExtension
|
|
403
|
+
let time = asset.duration
|
|
404
|
+
let seconds = Double(time.value) / Double(time.timescale)
|
|
405
|
+
|
|
406
|
+
result["width"] = size.width
|
|
407
|
+
result["height"] = size.height
|
|
408
|
+
result["extension"] = _extension
|
|
409
|
+
result["size"] = fileSizeString
|
|
410
|
+
result["duration"] = seconds
|
|
411
|
+
|
|
412
|
+
var commonMetadata: [AVMetadataItem] = []
|
|
413
|
+
for key in self.metadatas {
|
|
414
|
+
let items = AVMetadataItem.metadataItems(from: asset.commonMetadata, withKey: key, keySpace: AVMetadataKeySpace.common)
|
|
415
|
+
commonMetadata.append(contentsOf: items)
|
|
417
416
|
}
|
|
417
|
+
|
|
418
|
+
for item in commonMetadata {
|
|
419
|
+
if let value = item.value {
|
|
420
|
+
result[item.commonKey!.rawValue] = value
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
resolve(result)
|
|
418
425
|
}
|
|
419
426
|
}
|
|
420
427
|
}
|
|
421
|
-
} catch {
|
|
422
|
-
reject(error.localizedDescription, error.localizedDescription, nil)
|
|
423
428
|
}
|
|
424
429
|
}
|
|
425
430
|
|
|
@@ -52,6 +52,9 @@ const Video = {
|
|
|
52
52
|
if (options?.minimumFileSizeForCompress !== undefined) {
|
|
53
53
|
modifiedOptions.minimumFileSizeForCompress = options?.minimumFileSizeForCompress;
|
|
54
54
|
}
|
|
55
|
+
if (options?.stripAudio) {
|
|
56
|
+
modifiedOptions.stripAudio = options.stripAudio;
|
|
57
|
+
}
|
|
55
58
|
if (options?.getCancellationId) {
|
|
56
59
|
options?.getCancellationId(uuid);
|
|
57
60
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_Main","_utils","VideoCompressEventEmitter","NativeEventEmitter","Compressor","NativeVideoCompressor","cancelCompression","cancellationId","exports","Video","compress","fileUrl","options","onProgress","uuid","uuidv4","subscription","subscription2","addListener","event","data","progress","downloadProgress","modifiedOptions","progressDivider","bitrate","compressionMethod","maxSize","minimumFileSizeForCompress","undefined","getCancellationId","result","remove","activateBackgroundTask","onExpired","deactivateBackgroundTask","removeAllListeners","_default","default"],"sourceRoot":"../../../src","sources":["Video/index.tsx"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_Main","_utils","VideoCompressEventEmitter","NativeEventEmitter","Compressor","NativeVideoCompressor","cancelCompression","cancellationId","exports","Video","compress","fileUrl","options","onProgress","uuid","uuidv4","subscription","subscription2","addListener","event","data","progress","downloadProgress","modifiedOptions","progressDivider","bitrate","compressionMethod","maxSize","minimumFileSizeForCompress","undefined","stripAudio","getCancellationId","result","remove","activateBackgroundTask","onExpired","deactivateBackgroundTask","removeAllListeners","_default","default"],"sourceRoot":"../../../src","sources":["Video/index.tsx"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AA4BA,MAAMG,yBAAyB,GAAG,IAAIC,+BAAkB,CAACC,gBAAU,CAAC;AAEpE,MAAMC,qBAAqB,GAAGD,gBAAU;AAEjC,MAAME,iBAAiB,GAAIC,cAAsB,IAAK;EAC3D,OAAOF,qBAAqB,CAACC,iBAAiB,CAACC,cAAc,CAAC;AAChE,CAAC;AAACC,OAAA,CAAAF,iBAAA,GAAAA,iBAAA;AAEF,MAAMG,KAA0B,GAAG;EACjCC,QAAQ,EAAE,MAAAA,CAAOC,OAAe,EAAEC,OAA+B,EAAEC,UAAuC,KAAK;IAC7G,MAAMC,IAAI,GAAG,IAAAC,aAAM,EAAC,CAAC;IACrB,IAAIC,YAAqC;IACzC,IAA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EkB,UAAU,EAAE;QACvBP,eAAe,CAACO,UAAU,GAAGlB,OAAO,CAACkB,UAAU;MACjD;MACA,IAAIlB,OAAO,EAAEmB,iBAAiB,EAAE;QAC9BnB,OAAO,EAAEmB,iBAAiB,CAACjB,IAAI,CAAC;MAClC;MAEA,MAAMkB,MAAM,GAAG,MAAM3B,qBAAqB,CAACK,QAAQ,CAACC,OAAO,EAAEY,eAAe,CAAC;MAC7E,OAAOS,MAAM;IACf,CAAC,SAAS;MACR;MACA,IAAIhB,YAAY,EAAE;QAChBA,YAAY,CAACiB,MAAM,CAAC,CAAC;MACvB;MACA;MACA,IAAIhB,aAAa,EAAE;QACjBA,aAAa,CAACgB,MAAM,CAAC,CAAC;MACxB;IACF;EACF,CAAC;EACD3B,iBAAiB;EACjB4B,sBAAsBA,CAACC,SAAU,EAAE;IACjC,IAAIA,SAAS,EAAE;MACb,MAAMnB,YAAqC,GAAGd,yBAAyB,CAACgB,WAAW,CAAC,uBAAuB,EAAGC,KAAU,IAAK;QAC3HgB,SAAS,CAAChB,KAAK,CAAC;QAChB,IAAIH,YAAY,EAAE;UAChBA,YAAY,CAACiB,MAAM,CAAC,CAAC;QACvB;MACF,CAAC,CAAC;IACJ;IACA,OAAO5B,qBAAqB,CAAC6B,sBAAsB,CAAC,CAAC,CAAC,CAAC;EACzD,CAAC;EACDE,wBAAwBA,CAAA,EAAG;IACzBlC,yBAAyB,CAACmC,kBAAkB,CAAC,uBAAuB,CAAC;IACrE,OAAOhC,qBAAqB,CAAC+B,wBAAwB,CAAC,CAAC,CAAC,CAAC;EAC3D;AACF,CAAwB;AAAC,IAAAE,QAAA,GAAA9B,OAAA,CAAA+B,OAAA,GAEV9B,KAAK","ignoreList":[]}
|
|
@@ -47,6 +47,9 @@ const Video = {
|
|
|
47
47
|
if (options?.minimumFileSizeForCompress !== undefined) {
|
|
48
48
|
modifiedOptions.minimumFileSizeForCompress = options?.minimumFileSizeForCompress;
|
|
49
49
|
}
|
|
50
|
+
if (options?.stripAudio) {
|
|
51
|
+
modifiedOptions.stripAudio = options.stripAudio;
|
|
52
|
+
}
|
|
50
53
|
if (options?.getCancellationId) {
|
|
51
54
|
options?.getCancellationId(uuid);
|
|
52
55
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NativeEventEmitter","Compressor","uuidv4","VideoCompressEventEmitter","NativeVideoCompressor","cancelCompression","cancellationId","Video","compress","fileUrl","options","onProgress","uuid","subscription","subscription2","addListener","event","data","progress","downloadProgress","modifiedOptions","progressDivider","bitrate","compressionMethod","maxSize","minimumFileSizeForCompress","undefined","getCancellationId","result","remove","activateBackgroundTask","onExpired","deactivateBackgroundTask","removeAllListeners"],"sourceRoot":"../../../src","sources":["Video/index.tsx"],"mappings":";;AAAA,SAASA,kBAAkB,QAAQ,cAAc;AAEjD,SAASC,UAAU,QAAQ,SAAS;AACpC,SAASC,MAAM,QAAQ,UAAU;
|
|
1
|
+
{"version":3,"names":["NativeEventEmitter","Compressor","uuidv4","VideoCompressEventEmitter","NativeVideoCompressor","cancelCompression","cancellationId","Video","compress","fileUrl","options","onProgress","uuid","subscription","subscription2","addListener","event","data","progress","downloadProgress","modifiedOptions","progressDivider","bitrate","compressionMethod","maxSize","minimumFileSizeForCompress","undefined","stripAudio","getCancellationId","result","remove","activateBackgroundTask","onExpired","deactivateBackgroundTask","removeAllListeners"],"sourceRoot":"../../../src","sources":["Video/index.tsx"],"mappings":";;AAAA,SAASA,kBAAkB,QAAQ,cAAc;AAEjD,SAASC,UAAU,QAAQ,SAAS;AACpC,SAASC,MAAM,QAAQ,UAAU;AA4BjC,MAAMC,yBAAyB,GAAG,IAAIH,kBAAkB,CAACC,UAAU,CAAC;AAEpE,MAAMG,qBAAqB,GAAGH,UAAU;AAExC,OAAO,MAAMI,iBAAiB,GAAIC,cAAsB,IAAK;EAC3D,OAAOF,qBAAqB,CAACC,iBAAiB,CAACC,cAAc,CAAC;AAChE,CAAC;AAED,MAAMC,KAA0B,GAAG;EACjCC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B;MACA,IAAId,OAAO,EAAEe,0BAA0B,KAAKC,SAAS,EAAE;QACrDN,eAAe,CAACK,0BAA0B,GAAGf,OAAO,EAAEe,0BAA0B;MAClF;MACA,IAAIf,OAAO,EAAEiB,UAAU,EAAE;QACvBP,eAAe,CAACO,UAAU,GAAGjB,OAAO,CAACiB,UAAU;MACjD;MACA,IAAIjB,OAAO,EAAEkB,iBAAiB,EAAE;QAC9BlB,OAAO,EAAEkB,iBAAiB,CAAChB,IAAI,CAAC;MAClC;MAEA,MAAMiB,MAAM,GAAG,MAAMzB,qBAAqB,CAACI,QAAQ,CAACC,OAAO,EAAEW,eAAe,CAAC;MAC7E,OAAOS,MAAM;IACf,CAAC,SAAS;MACR;MACA,IAAIhB,YAAY,EAAE;QAChBA,YAAY,CAACiB,MAAM,CAAC,CAAC;MACvB;MACA;MACA,IAAIhB,aAAa,EAAE;QACjBA,aAAa,CAACgB,MAAM,CAAC,CAAC;MACxB;IACF;EACF,CAAC;EACDzB,iBAAiB;EACjB0B,sBAAsBA,CAACC,SAAU,EAAE;IACjC,IAAIA,SAAS,EAAE;MACb,MAAMnB,YAAqC,GAAGV,yBAAyB,CAACY,WAAW,CAAC,uBAAuB,EAAGC,KAAU,IAAK;QAC3HgB,SAAS,CAAChB,KAAK,CAAC;QAChB,IAAIH,YAAY,EAAE;UAChBA,YAAY,CAACiB,MAAM,CAAC,CAAC;QACvB;MACF,CAAC,CAAC;IACJ;IACA,OAAO1B,qBAAqB,CAAC2B,sBAAsB,CAAC,CAAC,CAAC,CAAC;EACzD,CAAC;EACDE,wBAAwBA,CAAA,EAAG;IACzB9B,yBAAyB,CAAC+B,kBAAkB,CAAC,uBAAuB,CAAC;IACrE,OAAO9B,qBAAqB,CAAC6B,wBAAwB,CAAC,CAAC,CAAC,CAAC;EAC3D;AACF,CAAwB;AAExB,eAAe1B,KAAK","ignoreList":[]}
|
|
@@ -10,6 +10,11 @@ type videoCompresssionType = {
|
|
|
10
10
|
* Default:0, we uses it when we use downloadProgress/onProgress
|
|
11
11
|
*/
|
|
12
12
|
progressDivider?: number;
|
|
13
|
+
/***
|
|
14
|
+
* When true, the audio track is removed entirely from the output video.
|
|
15
|
+
* Default: false
|
|
16
|
+
*/
|
|
17
|
+
stripAudio?: boolean;
|
|
13
18
|
};
|
|
14
19
|
export type VideoCompressorType = {
|
|
15
20
|
compress(fileUrl: string, options?: videoCompresssionType, onProgress?: (progress: number) => void): Promise<string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/Video/index.tsx"],"names":[],"mappings":"AAKA,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,QAAQ,CAAC;AAClD,KAAK,qBAAqB,GAAG;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC,0BAA0B,CAAC,EAAE,MAAM,CAAC;IACpC,iBAAiB,CAAC,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,IAAI,CAAC;IACrD,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9C;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/Video/index.tsx"],"names":[],"mappings":"AAKA,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,QAAQ,CAAC;AAClD,KAAK,qBAAqB,GAAG;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC,0BAA0B,CAAC,EAAE,MAAM,CAAC;IACpC,iBAAiB,CAAC,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,IAAI,CAAC;IACrD,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9C;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB,EAAE,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACrH,iBAAiB,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAChD,sBAAsB,CAAC,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IACtE,wBAAwB,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC;CAC1C,CAAC;AAMF,eAAO,MAAM,iBAAiB,GAAI,gBAAgB,MAAM,QAEvD,CAAC;AAEF,QAAA,MAAM,KAAK,EAAE,mBAoFW,CAAC;AAEzB,eAAe,KAAK,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-compressor",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.18.1",
|
|
4
4
|
"description": "Compress Image, Video, and Audio same like Whatsapp & Auto/Manual Compression | Background Upload | Download File | Create Video Thumbnail",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
package/src/Video/index.tsx
CHANGED
|
@@ -15,6 +15,11 @@ type videoCompresssionType = {
|
|
|
15
15
|
* Default:0, we uses it when we use downloadProgress/onProgress
|
|
16
16
|
*/
|
|
17
17
|
progressDivider?: number;
|
|
18
|
+
/***
|
|
19
|
+
* When true, the audio track is removed entirely from the output video.
|
|
20
|
+
* Default: false
|
|
21
|
+
*/
|
|
22
|
+
stripAudio?: boolean;
|
|
18
23
|
};
|
|
19
24
|
|
|
20
25
|
export type VideoCompressorType = {
|
|
@@ -63,6 +68,7 @@ const Video: VideoCompressorType = {
|
|
|
63
68
|
maxSize?: number;
|
|
64
69
|
minimumFileSizeForCompress?: number;
|
|
65
70
|
progressDivider?: number;
|
|
71
|
+
stripAudio?: boolean;
|
|
66
72
|
} = { uuid };
|
|
67
73
|
if (options?.progressDivider) modifiedOptions.progressDivider = options?.progressDivider;
|
|
68
74
|
if (options?.bitrate) modifiedOptions.bitrate = options?.bitrate;
|
|
@@ -79,6 +85,9 @@ const Video: VideoCompressorType = {
|
|
|
79
85
|
if (options?.minimumFileSizeForCompress !== undefined) {
|
|
80
86
|
modifiedOptions.minimumFileSizeForCompress = options?.minimumFileSizeForCompress;
|
|
81
87
|
}
|
|
88
|
+
if (options?.stripAudio) {
|
|
89
|
+
modifiedOptions.stripAudio = options.stripAudio;
|
|
90
|
+
}
|
|
82
91
|
if (options?.getCancellationId) {
|
|
83
92
|
options?.getCancellationId(uuid);
|
|
84
93
|
}
|