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

BlankAudioDataSource makes transcoding stuck forever. #180

Closed timcreatedit closed 1 week ago

timcreatedit commented 1 year ago

When adding a BlankAudioDataSource with any duration to a Transcoder, the transcoding process gets stuck forever with the following log:

V/TranscodeEngine( 9241): transcode(): executed step=53 advanced=false completed=false
V/Segment(AUDIO,0)( 9241): canAdvance(): state=State.Wait
V/Pipeline(Audio)( 9241): execute(): starting. head=0 steps=6 remaining=6
I/Decoder(AUDIO,0)( 9241): buffer() failed. dequeuedInputs=0 dequeuedOutputs=4
V/Reader  ( 9241): Returning State.Wait because buffer is null.
V/Pipeline(Audio)( 9241): execute(): step Reader (#0/6) is waiting. headState=State.Ok(kotlin.Unit) headIndex=0
V/Segment(VIDEO,0)( 9241): canAdvance(): state=State.Eos(kotlin.Unit)
V/Segments( 9241): hasNext(VIDEO): segment=com.otaliastudios.transcoder.internal.Segment@c6c217a lastIndex=0 canAdvance=false
V/Segment(VIDEO,0)( 9241): canAdvance(): state=State.Eos(kotlin.Unit)
V/Segment(AUDIO,0)( 9241): canAdvance(): state=State.Wait
V/Segments( 9241): hasNext(AUDIO): segment=com.otaliastudios.transcoder.internal.Segment@5463bad lastIndex=0 canAdvance=true
V/Segment(AUDIO,0)( 9241): canAdvance(): state=State.Wait
V/TranscodeEngine( 9241): transcode(): executed step=53 advanced=false completed=false
V/Segment(AUDIO,0)( 9241): canAdvance(): state=State.Wait
V/Pipeline(Audio)( 9241): execute(): starting. head=0 steps=6 remaining=6
I/Decoder(AUDIO,0)( 9241): buffer() failed. dequeuedInputs=0 dequeuedOutputs=4
V/Reader  ( 9241): Returning State.Wait because buffer is null.
V/Pipeline(Audio)( 9241): execute(): step Reader (#0/6) is waiting. headState=State.Ok(kotlin.Unit) headIndex=0
V/Segment(VIDEO,0)( 9241): canAdvance(): state=State.Eos(kotlin.Unit)
V/Segments( 9241): hasNext(VIDEO): segment=com.otaliastudios.transcoder.internal.Segment@c6c217a lastIndex=0 canAdvance=false

and so on...

I tried to modify the readTrack function in BlankAudioDataSource but to no avail. Not sure if @natario1 is still maintaining this repo, but maybe @mudar can help out as the original author of #64

Thank you so much!

mudar commented 1 year ago

Did you add a valid video track along with the blank audio?

timcreatedit commented 1 year ago

Hey, thanks for your super quick response!

We are basically doing this:

                val datasource = UriDataSource(context, sourcePathUri)

                datasource.initialize()
                val transcoder = Transcoder.into(destPath)
                    .addDataSource(TrackType.VIDEO, datasource)
                    .addDataSource(TrackType.AUDIO, BlankAudioDataSource(datasource.durationUs))

Without adding the BlankAudioDatasource, this code works fine. Once we add it, it is stuck infinitely as mentioned above.

timcreatedit commented 1 year ago

Our main goal is the problem you had originally as well, where we can't concat videos with audio tracks together with videos without audio tracks, although we might be missing something of course

mudar commented 1 year ago

It's been a while since I worked on this, so I'm not sure I can help with the code! Looking at the PR, I have the impression that adding the blankAudio is handled internally by the transcoder. You could try concatenating the two videos (with/without audio tracks) and see if that works :crossed_fingers:

timcreatedit commented 1 year ago

If we try to concatenate video with audio with video without audio, we run into the same problem as you did in #51 It seems like the audioTracks getter doesn’t do it’s job (anymore), or we're potentially missing something

thanks again for your help, it is really appreciated

timcreatedit commented 1 year ago

https://github.com/natario1/Transcoder/blob/ba8f098c9461a12da1c11d26c9f32feb1e69b4d5/lib/src/main/java/com/otaliastudios/transcoder/internal/DataSources.kt#L53

This looks like it should fill missing audio tracks with BlankAudioDataSources automatically

VOstopolets commented 1 year ago

@timcreatedit Hi. Any updates about this issue?

jordond commented 1 year ago

Experiencing the same thing over here. Hoping for some updates.

natario1 commented 1 week ago

I can't reproduce this anymore, it should be fixed in latest version.