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

This commit is contained in:
Max Kellermann 2021-08-24 11:45:28 +02:00
parent ebfbb74f9e
commit b904f8af03
2 changed files with 40 additions and 0 deletions

View File

@ -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)

View File

@ -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;