Voici un script (un peu trop long) pour un traitement audio avec avisynth. La fonction UpDownMix permet de modifier le nombre de canaux audio (augmenter ou diminuer).
Exemples d'utilisation :
Source.UpDownMix(normalise=true) --> créer une vidéo dont l'audio est boostée au maximum sans saturation (-> normalisée)
Source.UpDownMix(1.0) --> créer une vidéo dont l'audio est en mono
Source.UpDownMix(2.0) --> créer une vidéo dont l'audio est en stéréo
Source.UpDownMix(3.0, "ac3", normalise=true) --> créer une vidéo dont l'audio est normalisée et pourra être encodée en 3.0 ac3
Source.UpDownMix(5.1, "aac") --> créer une vidéo dont l'audio pourra être encodée en 5.1 aac
Code : Tout sélectionner
#
# UpDownMix(clip Video, float "sortie", string "format", bool "normalise")
#
# - Video (obligatoire) désigne la vidéo à traiter ayant de l'audio
# format wav comptant entre 1 et 6 canaux.
#
# - sortie (optionnel) désigne les canaux de sortie :
# 1.0, 2.0, 3.0, 4.0, 5.0, 5.1 (défaut = idem que video)
#
# - format (optionnel) désigne l'ordre désiré des canaux,
# "wav" (=défaut), "ac3" pour tout type de sortie
# "ogg", "dts", "aac", "aiff" pour les sortie 1.0, 2.0, 4.0, 5.1
#
# - normalise (optionnel) commande un boost maximum sans saturation
# true, false (=défaut)
#
# Canaux d'entrée : entre 1 et 6
# Format d'entrée : wav
#
# Canaux de sortie :
#
# 1.0 (C)
#
# 2.0 (L,R)
#
# 3.0 "wav"=(L,R,C)
# "ac3"=(L,C,R)
#
# 4.0 (L,R,SL,SR)
#
# 5.0 "wav"=(L,R,C,SL,SR)
# "ac3"=(L,C,R,SL,SR)
#
# 5.1 "wav"=(L,R,C,SW,SL,SR)
# "ac3"="ogg"=(L,C,R,SL,SR,SW)
# "dts"="aac"=(C,L,R,SL,SR,SW)
# "aiff"=(L,SL,C,R,SR,SW)
function from10toN(clip Video, int N)
{
C = GetChannel(Video, 1)
return N==1 ? C :\
N==2 ? MergeChannels(C,C) :\
N==3 ? MergeChannels(C,C,C) :\
N==4 ? MergeChannels(C,C,C,C) :\
N==5 ? MergeChannels(C,C,C,C,C) :\
MergeChannels(C,C,C,C,C,C)
}
function from20to10(clip Video)
{
L = GetChannel(Video, 1)
R = GetChannel(Video, 2)
return MixAudio(L,R)
}
function from20to20(clip Video)
{
L = GetChannel(Video, 1)
R = GetChannel(Video, 2)
return MergeChannels(L,R)
}
function from20to30(clip Video, string format)
{
L = GetChannel(Video, 1)
R = GetChannel(Video, 2)
C = MixAudio(L, R)
return format=="ac3" ? MergeChannels(L,C,R) :\
MergeChannels(L,R,C)
}
function from20to40(clip Video)
{
L = GetChannel(Video, 1)
R = GetChannel(Video, 2)
SL = L
SR = R
return MergeChannels(L,R,SL,SR)
}
function from20to50(clip Video, string format)
{
L = GetChannel(Video, 1)
R = GetChannel(Video, 2)
C = MixAudio(L, R)
SL = L
SR = R
return format=="ac3" ? MergeChannels(L,C,R,SL,SR) :\
MergeChannels(L,R,C,SL,SR)
}
function from20to51(clip Video, string format)
{
L = GetChannel(Video, 1)
R = GetChannel(Video, 2)
C = MixAudio(L, R)
SL = L
SR = R
SW = C
return format=="ac3" ? MergeChannels( L, C, R, SL, SR, SW ) :\
format=="ogg" ? MergeChannels( L, C, R, SL, SR, SW ) :\
format=="dts" ? MergeChannels( C, L, R, SL, SR, SW ) :\
format=="aac" ? MergeChannels( C, L, R, SL, SR, SW ) :\
format=="aiff" ? MergeChannels( L, SL, C, R, SR, SW ) :\
MergeChannels( L, R, C, SW, SL, SR )
}
function from30to10(clip Video)
{
L = GetChannel(Video, 1)
R = GetChannel(Video, 2)
C = GetChannel(Video, 3)
C = MixAudio(MixAudio(L, R), C, 2/3., 1/3.)
return C
}
function from30to20(clip Video)
{
L = GetChannel(Video, 1)
R = GetChannel(Video, 2)
C = GetChannel(Video, 3)
L = MixAudio(L, C, .5858, .4142)
R = MixAudio(R, C, .5858, .4142)
return MergeChannels(L,R)
}
function from30to30(clip Video, string format)
{
L = GetChannel(Video, 1)
R = GetChannel(Video, 2)
C = GetChannel(Video, 3)
return format=="ac3" ? MergeChannels(L,C,R) :\
MergeChannels(L,R,C)
}
function from30to40(clip Video)
{
SL = GetChannel(Video, 1)
SR = GetChannel(Video, 2)
C = GetChannel(Video, 3)
L = MixAudio(SL, C, .268, .732)
R = MixAudio(SR, C, .268, .732)
return MergeChannels(L,R,SL,SR)
}
function from30to50(clip Video, string format)
{
SL = GetChannel(Video, 1)
SR = GetChannel(Video, 2)
C = GetChannel(Video, 3)
L = MixAudio(SL, C, .5858, .4142)
R = MixAudio(SR, C, .5858, .4142)
return format=="ac3" ? MergeChannels(L,C,R,SL,SR) :\
MergeChannels(L,R,C,SL,SR)
}
function from30to51(clip Video, string format)
{
SL = GetChannel(Video, 1)
SR = GetChannel(Video, 2)
C = GetChannel(Video, 3)
L = MixAudio(SL, C, .6077, .3923)
R = MixAudio(SR, C, .6077, .3923)
SW = MixAudio(L,R)
return format=="ac3" ? MergeChannels( L, C, R, SL, SR, SW ) :\
format=="ogg" ? MergeChannels( L, C, R, SL, SR, SW ) :\
format=="dts" ? MergeChannels( C, L, R, SL, SR, SW ) :\
format=="aac" ? MergeChannels( C, L, R, SL, SR, SW ) :\
format=="aiff" ? MergeChannels( L, SL, C, R, SR, SW ) :\
MergeChannels( L, R, C, SW, SL, SR )
}
function from40to10(clip Video)
{
L = GetChannel(Video, 1)
R = GetChannel(Video, 2)
SL = GetChannel(Video, 3)
SR = GetChannel(Video, 4)
L = MixAudio(L, SL)
R = MixAudio(R, SR)
return MixAudio(L,R)
}
function from40to20(clip Video)
{
L = GetChannel(Video, 1)
R = GetChannel(Video, 2)
SL = GetChannel(Video, 3)
SR = GetChannel(Video, 4)
L = MixAudio(L, SL)
R = MixAudio(R, SR)
return MergeChannels(L,R)
}
function from40to30(clip Video, string format)
{
L = GetChannel(Video, 1)
R = GetChannel(Video, 2)
SL = GetChannel(Video, 3)
SR = GetChannel(Video, 4)
C = MixAudio(L, R)
L = MixAudio(L, SL, .375, .625)
R = MixAudio(R, SR, .375, .625)
return format=="ac3" ? MergeChannels(L,C,R) :\
MergeChannels(L,R,C)
}
function from40to40(clip Video)
{
L = GetChannel(Video, 1)
R = GetChannel(Video, 2)
SL = GetChannel(Video, 3)
SR = GetChannel(Video, 4)
return MergeChannels(L,R,SL,SR)
}
function from40to50(clip Video, string format)
{
L = GetChannel(Video, 1)
R = GetChannel(Video, 2)
SL = GetChannel(Video, 3)
SR = GetChannel(Video, 4)
C = MixAudio(L, R)
L = MixAudio(L, SL, .875, .125)
R = MixAudio(R, SR, .875, .125)
return format=="ac3" ? MergeChannels(L,C,R,SL,SR) :\
MergeChannels(L,R,C,SL,SR)
}
function from40to51(clip Video, string format)
{
L = GetChannel(Video, 1)
R = GetChannel(Video, 2)
SL = GetChannel(Video, 3)
SR = GetChannel(Video, 4)
C = MixAudio(L,R)
L = MixAudio(L, SL, .75, .25)
R = MixAudio(R, SR, .75, .25)
SW = C
return format=="ac3" ? MergeChannels( L, C, R, SL, SR, SW ) :\
format=="ogg" ? MergeChannels( L, C, R, SL, SR, SW ) :\
format=="dts" ? MergeChannels( C, L, R, SL, SR, SW ) :\
format=="aac" ? MergeChannels( C, L, R, SL, SR, SW ) :\
format=="aiff" ? MergeChannels( L, SL, C, R, SR, SW ) :\
MergeChannels( L, R, C, SW, SL, SR )
}
function from50to10(clip Video)
{
L = GetChannel(Video, 1)
R = GetChannel(Video, 2)
C = GetChannel(Video, 3)
SL = GetChannel(Video, 4)
SR = GetChannel(Video, 5)
L = MixAudio(L, SL)
R = MixAudio(R, SR)
C = MixAudio(MixAudio(L,R), C, 4/5., 1/5.)
return C
}
function from50to20(clip Video)
{
L = GetChannel(Video, 1)
R = GetChannel(Video, 2)
C = GetChannel(Video, 3)
SL = GetChannel(Video, 4)
SR = GetChannel(Video, 5)
L = MixAudio(MixAudio(L, SL), C, .7388, .2612)
R = MixAudio(MixAudio(R, SR), C, .7388, .2612)
return MergeChannels(L,R)
}
function from50to30(clip Video, string format)
{
L = GetChannel(Video, 1)
R = GetChannel(Video, 2)
C = GetChannel(Video, 3)
SL = GetChannel(Video, 4)
SR = GetChannel(Video, 5)
C = MixAudio(MixAudio(L, R), C, .472, .528)
L = MixAudio(L, SL, .472, .528)
R = MixAudio(R, SR, .472, .528)
return format=="ac3" ? MergeChannels(L,C,R) :\
MergeChannels(L,R,C)
}
function from50to40(clip Video)
{
L = GetChannel(Video, 1)
R = GetChannel(Video, 2)
C = GetChannel(Video, 3)
SL = GetChannel(Video, 4)
SR = GetChannel(Video, 5)
SL = MixAudio(SL, L, .6471, .3529)
SR = MixAudio(SR, R, .6471, .3529)
L = MixAudio(L, C, .5424, .4576)
R = MixAudio(R, C, .5424, .4576)
return MergeChannels(L,R,SL,SR)
}
function from50to50(clip Video, string format)
{
L = GetChannel(Video, 1)
R = GetChannel(Video, 2)
C = GetChannel(Video, 3)
SL = GetChannel(Video, 4)
SR = GetChannel(Video, 5)
return format=="ac3" ? MergeChannels(L,C,R,SL,SR) :\
MergeChannels(L,R,C,SL,SR)
}
function from50to51(clip Video, string format)
{
L = GetChannel(Video, 1)
R = GetChannel(Video, 2)
C = GetChannel(Video, 3)
SL = GetChannel(Video, 4)
SR = GetChannel(Video, 5)
SW = MixAudio(L,R)
return format=="ac3" ? MergeChannels( L, C, R, SL, SR, SW ) :\
format=="ogg" ? MergeChannels( L, C, R, SL, SR, SW ) :\
format=="dts" ? MergeChannels( C, L, R, SL, SR, SW ) :\
format=="aac" ? MergeChannels( C, L, R, SL, SR, SW ) :\
format=="aiff" ? MergeChannels( L, SL, C, R, SR, SW ) :\
MergeChannels( L, R, C, SW, SL, SR )
}
function from51to10(clip Video)
{
L = GetChannel(Video, 1)
R = GetChannel(Video, 2)
C = GetChannel(Video, 3)
SW = GetChannel(Video, 4)
SL = GetChannel(Video, 5)
SR = GetChannel(Video, 6)
LR = MixAudio(MixAudio(L, SL), MixAudio(R, SR))
C = MixAudio(C, SW)
return MixAudio(LR, C, 4/6., 2/6.)
}
function from51to20(clip Video)
{
L = GetChannel(Video, 1)
R = GetChannel(Video, 2)
C = GetChannel(Video, 3)
SW = GetChannel(Video, 4)
SL = GetChannel(Video, 5)
SR = GetChannel(Video, 6)
C = MixAudio(C, SW)
L = MixAudio(MixAudio(L, SL), C, .5858, .4142)
R = MixAudio(MixAudio(R, SR), C, .5858, .4142)
return MergeChannels(L,R)
}
function from51to30(clip Video, string format)
{
L = GetChannel(Video, 1)
R = GetChannel(Video, 2)
C = GetChannel(Video, 3)
SW = GetChannel(Video, 4)
SL = GetChannel(Video, 5)
SR = GetChannel(Video, 6)
C = MixAudio(MixAudio(L, R), C, .5858, .4142)
L = MixAudio(MixAudio(L, SW), SL, .5858, .4142)
R = MixAudio(MixAudio(R, SW), SR, .5858, .4142)
return format=="ac3" ? MergeChannels(L,C,R) :\
MergeChannels(L,R,C)
}
function from51to40(clip Video)
{
L = GetChannel(Video, 1)
R = GetChannel(Video, 2)
C = GetChannel(Video, 3)
SW = GetChannel(Video, 4)
SL = GetChannel(Video, 5)
SR = GetChannel(Video, 6)
C = MixAudio(C, SW)
SL = MixAudio(SL, L, .531, .469)
SR = MixAudio(SR, R, .531, .469)
L = MixAudio(L, C, .249, .751)
R = MixAudio(R, C, .249, .751)
return MergeChannels(L,R,SL,SR)
}
function from51to50(clip Video, string format)
{
L = GetChannel(Video, 1)
R = GetChannel(Video, 2)
C = GetChannel(Video, 3)
SW = GetChannel(Video, 4)
SL = GetChannel(Video, 5)
SR = GetChannel(Video, 6)
C = MixAudio(MixAudio(L,R), C, .3422, .6578)
SL = MixAudio(SL, L, .6578, .3422)
SR = MixAudio(SR, R, .6578, .3422)
L = MixAudio(L, SW, .5349, .4651)
R = MixAudio(R, SW, .5349, .4651)
return format=="ac3" ? MergeChannels(L,C,R,SL,SR) :\
MergeChannels(L,R,C,SL,SR)
}
function from51to51(clip Video, string format)
{
L = GetChannel(Video, 1)
R = GetChannel(Video, 2)
C = GetChannel(Video, 3)
SW = GetChannel(Video, 4)
SL = GetChannel(Video, 5)
SR = GetChannel(Video, 6)
return format=="ac3" ? MergeChannels( L, C, R, SL, SR, SW ) :\
format=="ogg" ? MergeChannels( L, C, R, SL, SR, SW ) :\
format=="dts" ? MergeChannels( C, L, R, SL, SR, SW ) :\
format=="aac" ? MergeChannels( C, L, R, SL, SR, SW ) :\
format=="aiff" ? MergeChannels( L, SL, C, R, SR, SW ) :\
MergeChannels( L, R, C, SW, SL, SR )
}
function UpDownMix(clip Video, float "sortie", string "format", bool "normalise")
{
sac = Video.AudioChannels
sortie = Defined(sortie) ? ceil(sortie) : sac
format = Default(format, "wav")
normalise = Default(normalise, false)
A = sac==1 ? from10toN(Video, sortie) :\
sac==2 ? sortie==1 ? from20to10(Video) :\
sortie==2 ? from20to20(Video) :\
sortie==3 ? from20to30(Video, format) :\
sortie==4 ? from20to40(Video, format) :\
sortie==5 ? from20to50(Video, format) :\
sortie==6 ? from20to51(Video, format) :\
nop :\
sac==3 ? sortie==1 ? from30to10(Video) :\
sortie==2 ? from30to20(Video) :\
sortie==3 ? from30to30(Video, format) :\
sortie==4 ? from30to40(Video) :\
sortie==5 ? from30to50(Video, format) :\
sortie==6 ? from30to51(Video, format) :\
nop :\
sac==4 ? sortie==1 ? from40to10(Video) :\
sortie==2 ? from40to20(Video) :\
sortie==3 ? from40to30(Video, format) :\
sortie==4 ? from40to40(Video) :\
sortie==5 ? from40to50(Video, format) :\
sortie==6 ? from40to51(Video, format) :\
nop :\
sac==5 ? sortie==1 ? from50to10(Video) :\
sortie==2 ? from50to20(Video) :\
sortie==3 ? from50to30(Video, format) :\
sortie==4 ? from50to40(Video) :\
sortie==5 ? from50to50(Video, format) :\
sortie==6 ? from50to51(Video, format) :\
nop :\
sac==6 ? sortie==1 ? from51to10(Video) :\
sortie==2 ? from51to20(Video) :\
sortie==3 ? from51to30(Video, format) :\
sortie==4 ? from51to40(Video) :\
sortie==5 ? from51to50(Video, format) :\
sortie==6 ? from51to51(Video, format) :\
nop :\
nop
A = normalise ? A.Normalize : A
Try {Video = Video.HasVideo ? AudioDub( Video, A ) : A
}
Catch(erreur)
{Video = AudioDub( Video, A )
}
return Video
}
function TestChannels( int N, float "volume" )
{# original from DIRK-PITT
# N entier compris entre 1 et 6
# le script renvoie vidéo + audio wav
S=Tone( 10.0, 440, 48000, 1, "Silence", 0.0 )
volume = Default(volume, 0.5)
# === Video ==========================================================
V1=MessageClip( "left / canal 1", 360, 200 ).ChangeFPS( 25 )
V2=MessageClip( "right / canal 2", 360, 200 ).ChangeFPS( 25 )
V3=MessageClip( "centre / canal 3", 360, 200 ).ChangeFPS( 25 )
V4=MessageClip( "subwoofer / canal 4", 360, 200 ).ChangeFPS( 25 )
V5=MessageClip( "sur.left / canal 5", 360, 200 ).ChangeFPS( 25 )
V6=MessageClip( "sur.right / canal 6", 360, 200 ).ChangeFPS( 25 )
V=ConvertToYV12(V1++V2++V3++V4++V5++V6)
# === Audio ==========================================================
L=Tone( 10.0, 440, 48000, 1, "Sine", volume )++S++S++S++S++S
R=S++Tone( 10.0, 440, 48000, 1, "Triangle", volume )++S++S++S++S
C=S++S++Tone( 10.0, 440, 48000, 1, "Sawtooth", volume )++S++S++S
SW=S++S++S++Tone( 10.0, 110, 48000, 1, "Noise", volume )++S++S
SL=S++S++S++S++Tone( 10.0, 880, 48000, 1, "Sine", volume )++S
SR=S++S++S++S++S++Tone( 10.0, 880, 48000, 1, "Triangle", volume )
# === Result =========================================================
Return N==1 ? AudioDub( V, C ) :\
N==2 ? AudioDub( V, MergeChannels( L, R ) ) :\
N==3 ? AudioDub( V, MergeChannels( L, R, C ) ) :\
N==4 ? AudioDub( V, MergeChannels( L, R, SL, SR ) ) :\
N==5 ? AudioDub( V, MergeChannels( L, R, C, SL, SR ) ) :\
AudioDub( V, MergeChannels( L, R, C, SW, SL, SR ) )
}