Skip to content

Commit

Permalink
Enable Passthrough remixer for more than 2 audio channels (#209)
Browse files Browse the repository at this point in the history
* Enable Passthrough remixer for more than 2 channels

* Remove audio track strategy in issue75 tests
  • Loading branch information
natario1 authored Nov 5, 2024
1 parent 0fed470 commit a7cebe3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.otaliastudios.transcoder.source.AssetFileDescriptorDataSource
import com.otaliastudios.transcoder.source.BlankAudioDataSource
import com.otaliastudios.transcoder.source.ClipDataSource
import com.otaliastudios.transcoder.source.FileDescriptorDataSource
import com.otaliastudios.transcoder.strategy.DefaultAudioStrategy
import com.otaliastudios.transcoder.strategy.DefaultVideoStrategy
import com.otaliastudios.transcoder.validator.WriteAlwaysValidator
import org.junit.Assume
Expand Down Expand Up @@ -135,4 +136,19 @@ class IssuesTests {
}
Unit
}

@Test(timeout = 16000)
fun issue75_workaround() = with(Helper(75)) {
transcode {
val vds = input("bbb_720p_30mb.mp4")
addDataSource(ClipDataSource(vds, 0, 500_000))
setVideoTrackStrategy(DefaultVideoStrategy.exact(300, 300).build())
// API 23:
// This video seems to have wrong number of channels in metadata (6) wrt MediaCodec decoder output (2)
// so when using DefaultAudioStrategy.CHANNELS_AS_INPUT we target 6 and try to upscale from 2 to 6, which fails
// The workaround below explicitly sets a number of channels different than CHANNELS_AS_INPUT to make it work
// setAudioTrackStrategy(DefaultAudioStrategy.builder().channels(1).build())
}
Unit
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ internal interface AudioRemixer {

companion object {
internal operator fun get(inputChannels: Int, outputChannels: Int): AudioRemixer = when {
inputChannels == outputChannels -> PassThroughAudioRemixer()
inputChannels !in setOf(1, 2) -> error("Input channel count not supported: $inputChannels")
outputChannels !in setOf(1, 2) -> error("Output channel count not supported: $inputChannels")
outputChannels !in setOf(1, 2) -> error("Output channel count not supported: $outputChannels")
inputChannels < outputChannels -> UpMixAudioRemixer()
inputChannels > outputChannels -> DownMixAudioRemixer()
else -> PassThroughAudioRemixer()
else -> DownMixAudioRemixer()
}
}
}

0 comments on commit a7cebe3

Please sign in to comment.