Hello guest, if you like this forum, why don't you register? https://fanrestore.com/member.php?action=register (December 14, 2021) x


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AviSynth PAL <-> NTSC audio conversion
#1
This simple Avisynth script converts an audio track from PAL to NTSC (or NTSC to PAL).

Required: nicaudio, to load audio files other than WAV
Optional: other audio import filters

Code:
################################################################################
# Avysinth script
#
# Converting audio tempo and/or pitch from PAL to NTSC and from NTSC to PAL
# note: NTSC works for both NTSC (29.97) and FILM (23.976) framerates
################################################################################

# choose ONLY one line and decomment it
# there are more audio loaders for avisynth,
# but these should cover 99% of restoration needs
################################################################################

# AC3 file load
#temp=nicac3source("filename.ac3")

# DTS file load
#temp=nicdtssource("filename.dts")

# WAV file load
#temp=wavsource("filename.wav")

################################################################################


# choose ONLY one line and decomment it
################################################################################

# change NTSC to PAL tempo, NOT pitch
#aud=temp.TimeStretch(tempo=100.0*25.0/(24000.0/1001.0))

# change NTSC to PAL tempo AND pitch too
#aud=temp.TimeStretch(tempo=100.0*25.0/(24000.0/1001.0),pitch=100.0*25.0/(24000.0/1001.0))

# changes PAL to NTSC tempo, NOT pitch
#aud=temp.TimeStretch(tempo=(100.0*24000.0/1001.0)/25.000)

# change PAL to NTSC tempo AND pitch too
#aud=temp.TimeStretch(tempo=(100.0*24000.0/1001.0)/25.000,pitch=(100.0*24000.0/1001.0)/25.000)

################################################################################

# create an empty video
vid=blankclip.loop

# mux video and audio together
audiodub(vid,aud)

# trim video to be long as audio
AudioTrim(0,last.AudioDuration)

# output is a WAV file

I'd like to see it as a function, with a call like soundconvert(audioclip,"p2n"yes) or something, where "p2n" is PAL to NTSC, and yes is for pitch conversion. Any good programmer here?
Reply
Thanks given by: PDB
#2
(2016-11-13, 02:17 AM)spoRv Wrote: I'd like to see it as a function, with a call like soundconvert(audioclip,"p2n"yes) or something, where "p2n" is PAL to NTSC, and yes is for pitch conversion. Any good programmer here?

This may or may not work. I've never written anything in Avisynth before.

Code:
#allowed file formats - ac3, wav, dts
#allowed commands - NTSC_TO_PAL_NO_PITCH, NTSC_TO_PAL_WITH_PITCH, PAL_TO_NTSC_NO_PITCH, PAL_TO_NTSC_WITH_PITCH
#filename must be full, with extension

function SoundConvert(string filename, string command)
{
extension = RightStr(filename, 3)

StrCmp(extension, "ac3") == 0 ? temp=nicac3source(filename) : NOP
StrCmp(extension, "dts") == 0 ? temp=nicdtssource(filename) : NOP
StrCmp(extension, "wav") == 0 ? temp=wavsource(filename) : NOP

################################################################################

StrCmp(command, "NTSC_TO_PAL_NO_PITCH") == 0 ? aud=temp.TimeStretch(tempo=100.0*25.0/(24000.0/1001.0)) : NOP

StrCmp(command, "NTSC_TO_PAL_WITH_PITCH") == 0 ? aud=temp.TimeStretch(tempo=100.0*25.0/(24000.0/1001.0),pitch=100.0*25.0/(24000.0/1001.0)) : NOP

StrCmp(command, "PAL_TO_NTSC_NO_PITCH") == 0 ? aud=temp.TimeStretch(tempo=(100.0*24000.0/1001.0)/25.000) : NOP

StrCmp(command, "PAL_TO_NTSC_WITH_PITCH") == 0 ? aud=temp.TimeStretch(tempo=(100.0*24000.0/1001.0)/25.000,pitch=(100.0*24000.0/1001.0)/25.000) : NOP

################################################################################

# create an empty video
vid=blankclip.loop

# mux video and audio together
audiodub(vid,aud)

# trim video to be long as audio
return AudioTrim(0,last.AudioDuration)

# output is a WAV file
}
Reply
Thanks given by:
#3
WARNING! To anybody who had the script in their computer: there was an error in the "change PAL to NTSC tempo AND pitch" formula; now both posts #1 and #2 are corrected, so you should replace your script.
Reply
Thanks given by:
#4
I am far from all these scripts, but I know by experience that many programs even know how to drag the roads to other purity, but almost all of them do not retain the tone of voice and after distortion the voice is distorted, does your script also have a distortion?
Reply
Thanks given by:
#5
No distorsion - but you must check if only tempo should be changed, or also pitch.
Reply
Thanks given by:
#6
Updated script in the first post, adding 24fps... yes, I know, it's an easy add, but for the lazy ones (like me) it is nice to get everything ready! Wink
And, yes, too lazy to make a simple function for it!

