Commit b904f8af authored by Max Kellermann's avatar Max Kellermann

lib/ffmpeg/Filter: add FilterContext::MakeAformat()

parent ebfbb74f
......@@ -100,6 +100,36 @@ MakeAudioBufferSink(AVFilterGraph &graph_ctx)
graph_ctx);
}
AVFilterContext &
MakeAformat(AudioFormat &audio_format,
AVFilterGraph &graph_ctx)
{
AVSampleFormat dest_format = ToFfmpegSampleFormat(audio_format.format);
if (dest_format == AV_SAMPLE_FMT_NONE) {
switch (audio_format.format) {
case SampleFormat::S24_P32:
audio_format.format = SampleFormat::S32;
dest_format = AV_SAMPLE_FMT_S32;
break;
default:
audio_format.format = SampleFormat::S16;
dest_format = AV_SAMPLE_FMT_S16;
break;
}
}
char args[256];
sprintf(args,
"sample_rates=%u:sample_fmts=%s:channel_layouts=0x%" PRIx64,
audio_format.sample_rate,
av_get_sample_fmt_name(dest_format),
ToFfmpegChannelLayout(audio_format.channels));
return CreateFilter(RequireFilterByName("aformat"), "aformat",
args, nullptr, graph_ctx);
}
void
FilterGraph::ParseSingleInOut(const char *filters, AVFilterContext &in,
AVFilterContext &out)
......
......@@ -93,6 +93,16 @@ MakeAudioBufferSource(AudioFormat &audio_format,
AVFilterContext &
MakeAudioBufferSink(AVFilterGraph &graph_ctx);
/**
* Create an "aformat" filter.
*
* @param the output audio format; may be modified by the function if
* the given format is not supported by libavfilter
*/
AVFilterContext &
MakeAformat(AudioFormat &audio_format,
AVFilterGraph &graph_ctx);
class FilterGraph {
AVFilterGraph *graph = nullptr;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment