Resampler
Converts audio frames between sample rates, channel counts and sample formats with FFmpeg's libswresample.
Resampler(AudioSpec(48_000, 2, SampleFormat.FltP), AudioSpec(44_100, 2, SampleFormat.S16)).use { resampler ->
decoded.forEach { frame -> frame.use { resampler.convert(it)?.use(::write) } }
generateSequence { resampler.flush() }.forEach { it.use(::write) }
}A channel layout is FFmpeg's default for the channel count unless AudioSpec.channelLayoutMask names one, so two channels are stereo and six are 5.1 with back surrounds. A layout change at the same count is converted too, such as side surrounds to back surrounds. A rate change holds some samples back to filter them, so a converted frame can be shorter than the one that went in, and flush returns the samples still held once the input ends. Output frames carry microsecond timestamps: the first one starts at the first input frame's timestamp (or zero when it had none), and every later one follows from the samples before it.
Not thread safe: use one resampler from one thread at a time. Available on the JVM, Android and the native targets; on the web the constructor throws FFmpegError.Unsupported.
Throws
when a rate or channel count is not positive, or a sample format is not one FFmpeg knows.
Converts audio frames between sample rates, channel counts and sample formats with FFmpeg's libswresample.
Resampler(AudioSpec(48_000, 2, SampleFormat.FltP), AudioSpec(44_100, 2, SampleFormat.S16)).use { resampler ->
decoded.forEach { frame -> frame.use { resampler.convert(it)?.use(::write) } }
generateSequence { resampler.flush() }.forEach { it.use(::write) }
}A channel layout is FFmpeg's default for the channel count unless AudioSpec.channelLayoutMask names one, so two channels are stereo and six are 5.1 with back surrounds. A layout change at the same count is converted too, such as side surrounds to back surrounds. A rate change holds some samples back to filter them, so a converted frame can be shorter than the one that went in, and flush returns the samples still held once the input ends. Output frames carry microsecond timestamps: the first one starts at the first input frame's timestamp (or zero when it had none), and every later one follows from the samples before it.
Not thread safe: use one resampler from one thread at a time. Available on the JVM, Android and the native targets; on the web the constructor throws FFmpegError.Unsupported.
Throws
when a rate or channel count is not positive, or a sample format is not one FFmpeg knows.
Converts audio frames between sample rates, channel counts and sample formats with FFmpeg's libswresample.
Resampler(AudioSpec(48_000, 2, SampleFormat.FltP), AudioSpec(44_100, 2, SampleFormat.S16)).use { resampler ->
decoded.forEach { frame -> frame.use { resampler.convert(it)?.use(::write) } }
generateSequence { resampler.flush() }.forEach { it.use(::write) }
}A channel layout is FFmpeg's default for the channel count unless AudioSpec.channelLayoutMask names one, so two channels are stereo and six are 5.1 with back surrounds. A layout change at the same count is converted too, such as side surrounds to back surrounds. A rate change holds some samples back to filter them, so a converted frame can be shorter than the one that went in, and flush returns the samples still held once the input ends. Output frames carry microsecond timestamps: the first one starts at the first input frame's timestamp (or zero when it had none), and every later one follows from the samples before it.
Not thread safe: use one resampler from one thread at a time. Available on the JVM, Android and the native targets; on the web the constructor throws FFmpegError.Unsupported.
Throws
when a rate or channel count is not positive, or a sample format is not one FFmpeg knows.
Converts audio frames between sample rates, channel counts and sample formats with FFmpeg's libswresample.
Resampler(AudioSpec(48_000, 2, SampleFormat.FltP), AudioSpec(44_100, 2, SampleFormat.S16)).use { resampler ->
decoded.forEach { frame -> frame.use { resampler.convert(it)?.use(::write) } }
generateSequence { resampler.flush() }.forEach { it.use(::write) }
}A channel layout is FFmpeg's default for the channel count unless AudioSpec.channelLayoutMask names one, so two channels are stereo and six are 5.1 with back surrounds. A layout change at the same count is converted too, such as side surrounds to back surrounds. A rate change holds some samples back to filter them, so a converted frame can be shorter than the one that went in, and flush returns the samples still held once the input ends. Output frames carry microsecond timestamps: the first one starts at the first input frame's timestamp (or zero when it had none), and every later one follows from the samples before it.
Not thread safe: use one resampler from one thread at a time. Available on the JVM, Android and the native targets; on the web the constructor throws FFmpegError.Unsupported.
Throws
when a rate or channel count is not positive, or a sample format is not one FFmpeg knows.
Constructors
Functions
Converts frame, which stays the caller's to close. The caller owns the frame this returns, and gets null when the resampler held every sample back.
Converts frame, which stays the caller's to close. The caller owns the frame this returns, and gets null when the resampler held every sample back.
Converts frame, which stays the caller's to close. The caller owns the frame this returns, and gets null when the resampler held every sample back.
The samples the resampler still holds, as one frame the caller owns, or null when it holds none. Call it until it returns null once the input has ended.
The samples the resampler still holds, as one frame the caller owns, or null when it holds none. Call it until it returns null once the input has ended.
The samples the resampler still holds, as one frame the caller owns, or null when it holds none. Call it until it returns null once the input has ended.