react-native-compressor 1.8.25 → 1.9.0

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.
@@ -111,11 +111,10 @@ dependencies {
111
111
  //noinspection GradleDynamicVersion
112
112
  implementation "com.facebook.react:react-native:+"
113
113
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
114
- implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
115
114
 
116
115
  implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4"
117
116
  implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4"
118
- implementation "com.googlecode.mp4parser:isoparser:1.0.6"
117
+ implementation 'org.mp4parser:isoparser:1.9.56'
119
118
  implementation 'com.github.banketree:AndroidLame-kotlin:v0.0.1'
120
119
  implementation 'javazoom:jlayer:1.0.1'
121
120
  }
@@ -14,9 +14,10 @@ import java.io.FileNotFoundException
14
14
  import java.io.IOException
15
15
  import java.net.HttpURLConnection
16
16
  import java.net.URL
17
+ import java.nio.ByteBuffer
17
18
  import java.util.UUID
18
19
  import java.util.regex.Pattern
19
- import kotlin.Throwable
20
+
20
21
 
21
22
  object Utils {
22
23
  private const val TAG = "react-native-compessor"
@@ -328,4 +329,12 @@ object Utils {
328
329
  -1L
329
330
  }
330
331
  }
332
+
333
+ fun subBuffer(buf: ByteBuffer, start: Int, count: Int = buf.remaining() - start): ByteBuffer {
334
+ val newBuf = buf.duplicate()
335
+ val bytes = ByteArray(count)
336
+ newBuf.position(start)
337
+ newBuf[bytes, 0, bytes.size]
338
+ return ByteBuffer.wrap(bytes)
339
+ }
331
340
  }
@@ -2,8 +2,10 @@ package com.reactnativecompressor.Video.VideoCompressor.video
2
2
 
3
3
  import android.media.MediaCodec
4
4
  import android.media.MediaFormat
5
- import com.coremedia.iso.boxes.*
6
- import com.googlecode.mp4parser.util.Matrix
5
+ import org.mp4parser.Box
6
+ import org.mp4parser.boxes.iso14496.part12.*
7
+
8
+ import org.mp4parser.support.Matrix
7
9
  import java.io.FileOutputStream
8
10
  import java.nio.ByteBuffer
9
11
  import java.nio.channels.FileChannel
