Log in

View Full Version : How can I replace part of an audio track


dunky
11th February 2017, 13:37
Hi,

I have an AVI file with one video track and multiple audio tracks. In the recording I rabbited on too long and now would like to trim off the end of the recording and replace the last part of one of the audio tracks.

Metadata:
encoder : DxtoryCore ver2.0.0.141
ISRC : Video:Lagarith Lossless Codec Audio0:Line Rec (4- Steinberg UR12 ) Audio1:Line Play (4- Steinberg UR12 ) Audio
2:VAC Line 1 (Virtual Audio Cable)
Duration: 00:43:17.07, start: 0.000000, bitrate: 149095 kb/s
Stream #0:0: Video: lagarith (LAGS / 0x5347414C), rgb24, 1920x1080, 144378 kb/s, 30 fps, 30 tbr, 30 tbn, 30 tbc
Stream #0:1: Audio: pcm_s24le ([1][0][0][0] / 0x0001), 44100 Hz, mono, s32 (24 bit), 1058 kb/s
Stream #0:2: Audio: pcm_s24le ([1][0][0][0] / 0x0001), 44100 Hz, stereo, s32 (24 bit), 2116 kb/s
Stream #0:3: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 48000 Hz, stereo, s16, 1536 kb/s

The code I normally use is:
LoadPlugin("C:\Program Files (x86)\MeGUI\tools\ffms\ffms2.dll")
V = FFVideoSource(source, fpsnum=30, fpsden=1, threads=1).Lanczos4Resize(1280, 720)
A1 = FFAudioSource(source, track=1).Normalize(volume=1.0, show=false)
A2 = FFAudioSource(source, track=2).Normalize(volume=1.0, show=false)
commentary = MonoToStereo(A1, A1).AmplifyDB(1.5)
audio = MixAudio(commentary, A2, 0.9, 0.1)
AudioDub(V, audio)
return last

I can trim the file easily enough using:
ffmpeg.exe -i clip-0012.avi -map 0 -c copy -ss 00:00:00 -t 00:35:50.400 clip-0012-cut.avi

But I'm stuck on replacing the last four seconds of the first audio track (A1) with another audio track. I reckon that this would be easy enough with Audacity but would like to do this within Avisynth.

Cheers and I hope you can help.

raffriff42
11th February 2017, 14:23
You have a pretty good start. Something like this should do it. LoadPlugin("C:\Program Files (x86)\MeGUI\tools\ffms\ffms2.dll")
V = FFVideoSource(source, fpsnum=30, fpsden=1, threads=1).Lanczos4Resize(1280, 720)
A1 = FFAudioSource(source, track=1).Normalize(volume=1.0, show=false)
A2 = FFAudioSource(source, track=2).Normalize(volume=1.0, show=false)

## alternate audio
AX = (...)

## replace last 4 sec. with alternate audio (trimmed maybe?)
A1=A1.AudioTrim (http://avisynth.nl/index.php/Trim#AudioTrim)(0, A1.AudioDuration-4.0) + AX #.AudioTrim(?.?, ?.?)

commentary = MonoToStereo(A1, A1).AmplifyDB(1.5)
audio = MixAudio(commentary, A2, 0.9, 0.1)
AudioDub(V, audio)
return last

dunky
11th February 2017, 15:48
## alternate audio
AX = (...)

## replace last 4 sec. with alternate audio (trimmed maybe?)
A1=A1.AudioTrim (http://avisynth.nl/index.php/Trim#AudioTrim)(0, A1.AudioDuration-4.0) + AX #.AudioTrim(?.?, ?.?)


Thanks for the quick and helpful answer, it worked perfectly.

I was make mountains out of mole hills. :)