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

Fix Failed to stop the muxer (ref #139) #159

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jumperson
Copy link
Contributor

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

This was referenced Jan 31, 2022
@jumperson
Copy link
Contributor Author

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

@pstevanovic-textnow
Copy link

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)

Comment on lines +42 to 52
if (eos) {
info.set(0, 0, 0, flags and MediaCodec.BUFFER_FLAG_END_OF_STREAM)
} else {
info.set(
buffer.position(),
buffer.remaining(),
timestamp,
flags
)
}
sink.writeTrack(track, buffer, info)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last buffer might have data in theory, is it possible to send it in a separate call?

if (eos) {
    if (buffer.hasRemaining()) {
        info.set(buffer.position(), buffer.remaining(), timestamp, flags)
        sink.writeTrack(track, buffer, info)
    }    
    info.set(0, 0, 0, flags and MediaCodec.BUFFER_FLAG_END_OF_STREAM)
} else {
    info.set(buffer.position(), buffer.remaining(), timestamp, flags)
}
sink.writeTrack(track, buffer, info)

Would this fix your crash?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@natario1 Thanks for your review.
I tried your codes. But Crashed.

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:466)
        at android.media.MediaMuxer.release(MediaMuxer.java:706)
        at com.otaliastudios.transcoder.sink.DefaultDataSink.release(DefaultDataSink.java:224)
        at com.otaliastudios.transcoder.internal.transcode.DefaultTranscodeEngine.cleanup(DefaultTranscodeEngine.kt:141)
        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:919)

@myounis97
Copy link

Any update on this issue?

@MadCoderme
Copy link

MadCoderme commented Jul 28, 2022

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

@natario1
Copy link
Owner

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

@shofizone
Copy link

shofizone commented Nov 20, 2022

@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)

@VadimEksler
Copy link

any updates on this issue?

@UrielFrankel
Copy link

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

@vanniktech
Copy link
Contributor

@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: #182 and then released a new version: #183

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

@UrielFrankel
Copy link

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

@mohsin-whizpool
Copy link

Any update on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet