[FFmpeg-devel] [PATCH] ffmpeg: add -map_channel option.

Michael Niedermayer michaelni at gmx.at
Mon Oct 24 18:29:10 CEST 2011


On Mon, Oct 24, 2011 at 04:19:10PM +0200, Michael Niedermayer wrote:
> On Mon, Oct 24, 2011 at 02:05:55PM +0200, Clément Bœsch wrote:
> > On Wed, Oct 19, 2011 at 11:42:15PM +0200, Michael Niedermayer wrote:
> > > [...]
> > > > diff --git a/libswresample/audioconvert.h b/libswresample/audioconvert.h
> > > > index e5fd4df..ca98d54 100644
> > > > --- a/libswresample/audioconvert.h
> > > > +++ b/libswresample/audioconvert.h
> > > > @@ -42,11 +42,14 @@ typedef struct AVAudioConvert AVAudioConvert;
> > > >   * @param in_fmt Input sample format
> > > >   * @param channels Number of channels
> > > >   * @param flags See AV_CPU_FLAG_xx
> > > > + * @param ch_map list of the channels id to pick from the source stream, NULL
> > > > + *               if all channels must be selected
> > > >   * @return NULL on error
> > > >   */
> > > >  AVAudioConvert *swr_audio_convert_alloc(enum AVSampleFormat out_fmt,
> > > >                                          enum AVSampleFormat in_fmt,
> > > > -                                        int channels, int flags);
> > > > +                                        int channels, const int *ch_map,
> > > > +                                        int flags);
> > > >  
> > > >  /**
> > > >   * Free audio sample format converter context.
> > > > diff --git a/libswresample/swresample.c b/libswresample/swresample.c
> > > > index bb5b523..67b9831 100644
> > > > --- a/libswresample/swresample.c
> > > > +++ b/libswresample/swresample.c
> > > > @@ -75,7 +75,7 @@ SwrContext *swr_alloc(void){
> > > >  
> > > >  SwrContext *swr_alloc2(struct SwrContext *s, int64_t out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate,
> > > >                         int64_t  in_ch_layout, enum AVSampleFormat  in_sample_fmt, int  in_sample_rate,
> > > > -                       int log_offset, void *log_ctx){
> > > > +                       const int *channel_map, int log_offset, void *log_ctx){
> > > >      if(!s) s= swr_alloc();
> > > >      if(!s) return NULL;
> > > >  
> > > > @@ -89,6 +89,7 @@ SwrContext *swr_alloc2(struct SwrContext *s, int64_t out_ch_layout, enum AVSampl
> > > >      av_set_int(s, "isf", in_sample_fmt);
> > > >      av_set_int(s, "isr", in_sample_rate);
> > > >  
> > > > +    s->channel_map = channel_map;
> > > >      s-> in.ch_count= av_get_channel_layout_nb_channels(s-> in_ch_layout);
> > > >      s->out.ch_count= av_get_channel_layout_nb_channels(s->out_ch_layout);
> > > >      s->int_sample_fmt = AV_SAMPLE_FMT_S16;
> > > 
> > > > @@ -176,7 +177,7 @@ int swr_init(SwrContext *s){
> > > >      if(!s->out_ch_layout)
> > > >          s->out_ch_layout= av_get_default_channel_layout(s->out.ch_count);
> > > >  
> > > > -    s->rematrix= s->out_ch_layout  !=s->in_ch_layout;
> > > > +    s->rematrix= s->out_ch_layout != s->in_ch_layout && s->channel_map < 0;
> > > 
> > > pointer < 0 ?
> > > 
> > 
> > This should be !s->channel_map of course (s->channel_map was an int in the
> > first version of the patch).
> > 
> > > also shouldnt rematrix be independant of the existence of a channel_map
> > > 
> > 
> > Well, AFAIU, the rematrix is meant to automatically set the audio gain
> > levels for each channel; the channel mapping is "incompatible" with this,
> > it's all about reordering, or maybe with another phrasing: ppl won't
> > expect the levels to change (the number of output channels being fixed by
> > the number of -map_channel and not a specific -ac option)
> 
> if your inputs represents 5.1 and your output represenst 7.0 you need
> the rematrix code

a better and simpler example is stereo input and mono output

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Republics decline into democracies and democracies degenerate into
despotisms. -- Aristotle
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20111024/b2644778/attachment.asc>


More information about the ffmpeg-devel mailing list