@@ -42,7 +44,7 @@ class MP4Builder {
42
44
  @Throws(Exception::class)
43
45
  private fun flushCurrentMdat() {
44
46
  val oldPosition = fc.position()
45
- fc.position(mdat.offset)
47
+ fc.position(mdat.getOffset())
46
48
  mdat.getBox(fc)
47
49
  fc.position(oldPosition)
48
50
  mdat.setDataOffset(0)
@@ -1,11 +1,11 @@
1
1
  package com.reactnativecompressor.Video.VideoCompressor.video
2
2
 
3
- import com.coremedia.iso.BoxParser
4
- import com.coremedia.iso.IsoFile
5
- import com.coremedia.iso.IsoTypeWriter
6
- import com.coremedia.iso.boxes.Box
7
- import com.coremedia.iso.boxes.Container
8
- import com.googlecode.mp4parser.DataSource
3
+ import org.mp4parser.Box
4
+ import org.mp4parser.BoxParser
5
+ import org.mp4parser.Container
6
+ import org.mp4parser.IsoFile
7
+ import org.mp4parser.tools.IsoTypeWriter
8
+
9
9
  import java.nio.ByteBuffer
10
10
  import java.nio.channels.WritableByteChannel
11
11
 
@@ -15,15 +15,15 @@ class Mdat : Box {
15
15
  private var contentSize = (1024 * 1024 * 1024).toLong()
16
16
  private var dataOffset: Long = 0
17
17
 
18
- override fun getParent(): Container = parent
18
+ fun getParent(): Container = parent
19
19
 
20
- override fun setParent(parent: Container) {
20
+ fun setParent(parent: Container) {
21
21
  this.parent = parent
22
22
  }
23
23
 
24
24
  override fun getSize(): Long = 16 + contentSize
25
25
 
26
- override fun getOffset(): Long = dataOffset
26
+ fun getOffset(): Long = dataOffset
27
27
 
28
28
  fun setDataOffset(offset: Long) {
29
29
  dataOffset = offset
@@ -63,12 +63,4 @@ class Mdat : Box {
63
63
  bb.rewind()
64
64
  writableByteChannel.write(bb)
65
65
  }
66
-
67
- override fun parse(
68
- dataSource: DataSource?,
69
- header: ByteBuffer?,
70
- contentSize: Long,
71
- boxParser: BoxParser?
72
- ) {
73
- }
74
66
  }
@@ -2,7 +2,7 @@ package com.reactnativecompressor.Video.VideoCompressor.video
2
2
 
3
3
  import android.media.MediaCodec
4
4
  import android.media.MediaFormat
5
- import com.googlecode.mp4parser.util.Matrix
5
+ import org.mp4parser.support.Matrix
6
6
  import java.io.File
7
7
  import java.util.*
8
8
 
@@ -3,17 +3,17 @@ package com.reactnativecompressor.Video.VideoCompressor.video
3
3
  import android.media.MediaCodec
4
4
  import android.media.MediaCodecInfo
5
5
  import android.media.MediaFormat
6
- import com.coremedia.iso.boxes.SampleDescriptionBox
7
- import com.coremedia.iso.boxes.sampleentry.AudioSampleEntry
8
- import com.coremedia.iso.boxes.sampleentry.VisualSampleEntry
9
- import com.googlecode.mp4parser.boxes.mp4.ESDescriptorBox
10
- import com.googlecode.mp4parser.boxes.mp4.objectdescriptors.AudioSpecificConfig
11
- import com.googlecode.mp4parser.boxes.mp4.objectdescriptors.DecoderConfigDescriptor
12
- import com.googlecode.mp4parser.boxes.mp4.objectdescriptors.ESDescriptor
13
- import com.googlecode.mp4parser.boxes.mp4.objectdescriptors.SLConfigDescriptor
14
- import com.mp4parser.iso14496.part15.AvcConfigurationBox
6
+ import com.reactnativecompressor.Utils.Utils
7
+ import org.mp4parser.boxes.iso14496.part1.objectdescriptors.AudioSpecificConfig
8
+ import org.mp4parser.boxes.iso14496.part1.objectdescriptors.DecoderConfigDescriptor
9
+ import org.mp4parser.boxes.iso14496.part1.objectdescriptors.ESDescriptor
10
+ import org.mp4parser.boxes.iso14496.part1.objectdescriptors.SLConfigDescriptor
11
+ import org.mp4parser.boxes.iso14496.part12.SampleDescriptionBox
12
+ import org.mp4parser.boxes.iso14496.part14.ESDescriptorBox
13
+ import org.mp4parser.boxes.iso14496.part15.AvcConfigurationBox
14
+ import org.mp4parser.boxes.sampleentry.AudioSampleEntry
15
+ import org.mp4parser.boxes.sampleentry.VisualSampleEntry
15
16
  import java.util.*
16
- import kotlin.reflect.jvm.isAccessible
17
17
 
18
18
  class Track(id: Int, format: MediaFormat, audio: Boolean) {
19
19
 
@@ -67,28 +67,10 @@ class Track(id: Int, format: MediaFormat, audio: Boolean) {
67
67
  VisualSampleEntry(VisualSampleEntry.TYPE3).setup(width, height)
68
68
 
69
69
  val avcConfigurationBox = AvcConfigurationBox()
70
- if (format.getByteBuffer("csd-0") != null) {
71
- val spsArray = ArrayList<ByteArray>()
72
- val spsBuff = format.getByteBuffer("csd-0")
73
- spsBuff!!.position(4)
74
-
75
- val spsBytes = ByteArray(spsBuff.remaining())
76
- spsBuff[spsBytes]
77
- spsArray.add(spsBytes)
78
-
79
- val ppsArray = ArrayList<ByteArray>()
80
- val ppsBuff = format.getByteBuffer("csd-1")
81
- ppsBuff?.let {
82
- it.position(4)
83
-
84
- val ppsBytes = ByteArray(it.remaining())
85
- it[ppsBytes]
86
-
87
- ppsArray.add(ppsBytes)
88
- avcConfigurationBox.sequenceParameterSets = spsArray
89
- avcConfigurationBox.pictureParameterSets = ppsArray
90
- }
91
- }
70
+ avcConfigurationBox.sequenceParameterSets =
71
+ format.getByteBuffer("csd-0")?.let { listOf(Utils.subBuffer(it, 4)) }
72
+ avcConfigurationBox.pictureParameterSets =
73
+ format.getByteBuffer("csd-1")?.let { listOf(Utils.subBuffer(it, 4)) }
92
74
 
93
75
  if (format.containsKey("level")) {
94
76
  when (format.getInteger("level")) {
@@ -188,39 +170,15 @@ class Track(id: Int, format: MediaFormat, audio: Boolean) {
188
170
 
189
171
  val audioSpecificConfig = AudioSpecificConfig()
190
172
 
191
- // Fix for com.googlecode.mp4parser:isoparser multiple version management
192
- // Updates based on
193
- // https://github.com/sannies/mp4parser/commit/9cf7f9185b294ac4fa1cd86be1915cd355d859eb#diff-5860894eeaba912c09de175e617d53d5beecebeadd2b64695ed736f9e598bf55
194
- // and
195
- // https://github.com/sannies/mp4parser/commit/b85f62274b56cc68d6c6e3dc2f9d4e23318e3341#diff-5860894eeaba912c09de175e617d53d5beecebeadd2b64695ed736f9e598bf55
196
- //
197
- val method = audioSpecificConfig::class.members.firstOrNull { it.name == "setOriginalAudioObjectType" }
198
- if (method != null) {
199
- // com.googlecode.mp4parser:isoparser is >= 1.1
200
- method.isAccessible = true
201
- method.call(audioSpecificConfig, 2)
202
- audioSpecificConfig.setSamplingFrequencyIndex(
203
- samplingFrequencyIndexMap[audioSampleEntry.sampleRate.toInt()]!!
204
- )
205
- audioSpecificConfig.setChannelConfiguration(audioSampleEntry.channelCount)
206
- decoderConfigDescriptor.audioSpecificInfo = audioSpecificConfig
207
- descriptor.decoderConfigDescriptor = decoderConfigDescriptor
208
-
209
- esds.esDescriptor = descriptor
210
- } else {
211
- // com.googlecode.mp4parser:isoparser is < 1.1 (eg: 1.0.6)
212
- audioSpecificConfig.setAudioObjectType(2)
213
- audioSpecificConfig.setSamplingFrequencyIndex(
214
- samplingFrequencyIndexMap[audioSampleEntry.sampleRate.toInt()]!!
215
- )
216
- audioSpecificConfig.setChannelConfiguration(audioSampleEntry.channelCount)
217
- decoderConfigDescriptor.audioSpecificInfo = audioSpecificConfig
218
- descriptor.decoderConfigDescriptor = decoderConfigDescriptor
219
-
220
- val data = descriptor.serialize()
221
- esds.esDescriptor = descriptor
222
- esds.data = data
223
- }
173
+ audioSpecificConfig.setOriginalAudioObjectType(2)
174
+ audioSpecificConfig.setSamplingFrequencyIndex(
175
+ samplingFrequencyIndexMap[audioSampleEntry.sampleRate.toInt()]!!
176
+ )
177
+ audioSpecificConfig.setChannelConfiguration(audioSampleEntry.channelCount)
178
+ decoderConfigDescriptor.audioSpecificInfo = audioSpecificConfig
179
+ descriptor.decoderConfigDescriptor = decoderConfigDescriptor
180
+
181
+ esds.esDescriptor = descriptor
224
182
 
225
183
  audioSampleEntry.addBox(esds)
226
184
  sampleDescriptionBox.addBox(audioSampleEntry)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-compressor",
3
- "version": "1.8.25",
3
+ "version": "1.9.0",
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",