Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: move to isoparser 1.9.X #311

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ dependencies {

implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4"
implementation "com.googlecode.mp4parser:isoparser:1.0.6"
implementation 'org.mp4parser:isoparser:1.9.56'
implementation 'com.github.banketree:AndroidLame-kotlin:v0.0.1'
implementation 'javazoom:jlayer:1.0.1'
}
Expand Down
11 changes: 10 additions & 1 deletion android/src/main/java/com/reactnativecompressor/Utils/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import java.io.FileNotFoundException
import java.io.IOException
import java.net.HttpURLConnection
import java.net.URL
import java.nio.ByteBuffer
import java.util.UUID
import java.util.regex.Pattern
import kotlin.Throwable


object Utils {
private const val TAG = "react-native-compessor"
Expand Down Expand Up @@ -328,4 +329,12 @@ object Utils {
-1L
}
}

fun subBuffer(buf: ByteBuffer, start: Int, count: Int = buf.remaining() - start): ByteBuffer {
val newBuf = buf.duplicate()
val bytes = ByteArray(count)
newBuf.position(start)
newBuf[bytes, 0, bytes.size]
return ByteBuffer.wrap(bytes)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package com.reactnativecompressor.Video.VideoCompressor.video

import android.media.MediaCodec
import android.media.MediaFormat
import com.coremedia.iso.boxes.*
import com.googlecode.mp4parser.util.Matrix
import org.mp4parser.Box
import org.mp4parser.boxes.iso14496.part12.*

import org.mp4parser.support.Matrix
import java.io.FileOutputStream
import java.nio.ByteBuffer
import java.nio.channels.FileChannel
Expand Down Expand Up @@ -42,7 +44,7 @@ class MP4Builder {
@Throws(Exception::class)
private fun flushCurrentMdat() {
val oldPosition = fc.position()
fc.position(mdat.offset)
fc.position(mdat.getOffset())
mdat.getBox(fc)
fc.position(oldPosition)
mdat.setDataOffset(0)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.reactnativecompressor.Video.VideoCompressor.video

import com.coremedia.iso.BoxParser
import com.coremedia.iso.IsoFile
import com.coremedia.iso.IsoTypeWriter
import com.coremedia.iso.boxes.Box
import com.coremedia.iso.boxes.Container
import com.googlecode.mp4parser.DataSource
import org.mp4parser.Box
import org.mp4parser.BoxParser
import org.mp4parser.Container
import org.mp4parser.IsoFile
import org.mp4parser.tools.IsoTypeWriter

import java.nio.ByteBuffer
import java.nio.channels.WritableByteChannel

Expand All @@ -15,15 +15,15 @@ class Mdat : Box {
private var contentSize = (1024 * 1024 * 1024).toLong()
private var dataOffset: Long = 0

override fun getParent(): Container = parent
fun getParent(): Container = parent

override fun setParent(parent: Container) {
fun setParent(parent: Container) {
this.parent = parent
}

override fun getSize(): Long = 16 + contentSize

override fun getOffset(): Long = dataOffset
fun getOffset(): Long = dataOffset

fun setDataOffset(offset: Long) {
dataOffset = offset
Expand Down Expand Up @@ -63,12 +63,4 @@ class Mdat : Box {
bb.rewind()
writableByteChannel.write(bb)
}

override fun parse(
dataSource: DataSource?,
header: ByteBuffer?,
contentSize: Long,
boxParser: BoxParser?
) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.reactnativecompressor.Video.VideoCompressor.video

import android.media.MediaCodec
import android.media.MediaFormat
import com.googlecode.mp4parser.util.Matrix
import org.mp4parser.support.Matrix
import java.io.File
import java.util.*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ package com.reactnativecompressor.Video.VideoCompressor.video
import android.media.MediaCodec
import android.media.MediaCodecInfo
import android.media.MediaFormat
import com.coremedia.iso.boxes.SampleDescriptionBox
import com.coremedia.iso.boxes.sampleentry.AudioSampleEntry
import com.coremedia.iso.boxes.sampleentry.VisualSampleEntry
import com.googlecode.mp4parser.boxes.mp4.ESDescriptorBox
import com.googlecode.mp4parser.boxes.mp4.objectdescriptors.AudioSpecificConfig
import com.googlecode.mp4parser.boxes.mp4.objectdescriptors.DecoderConfigDescriptor
import com.googlecode.mp4parser.boxes.mp4.objectdescriptors.ESDescriptor
import com.googlecode.mp4parser.boxes.mp4.objectdescriptors.SLConfigDescriptor
import com.mp4parser.iso14496.part15.AvcConfigurationBox
import com.reactnativecompressor.Utils.Utils
import org.mp4parser.boxes.iso14496.part1.objectdescriptors.AudioSpecificConfig
import org.mp4parser.boxes.iso14496.part1.objectdescriptors.DecoderConfigDescriptor
import org.mp4parser.boxes.iso14496.part1.objectdescriptors.ESDescriptor
import org.mp4parser.boxes.iso14496.part1.objectdescriptors.SLConfigDescriptor
import org.mp4parser.boxes.iso14496.part12.SampleDescriptionBox
import org.mp4parser.boxes.iso14496.part14.ESDescriptorBox
import org.mp4parser.boxes.iso14496.part15.AvcConfigurationBox
import org.mp4parser.boxes.sampleentry.AudioSampleEntry
import org.mp4parser.boxes.sampleentry.VisualSampleEntry
import java.nio.ByteBuffer
import java.util.*
import kotlin.reflect.jvm.isAccessible

Expand Down Expand Up @@ -67,28 +69,10 @@ class Track(id: Int, format: MediaFormat, audio: Boolean) {
VisualSampleEntry(VisualSampleEntry.TYPE3).setup(width, height)

val avcConfigurationBox = AvcConfigurationBox()
if (format.getByteBuffer("csd-0") != null) {
val spsArray = ArrayList<ByteArray>()
val spsBuff = format.getByteBuffer("csd-0")
spsBuff!!.position(4)

val spsBytes = ByteArray(spsBuff.remaining())
spsBuff[spsBytes]
spsArray.add(spsBytes)

val ppsArray = ArrayList<ByteArray>()
val ppsBuff = format.getByteBuffer("csd-1")
ppsBuff?.let {
it.position(4)

val ppsBytes = ByteArray(it.remaining())
it[ppsBytes]

ppsArray.add(ppsBytes)
avcConfigurationBox.sequenceParameterSets = spsArray
avcConfigurationBox.pictureParameterSets = ppsArray
}
}
avcConfigurationBox.sequenceParameterSets =
format.getByteBuffer("csd-0")?.let { listOf(Utils.subBuffer(it, 4)) }
avcConfigurationBox.pictureParameterSets =
format.getByteBuffer("csd-1")?.let { listOf(Utils.subBuffer(it, 4)) }

if (format.containsKey("level")) {
when (format.getInteger("level")) {
Expand Down
Loading