deepmedia / deepmedia/Transcoder

Bug Report: Transcoding Fails Due to Non-Monotonic Timestamps

Open
#213 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
864
Forks
181
PR merge metrics
No merged PRs in 30d

Description

When transcoding a specific video, I encounter the following issue:

java.lang.IllegalStateException: Timestamps must be monotonically increasing: 17229000, 17229000
at com.otaliastudios.transcoder.internal.Timer$SegmentInterpolator.interpolate(Timer.kt:103)
at com.otaliastudios.transcoder.internal.codec.DecoderTimer.advance(DecoderTimer.kt:31)
at com.otaliastudios.transcoder.internal.pipeline.PipelineItem.handle(Pipeline.kt:37)
at com.otaliastudios.transcoder.internal.pipeline.Pipeline.execute(Pipeline.kt:84)
at com.otaliastudios.transcoder.internal.Segment.advance(Segment.kt:17)
at com.otaliastudios.transcoder.internal.transcode.DefaultTranscodeEngine.transcode(DefaultTranscodeEngine.kt:115)
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:264)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
at java.lang.Thread.run(Thread.java:1012)
This happens when trying to transcode a specific video file.

Steps to Reproduce
Use the following transcoding setup:

```
val transcoder = Transcoder.into(outputFile.path)
.addDataSource(dataSource)
.setVideoTrackStrategy(videoStrategy)
.setAudioTrackStrategy(audioStrategy)
.setTimeInterpolator(MonotonicTimeInterpolator())
.setListener(object : TranscoderListener {
override fun onTranscodeProgress(progress: Double) {
Log.i(TAG, "Transcode Progress: ${progress * 100}%")
}

override fun onTranscodeCompleted(successCode: Int) {
Log.i(TAG, "Transcoding Completed")
}

override fun onTranscodeFailed(exception: Throwable) {
Log.e(TAG, "Transcoding Failed: ${exception.message}")
}
})
.transcode()
```

Using a custom MonotonicTimeInterpolator to enforce increasing timestamps:

class MonotonicTimeInterpolator : TimeInterpolator {
private val last = mutableTrackMapOf(Long.MIN_VALUE, Long.MIN_VALUE)

override fun interpolate(type: TrackType, time: Long): Long {
return interpolate(last[type], time).also { last[type] = it }
}

private fun interpolate(prev: Long, next: Long): Long {
if (prev == Long.MIN_VALUE) return next
return next.coerceAtLeast(prev + 1)
}
}
This prevents the non-monotonic timestamp issue, but then:

The transcoding stalls at the end.
If I set audio to pass-through:

`val audioStrategy = TrackStrategy { _, _ -> TrackStatus.PASS_THROUGH }
`
the video transcodes without sound.

Could you provide guidance on how to handle this properly?

It happen for some videos and other transcoded without problem

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.