deepmedia / Transcoder

🎞 Hardware-accelerated video transcoding using Android MediaCodec APIs. Supports cropping, concatenation, clipping, audio processing, video speed and much more.
https://opensource.deepmedia.io/transcoder
Apache License 2.0
778 stars 165 forks source link

Overflow in DefaultDataSink.enqueue (slow audio format) #163

Closed jumperson closed 1 week ago

jumperson commented 2 years ago

I used the demo app and I got the following error:

E/TranscodeEngine: Unexpected error while transcoding.
    java.nio.BufferOverflowException
        at java.nio.ByteBuffer.put(ByteBuffer.java:615)
        at com.otaliastudios.transcoder.sink.DefaultDataSink.enqueue(DefaultDataSink.java:191)
        at com.otaliastudios.transcoder.sink.DefaultDataSink.writeTrack(DefaultDataSink.java:165)
        at com.otaliastudios.transcoder.internal.utils.EosIgnoringDataSink.writeTrack(eos.kt:28)
        at com.otaliastudios.transcoder.internal.data.Writer.step(Writer.kt:52)
        at com.otaliastudios.transcoder.internal.pipeline.Pipeline.executeStep(Pipeline.kt:51)
        at com.otaliastudios.transcoder.internal.pipeline.Pipeline.execute(Pipeline.kt:28)
        at com.otaliastudios.transcoder.internal.Segment.advance(Segment.kt:18)
        at com.otaliastudios.transcoder.internal.transcode.DefaultTranscodeEngine.transcode(DefaultTranscodeEngine.kt:114)
        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)

may be refs #138

device: F-02L OS: 9

wendychen3k commented 1 year ago

This is still happening on the latest version: 0.10.4 on my Oneplus 7, tried to run the demo on a Samsung device and transcode the same video, working fine. Device: Oneplus 7 OS: Android 10

Here is the log from Oneplus 7:

DefaultDataSink: setTrackFormat(VIDEO) format={max-bitrate=8709120, csd-1=java.nio.HeapByteBuffer[pos=0 lim=9 cap=9], color-transfer=3, mime=video/avc, width=1080, bitrate=8709120, color-range=2, frame-rate=30, color-standard=2, height=1920, csd-0=java.nio.HeapByteBuffer[pos=0 lim=23 cap=23]}
DefaultDataSinkChecks: Output H.264 profile: High Profile. This might not be supported.
DefaultDataSink: enqueue(VIDEO): offset=0       realOffset=0    size=432        realSize=432    available=262144        total=262144    
DefaultDataSink: enqueue(VIDEO): offset=0       realOffset=0    size=1392       realSize=1392   available=261712        total=262144    
DefaultDataSink: enqueue(VIDEO): offset=0       realOffset=0    size=1792       realSize=1792   available=260320        total=262144    
DefaultDataSink: enqueue(VIDEO): offset=0       realOffset=0    size=2048       realSize=2048   available=258528        total=262144    
DefaultDataSink: enqueue(VIDEO): offset=0       realOffset=0    size=2720       realSize=2720   available=256480        total=262144    
DefaultDataSink: enqueue(VIDEO): offset=0       realOffset=0    size=4224       realSize=4224   available=253760        total=262144    
DefaultDataSink: enqueue(VIDEO): offset=0       realOffset=0    size=5024       realSize=5024   available=249536        total=262144    
DefaultDataSink: enqueue(VIDEO): offset=0       realOffset=0    size=8240       realSize=8240   available=244512        total=262144    
DefaultDataSink: enqueue(VIDEO): offset=0       realOffset=0    size=12896      realSize=12896  available=236272        total=262144    
DefaultDataSink: enqueue(VIDEO): offset=0       realOffset=0    size=19376      realSize=19376  available=223376        total=262144    
DefaultDataSink: enqueue(VIDEO): offset=0       realOffset=0    size=27552      realSize=27552  available=204000        total=262144    
DefaultDataSink: enqueue(VIDEO): offset=0       realOffset=0    size=37936      realSize=37936  available=176448        total=262144    
DefaultDataSink: enqueue(VIDEO): offset=0       realOffset=0    size=50288      realSize=50288  available=138512        total=262144    
DefaultDataSink: enqueue(VIDEO): offset=0       realOffset=0    size=51584      realSize=51584  available=88224 total=262144
DefaultDataSink: enqueue(VIDEO): offset=0       realOffset=0    size=37008      realSize=37008  available=36640 total=262144
TranscodeEngine: Unexpected error while transcoding.
    java.nio.BufferOverflowException
        at java.nio.ByteBuffer.put(ByteBuffer.java:611)
        at java.nio.DirectByteBuffer.put(DirectByteBuffer.java:256)
        at com.otaliastudios.transcoder.sink.DefaultDataSink.enqueue(DefaultDataSink.java:191)
        at com.otaliastudios.transcoder.sink.DefaultDataSink.writeTrack(DefaultDataSink.java:165)
        at com.otaliastudios.transcoder.internal.utils.EosIgnoringDataSink.writeTrack(eos.kt:28)
        at com.otaliastudios.transcoder.internal.data.Writer.step(Writer.kt:50)
        at com.otaliastudios.transcoder.internal.pipeline.Pipeline.executeStep(Pipeline.kt:51)
        at com.otaliastudios.transcoder.internal.pipeline.Pipeline.execute(Pipeline.kt:28)
        at com.otaliastudios.transcoder.internal.Segment.advance(Segment.kt:18)
        at com.otaliastudios.transcoder.internal.transcode.DefaultTranscodeEngine.transcode(DefaultTranscodeEngine.kt:114)
        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:919)

Log from Samsung:

DefaultDataSink: setTrackFormat(VIDEO) format={max-bitrate=8709120, crop-right=1079, level=2048, mime=video/avc, profile=8, bitrate=8709120, priority=0, intra-refresh-period=0, color-standard=1, csd-1=java.nio.HeapByteBuffer[pos=0 lim=8 cap=8], color-transfer=3, crop-bottom=1919, prepend-sps-pps-to-idr-frames=0, crop-left=0, width=1080, bitrate-mode=1, color-range=2, crop-top=0, frame-rate=30, height=1920, csd-0=java.nio.HeapByteBuffer[pos=0 lim=31 cap=31]}
DefaultDataSinkChecks: Output H.264 profile: High Profile. This might not be supported.
DefaultDataSink: enqueue(VIDEO): offset=0       realOffset=0    size=12998      realSize=12998  available=262144        total=262144
DefaultDataSink: setTrackFormat(AUDIO) format={max-bitrate=256000, sample-rate=48000, level=0, mime=audio/mp4a-latm, profile=2, channel-count=2, bitrate=256000, csd-0=java.nio.HeapByteBuffer[pos=0 lim=2 cap=2]}
DefaultDataSink: Added track #0 with video/avc to muxer
DefaultDataSink: Added track #1 with audio/mp4a-latm to muxer
DefaultDataSink: Output format determined, writing pending data into the muxer. samples:1 bytes:12998
natario1 commented 1 month ago

(Pasted to all my answers today: it's been a long time since my last issues review. I am sorry about the delay and I know you likely have moved on by now. Still, I'm going to answer where I can)

What's happening here is that audio output format is, for some reason, slow to arrive and the video temporary queue gets filled. I will investigate.