GetChannel

From Avisynth wiki
(Difference between revisions)
Jump to: navigation, search
m (Make section headings; add internal link to Remarks section)
(add link to avs+ documentation)
 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Template:Func3Def|GetChannel(clip ''clip'', int ''ch1'' [, int ''ch2'', ...])|GetLeftChannel(clip ''clip'')|GetRightChannel(clip ''clip'')}}
+
<div style="max-width:68em" >
 +
<div {{BlueBox2|40|0|3px solid purple}} >
 +
{{AvsPlusFullname}}<br>
 +
Up-to-date documentation: [https://avisynthplus.readthedocs.io/en/latest/avisynthdoc/corefilters/getchannel.html https://avisynthplus.readthedocs.io]
 +
</div>
  
GetChannel is present starting from v2.5 and it returns one or more channels of a multichannel signal. Prior to v2.5 GetLeftChannel returns the left and GetRightChannel the right channel from a stereo signal. GetChannels is an alias to GetChannel and they can be used interchangeably.
 
  
The ordering of the channels is determined by the ordering of the input file, because AviSynth doesn't assume any ordering (see [[GetChannel#Remarks|Remarks]]). In case of stereo 2.0 WAV and 5.1 WAV files the ordering should be as follows:
+
{{Func4Def
 +
|GetChannel(clip ''clip'', int ''ch1'' [, int ''ch2'', ...] )
 +
|GetChannels(clip ''clip'', int ''ch1'' [, int ''ch2'', ...] )
 +
|GetLeftChannel(clip ''clip'')
 +
|GetRightChannel(clip ''clip'')
 +
}}
  
'''WAV, 2 channels (stereo):'''
+
*'''GetChannel''' returns one or more channels of a multichannel signal.
{| border=1 cellspacing=1 cellpadding=4
+
*'''GetLeftChannel''' returns the left channel from a stereo signal, and '''GetRightChannel''' returns the right.
| 1 || left channel
+
*'''GetChannels''' is an alias for '''GetChannel''' and can be used interchangeably.
 +
 
 +
 
 +
The ordering of the channels is determined by the ordering of the input file, because AviSynth doesn't assume any ordering (see [[GetChannel#Remarks|Remarks]]).
 +
 
 +
In case of WAV files, the ordering should be as follows:
 +
:{|class="wikitable" style="width:27em"
 +
|-
 +
! colspan="2" style="text-align:left" |&nbsp; WAV, 2 channels (stereo)&nbsp;
 +
|-
 +
|style="width:2em"| 1 || left
 
|-
 
|-
| 2 || right channel
+
| 2 || right
 
|}
 
|}
  
'''WAV, 5.1 channels:'''
+
:{|class="wikitable" style="width:27em"
{|border=1 cellspacing=1 cellpadding=4
+
| 1 || front left channel
+
 
|-
 
|-
| 2 || front right channel 
+
! colspan="2" style="text-align:left" |&nbsp; WAV, 5.1 channels&nbsp;
 
|-
 
|-
| 3 || front center channel
+
|style="width:2em"| 1 || front left
 +
|-
 +
| 2 || front right
 +
|-
 +
| 3 || front center
 
|-
 
|-
 
| 4 || LFE (Low Frequency Enhancement; Subwoofer)
 
| 4 || LFE (Low Frequency Enhancement; Subwoofer)
 
|-
 
|-
| 5 || rear left channel
+
| 5 || rear left
 
|-
 
|-
| 6 || rear right channel
+
| 6 || rear right
 
|}
 
|}
 +
</div>
  
  
===Examples===
+
==== Remarks ====
 +
<div style="max-width:68em" >
 +
Every file format has a different internal channel ordering. The following table gives this internal ordering for some formats (useful for plugin writers), but it is the decoder's task to return the expected channel order. If you use decoders like [[NicAudio]]/[[BassAudio]] or [[Ffdshow|ffdshow]]/[http://www.ac3filter.net/ AC3Filter] you don't need to worry about this.
 +
</div>
  
<code>
+
:{|class="wikitable"
# Removes right channel information, and return as mono clip with only left channel:
+
! Format !! Channel 1 !! Channel 2 !! Channel 3 !! Channel 4 !! Channel 5 !! Channel 6  
video = [[AviSource]]("c:\filename.avi")
+
stereo = WavSource("c:\afx-ab3_t4.wav")
+
mono = GetLeftChannel(stereo)
+
return [[AudioDub]](video, mono)
+
 
+
# Using v2.5 this becomes:
+
video = AviSource("c:\filename.avi")
+
stereo = [[WavSource]]("c:\afx-ab3_t4.wav")
+
mono = GetChannel(stereo, 1)
+
return AudioDub(video, mono)
+
 
+
# You could also obtain the channels from the avi file itself:
+
video = AviSource("c:\filename.avi")
+
return GetChannel(video, 1)
+
 
+
# Converts avi with 5.1 audio to a stereo signal:
+
# (But see below for channel ordering, and [http://forum.doom9.org/showthread.php?p=1243880#post1243880 here] for more complex downmix functions.)
+
video = AviSource("c:\divx_51.avi")
+
stereo = GetChannel(video, 1, 2)
+
return AudioDub(video, stereo)
+
 
+
# Converts avi with "uncompressed 5.1 wav" audio to a stereo signal:
+
video = AviSource("c:\divx_wav.avi")
+
audio = WavSource("c:\divx_wav.avi")
+
stereo = GetChannel(audio, 1, 2)
+
return AudioDub(video, stereo)
+
</code>
+
 
+
===Remarks===
+
 
+
Every file format has a different internal channel ordering. The following table gives this internal ordering for some formats (useful for plugin writers), but it is a decoder task supply to AviSynth the expected channel order (like WAV), if you use decoders like NicAudio/BassAudio or ffdshow/AC3_filter you don't need to worry about this:
+
 
+
{|border=1 cellspacing=1 cellpadding=4
+
! Reference: !! Channel 1 !! Channel 2 !! Channel 3 !! Channel 4 !! Channel 5 !! Channel 6  
+
 
|-
 
|-
| [http://www.cs.bath.ac.uk/~jpff/NOS-DREAM/researchdev/wave-ex/wave_ex.html 5.1 WAV]  
+
| [http://www.cs.bath.ac.uk/~jpff/NOS-DREAM/researchdev/wave-ex/wave_ex.html 5.1 WAV]
| front left channel
+
| front left
| front right channel
+
| front right
| front center channel
+
| front center&nbsp;
 
| LFE  
 
| LFE  
| rear left channel
+
| rear left
| rear right channel
+
| rear right
 
|-
 
|-
| [http://www.atsc.org/standards/a_52a.pdf 5.1 AC3]  
+
| [https://web.archive.org/web/20051108165008/http://www.atsc.org/standards/a_52a.pdf 5.1 AC3]  
| front left channel
+
| front left
| front center channel
+
| front center&nbsp;
| front right channel
+
| front right
| rear left channel
+
| rear left
| rear right channel
+
| rear right&nbsp;
 
| LFE  
 
| LFE  
 
|-
 
|-
| [http://webapp.etsi.org/action%5CPU/20020827/ts_102114v010101p.pdf 5.1 DTS]  
+
| [http://www.etsi.org/deliver/etsi_ts/102100_102199/102114/01.01.01_60/ts_102114v010101p.pdf 5.1 DTS] {{BoldColor|blue|100|&sup1;}}
| front center channel
+
| front center&nbsp;
| front left channel
+
| front left
| front right channel
+
| front right
| rear left channel
+
| rear left
| rear right channel
+
| rear right
 
| LFE  
 
| LFE  
 
|-
 
|-
| [http://www.hydrogenaudio.org/index.php?showtopic=10986 5.1 AAC]  
+
| [http://web.archive.org/web/20070830151620/http://www.hydrogenaudio.org/forums/index.php?showtopic=10986 5.1 AAC] {{BoldColor|blue|100|&sup2;}}
| front center channel
+
| front center&nbsp;
| front left channel
+
| front left
| front right channel
+
| front right
| rear left channel
+
| rear left
| rear right channel
+
| rear right
 
| LFE  
 
| LFE  
 
|-
 
|-
| [http://preserve.harvard.edu/standards/Audio%20IFF%20Specification%201%203.pdf 5.1 AIFF]  
+
| [http://web.archive.org/web/20030817071619/http://preserve.harvard.edu/standards/Audio%20IFF%20Specification%201%203.pdf 5.1 AIFF]  
| front left channel
+
| front left
| rear left channel
+
| rear left
| front center channel
+
| front center&nbsp;
| front right channel
+
| front right&nbsp;
| rear right channel
+
| rear right
 
| LFE
 
| LFE
 
|-
 
|-
 
| [http://flac.sourceforge.net/format.html 5.1 FLAC]  
 
| [http://flac.sourceforge.net/format.html 5.1 FLAC]  
| front left channel
+
| front left
| front right channel
+
| front right
| front center channel
+
| front center&nbsp;
 
| LFE
 
| LFE
| rear left channel
+
| rear left
| rear right channel
+
| rear right&nbsp;
 
|-
 
|-
| [http://lists.mplayerhq.hu/pipermail/mplayer-users/2006-October/063511.html 5.1 WMA]
+
| [http://lists.mplayerhq.hu/pipermail/mplayer-users/2006-October/063511.html 5.1 WMA] &nbsp;
| front left channel
+
| front left
| front right channel
+
| front right
| front center channel
+
| front center&nbsp;
 
| LFE
 
| LFE
| rear left channel
+
| rear left
| rear right channel
+
| rear right&nbsp;
 +
|-
 +
|colspan="7"|
 +
{{BoldColor|blue|100|&sup1;}} 5.1 DTS: the LFE is on a separate stream (much like on multichannel MPEG2).<br>
 +
{{BoldColor|blue|100|&sup2;}} There is no free version of the AAC specification available online.
 
|}
 
|}
  
* 5.1 DTS: the LFE is on a separate stream (much like on multichannel MPEG2).
+
 
* A free version of the AAC specifications are unavailable online.
+
==== Examples ====
 +
* Get mono audio from left channel of a WAV file,
 +
<div {{ListItemContinue}} >
 +
and dub to video from AVI:
 +
</div>
 +
<div {{BoxWidthIndent|36|2}} >
 +
video = [[AviSource]]("c:\video.avi")
 +
stereo = [[WavSource]]("c:\audio2ch.wav")
 +
mono = GetLeftChannel(stereo)
 +
return [[AudioDub]](video, mono)
 +
</div>
 +
 
 +
* Do the same, alternate syntax:
 +
<div {{BoxWidthIndent|36|2}} >
 +
video = AviSource("c:\video.avi")
 +
stereo = WavSource("c:\audio2ch.wav")
 +
mono = GetChannel(stereo, 1)
 +
return AudioDub(video, mono)
 +
</div>
 +
 
 +
* Do the same with the audio channels from the AVI file itself:
 +
<div {{BoxWidthIndent|36|2}} >
 +
video = AviSource("c:\video+audio2ch.avi")
 +
return GetChannel(video, 1)
 +
</div>
 +
 
 +
* Convert AVI with 5.1 audio to stereo (copy ''front left'' and ''front right'')
 +
<div {{ListItemContinue}} >
 +
(But see [[#Remarks|Remarks]] for channel ordering, and examples below and [http://forum.doom9.org/showthread.php?p=1243880#post1243880 here] for more complex downmix functions.)
 +
</div>
 +
<div {{BoxWidthIndent|36|2}} >
 +
video = AviSource("c:\video+audio6ch.avi")
 +
stereo = GetChannel(video, 1, 2)
 +
return AudioDub(video, stereo)
 +
</div>
 +
 
 +
* Get ''front left'' and ''front right'' audio from a 5.1 AVI:
 +
<div {{BoxWidthIndent|36|2}} >
 +
video = AviSource("c:\video+audio6ch.avi")
 +
audio = WavSource("c:\video+audio6ch.avi")
 +
stereo = GetChannel(audio, 1, 2)
 +
return AudioDub(video, stereo)
 +
</div>
 +
 
 +
* Mix 5.1 to stereo - see discussion [http://forum.doom9.org/showthread.php?p=1735072#post1735072 here].
 +
<div {{ListItemContinue}} >
 +
Note returned audio has sample type [[Float]].<br>
 +
[[Normalize]] is recommended before [[ConvertAudio|converting to 16-bit]] to avoid possible overload.
 +
</div>
 +
<div {{BoxWidthIndent|36|2}} >
 +
AviSource("c:\video+audio6ch.avi")
 +
DownMix
 +
[[Normalize]]
 +
[[ConvertAudioTo16bit]]
 +
return Last
 +
function DownMix(clip a,
 +
\    float "centergain", float "surroundgain")
 +
{
 +
    a.[[ConvertAudioToFloat]]
 +
 +
    ## 5.1 WAV channel layout:
 +
    fl = GetChannel(1)
 +
    fr = GetChannel(2)
 +
    fc = GetChannel(3)
 +
    lf = GetChannel(4) ## (LFE not used)
 +
    sl = GetChannel(5)
 +
    sr = GetChannel(6)
 +
 +
    ## add center
 +
    gc = Default(centergain, 1.0) * 0.7071
 +
    fl = MixAudio(fl, fc, 1.0, gc)
 +
    fr = MixAudio(fr, fc, 1.0, gc)
 +
 +
    ## add surround
 +
    gs = Default(surroundgain, 1.0) * 0.7071
 +
    fl = [[MixAudio]](fl, sl, 1.0, gs)
 +
    fr = MixAudio(fr, sr, 1.0, gs)
 +
 +
    return [[AudioDub]](a, [[MergeChannels]](fl, fr))
 +
}
 +
</div>
  
  
 
[[Category:Internal filters]]
 
[[Category:Internal filters]]
 +
[[Category:Audio_filters]]

Latest revision as of 06:29, 18 September 2022

AviSynth+
Up-to-date documentation: https://avisynthplus.readthedocs.io


GetChannel(clip clip, int ch1 [, int ch2, ...] )
GetChannels(clip clip, int ch1 [, int ch2, ...] )
GetLeftChannel(clip clip)
GetRightChannel(clip clip)

  • GetChannel returns one or more channels of a multichannel signal.
  • GetLeftChannel returns the left channel from a stereo signal, and GetRightChannel returns the right.
  • GetChannels is an alias for GetChannel and can be used interchangeably.


The ordering of the channels is determined by the ordering of the input file, because AviSynth doesn't assume any ordering (see Remarks).

In case of WAV files, the ordering should be as follows:

  WAV, 2 channels (stereo) 
1 left
2 right
  WAV, 5.1 channels 
1 front left
2 front right
3 front center
4 LFE (Low Frequency Enhancement; Subwoofer)
5 rear left
6 rear right


[edit] Remarks

Every file format has a different internal channel ordering. The following table gives this internal ordering for some formats (useful for plugin writers), but it is the decoder's task to return the expected channel order. If you use decoders like NicAudio/BassAudio or ffdshow/AC3Filter you don't need to worry about this.

Format Channel 1 Channel 2 Channel 3 Channel 4 Channel 5 Channel 6
5.1 WAV front left front right front center  LFE rear left rear right
5.1 AC3 front left front center  front right rear left rear right  LFE
5.1 DTS ¹ front center  front left front right rear left rear right LFE
5.1 AAC ² front center  front left front right rear left rear right LFE
5.1 AIFF front left rear left front center  front right  rear right LFE
5.1 FLAC front left front right front center  LFE rear left rear right 
5.1 WMA   front left front right front center  LFE rear left rear right 

¹ 5.1 DTS: the LFE is on a separate stream (much like on multichannel MPEG2).
² There is no free version of the AAC specification available online.


[edit] Examples

  • Get mono audio from left channel of a WAV file,

and dub to video from AVI:

video = AviSource("c:\video.avi")
stereo = WavSource("c:\audio2ch.wav")
mono = GetLeftChannel(stereo)
return AudioDub(video, mono)
  • Do the same, alternate syntax:
video = AviSource("c:\video.avi")
stereo = WavSource("c:\audio2ch.wav")
mono = GetChannel(stereo, 1)
return AudioDub(video, mono)
  • Do the same with the audio channels from the AVI file itself:
video = AviSource("c:\video+audio2ch.avi")
return GetChannel(video, 1)
  • Convert AVI with 5.1 audio to stereo (copy front left and front right)

(But see Remarks for channel ordering, and examples below and here for more complex downmix functions.)

video = AviSource("c:\video+audio6ch.avi")
stereo = GetChannel(video, 1, 2)
return AudioDub(video, stereo)
  • Get front left and front right audio from a 5.1 AVI:
video = AviSource("c:\video+audio6ch.avi")
audio = WavSource("c:\video+audio6ch.avi")
stereo = GetChannel(audio, 1, 2)
return AudioDub(video, stereo)
  • Mix 5.1 to stereo - see discussion here.

Note returned audio has sample type Float.
Normalize is recommended before converting to 16-bit to avoid possible overload.

AviSource("c:\video+audio6ch.avi")
DownMix
Normalize
ConvertAudioTo16bit
return Last
function DownMix(clip a, 
\     float "centergain", float "surroundgain")
{
   a.ConvertAudioToFloat

   ## 5.1 WAV channel layout:
   fl = GetChannel(1)
   fr = GetChannel(2)
   fc = GetChannel(3)
   lf = GetChannel(4) ## (LFE not used)
   sl = GetChannel(5)
   sr = GetChannel(6)

   ## add center
   gc = Default(centergain, 1.0) * 0.7071
   fl = MixAudio(fl, fc, 1.0, gc)
   fr = MixAudio(fr, fc, 1.0, gc)

   ## add surround
   gs = Default(surroundgain, 1.0) * 0.7071
   fl = MixAudio(fl, sl, 1.0, gs)
   fr = MixAudio(fr, sr, 1.0, gs)

   return AudioDub(a, MergeChannels(fl, fr))
}
Personal tools