Code:
################################################################################
# Avysinth script
#
# Converting audio tempo and/or pitch from different sources
# note: NTSC works for both NTSC (29.97) and FILM (23.976) framerates
################################################################################

# choose ONLY one line and decomment it
# there are more audio loaders for avisynth,
# but these should cover 99% of restoration needs
################################################################################

# AC3 file load
#temp=nicac3source("filename.ac3")

# DTS file load
#temp=nicdtssource("filename.dts")

# WAV file load
#temp=wavsource("filename.wav")

# FF file load - should works with almost all other audio codecs
#temp=ffaudiosource("filename.putanaudioextensionhere")

################################################################################

# choose ONLY one line and decomment it
################################################################################

# changes NTSC to PAL tempo, NOT pitch
#aud=temp.TimeStretch(tempo=100.0*25.0/(24000.0/1001.0))

# changes NTSC to PAL tempo AND pitch too
#aud=temp.TimeStretch(tempo=100.0*25.0/(24000.0/1001.0),pitch=100.0*25.0/(24000.0/1001.0))

# changes NTSC to 24fps tempo, NOT pitch
#aud=temp.TimeStretch(tempo=100.0*24.0/(24000.0/1001.0))

# changes NTSC to 24fps tempo AND pitch too
#aud=temp.TimeStretch(tempo=100.0*24.0/(24000.0/1001.0),pitch=100.0*25.0/(24000.0/1001.0))

# changes PAL to NTSC tempo, NOT pitch
#aud=temp.TimeStretch(tempo=(100.0*24000.0/1001.0)/25.000)

# changes PAL to NTSC tempo AND pitch too
#aud=temp.TimeStretch(tempo=(100.0*24000.0/1001.0)/25.000,pitch=(100.0*24000.0/1001.0)/25.000)

# changes PAL to 24fps tempo, NOT pitch
#aud=temp.TimeStretch(tempo=(100.0*24000.0/1000.0)/25.000)

# changes PAL to 24fps tempo AND pitch too
#aud=temp.TimeStretch(tempo=(100.0*24000.0/1000.0)/25.000,pitch=(100.0*24000.0/1000.0)/25.000)

# changes 24fps to PAL tempo, NOT pitch
#aud=temp.TimeStretch(tempo=100.0*25.0/(24000.0/1000.0))

# changes 24fps to PAL tempo AND pitch too
#aud=temp.TimeStretch(tempo=100.0*25.0/(24000.0/1000.0),pitch=100.0*25.0/(24000.0/1000.0))

# changes 24fps to NTSC tempo, NOT pitch
#aud=temp.TimeStretch(tempo=(100.0*24000.0/1001.0)/24.000)

# changes 24fps to NTSC tempo AND pitch too
#aud=temp.TimeStretch(tempo=(100.0*24000.0/1001.0)/24.000,pitch=(100.0*24000.0/1001.0)/24.000)

################################################################################

# create an empty video
vid=blankclip.loop

# mux video and audio together
audiodub(vid,aud)

# trim video to be long as audio
AudioTrim(0,last.AudioDuration)

# output is a WAV file
Reply
Thanks given by:
#7
You can also perform these conversions with BeHappy, which uses AviSynth under the hood and enables you to preview the script so you can see how a given conversion is taking place.
Reply
Thanks given by:
#8
(2018-12-24, 03:38 PM)Chewtobacca Wrote: You can also perform these conversions with BeHappy, which uses AviSynth under the hood and enables you to preview the script so you can see how a given conversion is taking place.

Good! Well, for some old dinosaurs like me (and you Wink ) the script could always be useful... maybe?
Reply
Thanks given by:
#9
Yes; it's dinosaur friendly.  If you're unsure, you can set up BeHappy, preview the script, and copy the relevant line into a project – a convenient safeguard against user error.
Reply
Thanks given by:
#10
Hi Guys I'm getting the following error.

Im running Avisynth+ 64bit Latest Version
[Image: i5hq.jpg]

I copied the code in the second post and saved it as soundconvert.avsi and put it into the plugins64+ in avisynth
Ive also added nicaudio Smile
And trying to run the following script

Code:
MPEG2Source("VTS_10_1.d2v").TFM(d2v="VTS_10_1.d2v").ColorMatrix(Source=2, dest=0).spline64resize(1024, 576).Assumefps(23.976)
LWLibavAudioSource("VTS_10_1 T81 2_0ch 192Kbps DELAY 0ms.ac3").SoundConvert("PAL_TO_NTSC_WITH_PITCH")
AudioDub(V,A)
FFT3Dgpu(sigma=1.5, plane=4, bt=4, mode=1, bw=16, bh=16, precision=2, ow=8, oh=8)
SR(1280, 720)
prefetch(8)

Im still learning AVIsynth so it's probably a problem with my script.
Reply
Thanks given by:


Possibly Related Threads…
Thread Author Replies Views Last Post
  eac3to The Audio Delay Thread Chewtobacca 29 29,976 2020-10-20, 12:27 AM
Last Post: Chewtobacca

Forum Jump:


Users browsing this thread: 1 Guest(s)