69 #define OFFSET(x) offsetof(ChannelMapContext, x)
70 #define A AV_OPT_FLAG_AUDIO_PARAM
71 #define F AV_OPT_FLAG_FILTERING_PARAM
73 {
"map",
"A comma-separated list of input channel numbers in output order.",
75 {
"channel_layout",
"Output channel layout.",
90 char *next = strchr(
message, delim);
104 if (!next && delim ==
'-')
107 sscanf(*
map,
"%d%n", ch, &n);
119 if (!next && delim ==
'-')
130 char layout_name[256];
132 if (channel_idx < 0 || channel_idx >=
nb_channels) {
137 "%sput channel '%s' not available from %sput layout '%s'\n",
141 "%sput channel #%d not available from %sput layout '%s'\n",
153 char *mapping, separator =
'|';
157 uint64_t out_ch_mask = 0;
158 uint64_t presence_mask;
161 mapping =
s->mapping_str;
166 char *dash = strchr(mapping,
'-');
188 while ((sep = strchr(sep, separator))) {
198 for (
i = 0;
i < map_entries;
i++) {
199 int in_ch_idx = -1, out_ch_idx = -1;
200 uint64_t in_ch = 0, out_ch = 0;
201 static const char err[] =
"Failed to parse channel map\n";
203 s->map[
i].in_channel_idx = -1;
204 s->map[
i].out_channel_idx = -1;
212 s->map[
i].in_channel_idx = in_ch_idx;
213 s->map[
i].out_channel_idx =
i;
216 if (
get_channel(&mapping, &in_ch, separator) < 0) {
220 s->map[
i].in_channel = in_ch;
221 s->map[
i].out_channel_idx =
i;
229 s->map[
i].in_channel_idx = in_ch_idx;
230 s->map[
i].out_channel_idx = out_ch_idx;
238 s->map[
i].in_channel_idx = in_ch_idx;
239 s->map[
i].out_channel = out_ch;
240 out_ch_mask |= out_ch;
248 s->map[
i].in_channel = in_ch;
249 s->map[
i].out_channel_idx = out_ch_idx;
257 s->map[
i].in_channel = in_ch;
258 s->map[
i].out_channel = out_ch;
259 out_ch_mask |= out_ch;
264 s->nch = map_entries;
265 s->output_layout = out_ch_mask ? out_ch_mask :
268 if (
s->channel_layout_str) {
272 s->channel_layout_str);
283 for (
i = 0;
i <
s->nch;
i++) {
284 s->map[
i].in_channel_idx =
i;
285 s->map[
i].out_channel_idx =
i;
287 }
else if (out_ch_mask && out_ch_mask != fmt) {
290 "Output channel layout '%s' does not match the list of channel mapped: '%s'.\n",
291 s->channel_layout_str, buf);
295 "Output channel layout %s does not match the number of channels mapped %d.\n",
296 s->channel_layout_str,
s->nch);
299 s->output_layout = fmt;
301 if (!
s->output_layout) {
303 "cannot be guessed from the maps.\n");
308 for (
i = 0;
i <
s->nch;
i++) {
310 s->output_layout,
s->map[
i].out_channel);
315 for (
i = 0;
i <
s->nch;
i++) {
320 idx_mask = (1ULL <<
s->map[
i].out_channel_idx);
321 if (presence_mask & idx_mask) {
322 char layout_name[256];
325 i + 1,
s->map[
i].out_channel_idx, layout_name);
328 presence_mask |= idx_mask;
344 &
ctx->outputs[0]->incfg.channel_layouts)) < 0)
348 &
ctx->inputs[0]->outcfg.channel_layouts);
356 const int nch_in = inlink->
channels;
357 const int nch_out =
s->nch;
361 nch_in *
sizeof(
s->source_planes[0]));
363 if (nch_out > nch_in) {
367 if (!new_extended_data) {
383 for (ch = 0; ch < nch_out; ch++) {
385 s->source_planes[
s->map[ch].in_channel_idx];
404 for (
i = 0;
i <
s->nch;
i++) {
418 sizeof(*
s->source_planes));
419 if (!
s->source_planes)
445 .
name =
"channelmap",
451 .priv_class = &channelmap_class,
static const AVFilterPad inputs[]
static const AVFilterPad outputs[]
AVFILTER_DEFINE_CLASS(channelmap)
static int channelmap_config_input(AVFilterLink *inlink)
static const AVFilterPad avfilter_af_channelmap_outputs[]
static const AVFilterPad avfilter_af_channelmap_inputs[]
static int check_idx_and_id(AVFilterContext *ctx, int channel_idx, uint64_t channel, uint64_t ch_layout, int nb_channels, const char *io)
static int get_channel_idx(char **map, int *ch, char delim)
static av_cold int channelmap_init(AVFilterContext *ctx)
AVFilter ff_af_channelmap
static const AVOption channelmap_options[]
static char * split(char *message, char delim)
static int channelmap_filter_frame(AVFilterLink *inlink, AVFrame *buf)
static int get_channel(char **map, uint64_t *ch, char delim)
static int channelmap_query_formats(AVFilterContext *ctx)
static void channelmap_uninit(AVFilterContext *ctx)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Main libavfilter public API header.
audio channel layout utility functions
common internal and external API header
static const uint16_t channel_layouts[7]
mode
Use these values in ebur128_init (or'ed).
channel
Use these values when setting the channel map with ebur128_set_channel().
int av_get_channel_layout_channel_index(uint64_t channel_layout, uint64_t channel)
Get the index of a channel in channel_layout.
uint64_t av_get_channel_layout(const char *name)
Return a channel layout id that matches name, or 0 if no match is found.
void av_get_channel_layout_string(char *buf, int buf_size, int nb_channels, uint64_t channel_layout)
Return a description of a channel layout.
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
int64_t av_get_default_channel_layout(int nb_channels)
Return default channel layout for a given number of channels.
const char * av_get_channel_name(uint64_t channel)
Get the name of a given channel.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
void * av_mallocz_array(size_t nmemb, size_t size)
Allocate a memory block for an array with av_mallocz().
static av_const int av_isdigit(int c)
Locale-independent conversion of ASCII isdigit.
const VDPAUPixFmtMap * map
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define FF_ARRAY_ELEMS(a)
Describe the class of an AVClass context structure.
A list of supported channel layouts.
A link between two filters.
int channels
Number of channels.
uint64_t channel_layout
channel layout of current buffer (see libavutil/channel_layout.h)
AVFilterContext * dst
dest filter
A filter pad used for either input or output.
const char * name
Pad name.
const char * name
Filter name.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int channels
number of audio channels, only used for audio.
uint64_t channel_layout
Channel layout of the audio data.
uint8_t ** extended_data
pointers to the data planes/channels.
char * channel_layout_str
uint64_t out_channel
layout describing the output channel
int in_channel_idx
index of in_channel in the input stream data
uint64_t in_channel
layout describing the input channel