israel-fl / bitmap2video

Generate video from Image resources, Bitmaps or a Canvas. Allows for audio multiplexing.
Apache License 2.0
89 stars 27 forks source link

Bug: build fail and when fixed, also creation of the video fails #12

Open AndroidDeveloperLB opened 3 years ago

AndroidDeveloperLB commented 3 years ago

AAPT: error: resource style/Theme.MaterialComponents.DayNight (aka com.israelfl.bitmap2video:style/Theme.MaterialComponents.DayNight) not found. error: failed linking references.

image

Adding this fixes it:

    implementation 'com.google.android.material:material:1.3.0-alpha03'

But then when running, and choosing the button "make it!", I get a crash with this exceptioN:

2020-11-06 00:28:13.788 13354-13400/com.israelfl.bitmap2video E/AndroidRuntime: FATAL EXCEPTION: DefaultDispatcher-worker-1
    Process: com.israelfl.bitmap2video, PID: 13354
    java.lang.RuntimeException: format changed twice
        at com.homesoft.encoder.FrameBuilder.drainCodec(FrameBuilder.kt:170)
        at com.homesoft.encoder.FrameBuilder.postCanvasFrame(FrameBuilder.kt:134)
        at com.homesoft.encoder.FrameBuilder.drawBitmapAndPostCanvas(FrameBuilder.kt:125)
        at com.homesoft.encoder.FrameBuilder.createFrame(FrameBuilder.kt:102)
        at com.homesoft.encoder.Muxer.mux(Muxer.kt:75)
        at com.homesoft.encoder.Muxer.muxAsync(Muxer.kt:93)
        at com.homesoft.bitmap2video.MainActivity$createVideoAsync$1.invokeSuspend(MainActivity.kt:142)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:738)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)

Or this:

2020-11-06 00:27:47.318 13006-13039/com.israelfl.bitmap2video E/AndroidRuntime: FATAL EXCEPTION: DefaultDispatcher-worker-1
    Process: com.israelfl.bitmap2video, PID: 13006
    java.lang.IllegalStateException: Failed to add the track to the muxer
        at android.media.MediaMuxer.nativeAddTrack(Native Method)
        at android.media.MediaMuxer.addTrack(MediaMuxer.java:660)
        at com.homesoft.encoder.Mp4FrameMuxer.start(Mp4FrameMuxer.kt:52)
        at com.homesoft.encoder.FrameBuilder.drainCodec(FrameBuilder.kt:176)
        at com.homesoft.encoder.FrameBuilder.postCanvasFrame(FrameBuilder.kt:134)
        at com.homesoft.encoder.FrameBuilder.drawBitmapAndPostCanvas(FrameBuilder.kt:125)
        at com.homesoft.encoder.FrameBuilder.createFrame(FrameBuilder.kt:102)
        at com.homesoft.encoder.Muxer.mux(Muxer.kt:75)
        at com.homesoft.encoder.Muxer.muxAsync(Muxer.kt:93)
        at com.homesoft.bitmap2video.MainActivity$createVideoAsync$1.invokeSuspend(MainActivity.kt:142)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:738)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
abritopach commented 3 years ago

Hi @AndroidDeveloperLB

The problem is that both methods are being called to generate the video in this part of the code

// Basic implementation
    private fun basicVideoCreation() {
        videoFile = getVideoFile(this@MainActivity, "test.mp4")
        videoFile?.run {
            muxerConfig = MuxerConfig(this, 600, 600, mimeType, 3, 1F, 1500000)
            val muxer = Muxer(this@MainActivity, muxerConfig!!)

            createVideo(muxer) // using callbacks
            // or
            createVideoAsync(muxer) // using co-routines
        }
    }

If you comment on one of the two calls it will work.