deepmedia / Transcoder

🎞 Hardware-accelerated video transcoding using Android MediaCodec APIs. Supports cropping, concatenation, clipping, audio processing, video speed and much more.
https://opensource.deepmedia.io/transcoder
Apache License 2.0
783 stars 166 forks source link

java.lang.NullPointerException: Attempt to invoke interface method 'boolean com.otaliastudios.transcoder.source.DataSource.isInitialized()' on a null object reference #154

Closed jd565 closed 2 years ago

jd565 commented 3 years ago

Hit this attempting to transcode something from a file path string.

It seems like calling isInitialized() hits an NPE as the FilePathDataSource only sets a source once it has been initialized, but checking to see if the data source has been initialized checks if the source (which is still null) has been initialized.

I think a simple fix would be to override the isInitialized method for FilePathDataSource to check if the source is null first.

kurtrex commented 3 years ago

I have the same isssue using 0.10.4 (The issue does not occur with 0.9.1) Have reproduced with API 28, 29 & 30.

Trace:

E/TranscodeEngine: Unexpected error while transcoding. java.lang.NullPointerException: Attempt to invoke interface method 'boolean com.otaliastudios.transcoder.source.DataSource.isInitialized()' on a null object reference at com.otaliastudios.transcoder.source.DataSourceWrapper.isInitialized(DataSourceWrapper.java:99) at com.otaliastudios.transcoder.internal.DataSources.init(DataSources.kt:25) at com.otaliastudios.transcoder.internal.DataSources.(DataSources.kt:35) at com.otaliastudios.transcoder.internal.DataSources.(DataSources.kt:17) at com.otaliastudios.transcoder.internal.transcode.TranscodeEngine$Companion.transcode(TranscodeEngine.kt:33) at com.otaliastudios.transcoder.internal.transcode.TranscodeEngine.transcode(Unknown Source:2) at com.otaliastudios.transcoder.Transcoder$1.call(Transcoder.java:102) at com.otaliastudios.transcoder.Transcoder$1.call(Transcoder.java:99)

Code to reproduce:

private var mTranscoderFuture: Future<Void>? = null

fun executeJoinVideoTranscoder(fileList: List<File>, newFile: File) {
    val transcoder = Transcoder.into(newFile.absolutePath)
    for (file in fileList) {
        transcoder.addDataSource(file.absolutePath)
    }

    transcoder.setListener(object : TranscoderListener {
        override fun onTranscodeProgress(progress: Double) {
            _videoProgress.postValue(progress)
            // Log.i(TAG, "Transcode progress =$progress")
        }

        override fun onTranscodeCompleted(successCode: Int) {
            _joinVideo.postValue(newFile.absolutePath)
            Log.i(TAG, "Transcode completed successfully.")
        }

        override fun onTranscodeCanceled() {
            _joinVideo.postValue("CANCEL")
            Log.i(TAG, "Transcode cancelled by user.")
        }

        override fun onTranscodeFailed(exception: Throwable) {
            _joinVideo.postValue("ERROR")
            Log.i(TAG, "Transcode failed")
        }
    })
    mTranscoderFuture = transcoder.transcode()
}
humazed commented 3 years ago

Also can confirm it is not happening on 0.9.1

hafiz013 commented 2 years ago

when this fix version will release?

amentan commented 2 years ago

when this fix version will release?

mhackeras commented 2 years ago

I today reproduced this issue. @natario1

Mouadabdelghafouraitali commented 2 years ago

Same issue here

Mouadabdelghafouraitali commented 2 years ago

Using URI instead of video path fix the issue