linkedin / LiTr

Lightweight hardware accelerated video/audio transcoder for Android.
BSD 2-Clause "Simplified" License
613 stars 85 forks source link

Add silent audio track to output if input video doesn't contain audio track #237

Closed timcreatedit closed 1 year ago

timcreatedit commented 1 year ago

Hey, thank you for the great library and all the work you do!

For concatenation purposes, I need to prepare a bunch of videos by transcoding them all into the same size/format etc. This includes the requirement, that all the transcoded videos need to contain an audio track. Therefore I would like to add an empty (silent) audio track to all the videos that don't contain one, without modifying their duration of course. I couldn't find a straightforward way of doing that, could someone maybe point me in the right direction?

timcreatedit commented 1 year ago

Basically what I would need is an equivalent to MockVideoMediaSource for Audio. I tried writing my own by looking at MockVideoMediaSource and BlankAudioDatasource from the transcoder library, but I can't get it to work with neither MediaCodecDecoder nor PassthroughDecoder.

timcreatedit commented 1 year ago

Okay I actually did get it working in the end.

This is the BlankAudioMediaSource, and it works well now with MediaCodecDecoder and MediaCodecEncoder

https://gist.github.com/timcreatedit/ec310c6d962db53d0da824e1f8f5e6fd

I'm gonna close this issue for now, let me know if you want this as a LiTr feature, I could clean everything up and submit a PR :)

izzytwosheds commented 1 year ago

You are quick. :) I was going to look into this today, but you beat me to it. I will be delighted if you contribute your work to LiTr, I am sure many users will appreciate it, too. Thank you!