Skip to content

Commit a7cebe3

Browse files
authored
Enable Passthrough remixer for more than 2 audio channels (#209)
* Enable Passthrough remixer for more than 2 channels * Remove audio track strategy in issue75 tests
1 parent 0fed470 commit a7cebe3

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

.idea/misc.xml

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.

lib/src/androidTest/java/com/otaliastudios/transcoder/integration/IssuesTests.kt

+16
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import com.otaliastudios.transcoder.source.AssetFileDescriptorDataSource
1414
import com.otaliastudios.transcoder.source.BlankAudioDataSource
1515
import com.otaliastudios.transcoder.source.ClipDataSource
1616
import com.otaliastudios.transcoder.source.FileDescriptorDataSource
17+
import com.otaliastudios.transcoder.strategy.DefaultAudioStrategy
1718
import com.otaliastudios.transcoder.strategy.DefaultVideoStrategy
1819
import com.otaliastudios.transcoder.validator.WriteAlwaysValidator
1920
import org.junit.Assume
@@ -135,4 +136,19 @@ class IssuesTests {
135136
}
136137
Unit
137138
}
139+
140+
@Test(timeout = 16000)
141+
fun issue75_workaround() = with(Helper(75)) {
142+
transcode {
143+
val vds = input("bbb_720p_30mb.mp4")
144+
addDataSource(ClipDataSource(vds, 0, 500_000))
145+
setVideoTrackStrategy(DefaultVideoStrategy.exact(300, 300).build())
146+
// API 23:
147+
// This video seems to have wrong number of channels in metadata (6) wrt MediaCodec decoder output (2)
148+
// so when using DefaultAudioStrategy.CHANNELS_AS_INPUT we target 6 and try to upscale from 2 to 6, which fails
149+
// The workaround below explicitly sets a number of channels different than CHANNELS_AS_INPUT to make it work
150+
// setAudioTrackStrategy(DefaultAudioStrategy.builder().channels(1).build())
151+
}
152+
Unit
153+
}
138154
}

lib/src/main/java/com/otaliastudios/transcoder/internal/audio/remix/AudioRemixer.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ internal interface AudioRemixer {
2323

2424
companion object {
2525
internal operator fun get(inputChannels: Int, outputChannels: Int): AudioRemixer = when {
26+
inputChannels == outputChannels -> PassThroughAudioRemixer()
2627
inputChannels !in setOf(1, 2) -> error("Input channel count not supported: $inputChannels")
27-
outputChannels !in setOf(1, 2) -> error("Output channel count not supported: $inputChannels")
28+
outputChannels !in setOf(1, 2) -> error("Output channel count not supported: $outputChannels")
2829
inputChannels < outputChannels -> UpMixAudioRemixer()
29-
inputChannels > outputChannels -> DownMixAudioRemixer()
30-
else -> PassThroughAudioRemixer()
30+
else -> DownMixAudioRemixer()
3131
}
3232
}
3333
}

0 commit comments

Comments
 (0)