diff --git a/lib/src/main/java/com/otaliastudios/transcoder/internal/data/Writer.kt b/lib/src/main/java/com/otaliastudios/transcoder/internal/data/Writer.kt index 12aa1c2f..ce2a67bf 100644 --- a/lib/src/main/java/com/otaliastudios/transcoder/internal/data/Writer.kt +++ b/lib/src/main/java/com/otaliastudios/transcoder/internal/data/Writer.kt @@ -38,9 +38,14 @@ internal class Writer( override fun step(state: State.Ok, fresh: Boolean): State { val (buffer, timestamp, flags) = state.value + // Note: flags does NOT include BUFFER_FLAG_END_OF_STREAM. That's passed via State.Eos. val eos = state is State.Eos if (eos) { - info.set(0, 0, 0, flags and MediaCodec.BUFFER_FLAG_END_OF_STREAM) + // Note: it may happen that at this point, buffer has some data. but creating an extra writeTrack() call + // can cause some crashes that were not properly debugged, probably related to wrong timestamp. + // I think if we could ensure that timestamp is valid (> previous, > 0) and buffer.hasRemaining(), there should + // be an extra call here. See #159. Reluctant to do so without a repro test. + info.set(0, 0, 0, flags or MediaCodec.BUFFER_FLAG_END_OF_STREAM) } else { info.set( buffer.position(),