[FFmpeg-devel] [PATCH] 5.1->stereo resample

Aurelien Jacobs aurel
Sat Jan 12 14:19:34 CET 2008


Brian Connolly wrote:

> Here is a very simple patch that allows libavcodec/resample.c to
> convert a 5.1 audio stream to stereo. 
> 
> Currently, any attempt to do this is rejected with an error message
> "Resampling with input channels greater than 2 unsupported."
> 
> After applying this patch, the audio_resample routine performs the
> following logic for 6-channel input streams:
> 
> - out-left = front_left + (rear_gain * rear_left) + (center_gain *
> center)
> - out-right = front_right + (rear_gain * rear_right) + (center_gain *
> center)
> 
> ...where rear_gain is 0.5 and center_gain is 0.7 (-3 dB).
> 
> > Index: libavcodec/resample.c
> ===================================================================
> --- libavcodec/resample.c	(revision 11509)
> +++ libavcodec/resample.c	(working copy)
> @@ -37,6 +37,17 @@
>      int input_channels, output_channels, filter_channels;
>  };
>  
> +/*
> +*/
> +static short clip_short(int v) {
> +    if (v < -32768)
> +        v = -32768;
> +    else if (v > 32767)
> +        v = 32767;
> +    return (short) v;
> +}

Use av_clip_int16() instead of redefining your own version of it.

> [...]
>  
> @@ -131,9 +171,9 @@
>  {
>      ReSampleContext *s;
>  
> -    if ( input_channels > 2)
> +	 if ((input_channels > 2) && (input_channels != 6))

Tabs are forbidden in ffmpeg SVN. Please remove all of them.

Aurel




More information about the ffmpeg-devel mailing list