Transcoder icon indicating copy to clipboard operation
Transcoder copied to clipboard

Fix Failed to stop the muxer (ref #139)

Open jumperson opened this issue 2 years ago • 11 comments

I think info.set(0, 0, 0, flags and MediaCodec.BUFFER_FLAG_END_OF_STREAM) is fine for EOS. Do you think it is correct ?

ref: #139

jumperson avatar Dec 23 '21 07:12 jumperson

@natario1 Thank you for developing a great library. I would appreciate it if you could review the fix.

jumperson avatar Feb 01 '22 13:02 jumperson

Stacktrace:

2022-02-09 20:20:39.537 3543-6522/com.test.MyTestApp E/TranscodeEngine: Unexpected error while transcoding.
    java.lang.IllegalStateException: Failed to stop the muxer
        at android.media.MediaMuxer.nativeStop(Native Method)
        at android.media.MediaMuxer.stop(MediaMuxer.java:454)
        at com.otaliastudios.transcoder.sink.DefaultDataSink.stop(DefaultDataSink.java:218)
        at com.otaliastudios.transcoder.internal.transcode.DefaultTranscodeEngine.transcode(DefaultTranscodeEngine.kt:132)
        at com.otaliastudios.transcoder.internal.transcode.TranscodeEngine$Companion.transcode(TranscodeEngine.kt:48)
        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)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:764)

2022-02-09 20:20:39.538 3543-6522/com.test.MyTestApp E/MediaMuxer: stop() is called in invalid state 3
2022-02-09 20:20:39.539 3543-6522/com.test.MyTestApp W/DefaultDataSink: Failed to release the muxer.
    java.lang.IllegalStateException: Failed to stop the muxer
        at android.media.MediaMuxer.nativeStop(Native Method)
        at android.media.MediaMuxer.stop(MediaMuxer.java:454)
        at android.media.MediaMuxer.release(MediaMuxer.java:694)
        at com.otaliastudios.transcoder.sink.DefaultDataSink.release(DefaultDataSink.java:224)
        at com.otaliastudios.transcoder.internal.transcode.DefaultTranscodeEngine.cleanup(DefaultTranscodeEngine.kt:137)
        at com.otaliastudios.transcoder.internal.transcode.TranscodeEngine$Companion.transcode(TranscodeEngine.kt:63)
        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)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:764)

pstevanovic-textnow avatar Feb 10 '22 01:02 pstevanovic-textnow

Any update on this issue?

myounis97 avatar Apr 29 '22 15:04 myounis97

Please review and merge the changes, the library doesn't work in a lot of devices

MadCoderme avatar Jul 28 '22 09:07 MadCoderme

I'm not sure what the correct solution is. I don't have a crashing device, but it would be nice to know the API level and the values of buffer.remaining(), buffer.position(), timestamp and flags at the last invocation before crash. If my snippet above crashed that means that buffer has data, and with the current solution we would be dropping it

natario1 avatar Jul 28 '22 11:07 natario1

@natario1 I am getting this error on Android 7.1, But i don't see this issue on android 12/13. Also it doesn't shows up for all vieos.

E/TranscodeEngine(14057): Unexpected error while transcoding.
E/TranscodeEngine(14057): java.lang.IllegalStateException: Failed to stop the muxer
E/TranscodeEngine(14057): 	at android.media.MediaMuxer.nativeStop(Native Method)
E/TranscodeEngine(14057): 	at android.media.MediaMuxer.stop(MediaMuxer.java:245)
E/TranscodeEngine(14057): 	at com.otaliastudios.transcoder.sink.DefaultDataSink.stop(DefaultDataSink.java:218)
E/TranscodeEngine(14057): 	at com.otaliastudios.transcoder.internal.transcode.DefaultTranscodeEngine.transcode(DefaultTranscodeEngine.kt:132)
E/TranscodeEngine(14057): 	at com.otaliastudios.transcoder.internal.transcode.TranscodeEngine$Companion.transcode(TranscodeEngine.kt:48)
E/TranscodeEngine(14057): 	at com.otaliastudios.transcoder.internal.transcode.TranscodeEngine.transcode(TranscodeEngine.kt)
E/TranscodeEngine(14057): 	at com.otaliastudios.transcoder.Transcoder$1.call(Transcoder.java:102)
E/TranscodeEngine(14057): 	at com.otaliastudios.transcoder.Transcoder$1.call(Transcoder.java:99)
E/TranscodeEngine(14057): 	at java.util.concurrent.FutureTask.run(FutureTask.java:237)
E/TranscodeEngine(14057): 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
E/TranscodeEngine(14057): 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
E/TranscodeEngine(14057): 	at java.lang.Thread.run(Thread.java:760)

shofizone avatar Nov 20 '22 04:11 shofizone

any updates on this issue?

VadimEksler avatar Apr 04 '23 08:04 VadimEksler

In the meantime whoever wants this fix use: implementation 'com.github.jumperson:transcoder:0.10.4.2'

UrielFrankel avatar Apr 04 '23 08:04 UrielFrankel

@UrielFrankel thanks for providing a fork. Do you think it's possible that you can create a new PR with a fix and get it merged? I did the same a few weeks ago: https://github.com/natario1/Transcoder/pull/182 and then released a new version: https://github.com/natario1/Transcoder/pull/183

This way the complex code that we have here is unified and everyone benefits from the fixes.

vanniktech avatar Apr 04 '23 09:04 vanniktech

@vanniktech this is not my fork, it is @jumperson code from above.

UrielFrankel avatar Apr 04 '23 10:04 UrielFrankel

Any update on this?

mohsin-whizpool avatar Aug 07 '23 09:08 mohsin-whizpool