Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > General > Audio encoding

Reply
 
Thread Tools Search this Thread Display Modes
Old 8th February 2020, 18:42   #1  |  Link
LeXXuz
21 years and counting...
 
LeXXuz's Avatar
 
Join Date: Oct 2002
Location: Germany
Posts: 716
What do you guys use to edit/sync audio tracks?

Well... the last time I had to sync an audio track to a video file was way over 10 years ago and I can't even remember which tools I used back in those days.

So I was wondering what would be a good tool to do this job nowadays?

I'd like to add audio tracks taken from tv recordings to some of my favourite films from DVD/BD.

Adding simple delays does not work because of ad-breaks and what not in those tv recordings they get out of sync after every couple of minutes or so.

I need to cut/add audio frames at certain different positions to get those tracks back in sync again.

Ideally that tool should be able to play matroska files with common codecs to help in the syncing process.

I don't mind a commercial solution but it shouldn't be too expensive as I probably only need it a few times.

Any recommendations?
LeXXuz is offline   Reply With Quote
Old 8th February 2020, 21:35   #2  |  Link
tebasuna51
Moderator
 
tebasuna51's Avatar
 
Join Date: Feb 2005
Location: Spain
Posts: 6,890
I use a audio editor to sincronize the original audio track with the local track captured from tv.

Audacity is free.
__________________
BeHappy, AviSynth audio transcoder.
tebasuna51 is offline   Reply With Quote
Old 9th February 2020, 20:02   #3  |  Link
LeXXuz
21 years and counting...
 
LeXXuz's Avatar
 
Join Date: Oct 2002
Location: Germany
Posts: 716
I had trouble getting used to Audacity. And I was unable to find an option for video preview to make syncing much easier.

I still have an old version of Sound Forge but it doesn't work with modern containers and codecs.

What is the audio editor you use for your projects?
LeXXuz is offline   Reply With Quote
Old 10th February 2020, 01:04   #4  |  Link
Richard1485
Guest
 
Posts: n/a
AviSynth
  Reply With Quote
Old 10th February 2020, 01:54   #5  |  Link
tebasuna51
Moderator
 
tebasuna51's Avatar
 
Join Date: Feb 2005
Location: Spain
Posts: 6,890
I don't know any free audio editor with video preview.

If I need a video preview frame to frame I use VirtualDub2 or AviDemux
__________________
BeHappy, AviSynth audio transcoder.
tebasuna51 is offline   Reply With Quote
Old 10th February 2020, 13:23   #6  |  Link
LeXXuz
21 years and counting...
 
LeXXuz's Avatar
 
Join Date: Oct 2002
Location: Germany
Posts: 716
Quote:
Originally Posted by Richard1485 View Post
AviSynth
Hm... my knowledge to Avisynth is somewhat limited to just frame serving or adding a few video filters here and there.

How exactly do you cut/insert certain audio frames at a given position with Avisynth?

Quote:
Originally Posted by tebasuna51 View Post
I don't know any free audio editor with video preview.
I was afraid you might say that. Any commercial solutions worth taking a closer look?
LeXXuz is offline   Reply With Quote
Old 10th February 2020, 18:21   #7  |  Link
Richard1485
Guest
 
Posts: n/a
Quote:
Originally Posted by LeXXuz View Post
How exactly do you cut/insert certain audio frames at a given position with Avisynth?
Trim()
Dissolve()
Loop()

etc
  Reply With Quote
Old 10th February 2020, 21:02   #8  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,823
You can try this method, but it takes a little getting used to. Instead of listening to the audio, you edit it visually.
It assumes the A/V sync of each individual source is fine.

In the screenshots below I'm taking the audio from the top video and matching it with the bottom video. To do that I note the position of matching frames and how far apart they are. To be certain, I use frames on a scene change. For the bottom video the first frame I'm using is at 1.751 (seconds and milliseconds) while for the top video it doesn't appear until 2.752.
2.752 - 1..751 = 1.001, so I have to delete 1.001 worth of silence from the beginning of the audio to sync it with the bottom video. Thumbnails:



For this video, there's always a fade to black where the commercials would have been, and for the version from which I'm taking the audio it's always slower, requiring some audio be cut to match the bottom video.

The first break happens at 381.422 for the top video,



so using the next "scene change" frame to match the two, the times are 385.314 and 388.971.
388.971 - 385.134 gives me a difference of 3.837. but...... where it gets a little funky and takes some getting used to is, it's cumulative, so if you're cutting, make a note of how much each time, In this case. 3.837 - 1.001 = 2.836 for the second cut amount. Next break, if you need to cut again, you'd subtract 3.837ms from the time difference. If you only ever need to cut (which is hopefully the case when removing commercials), or you're only adding silence, it's not too hard.



This is how it looks so far in a script.

Code:
Video1 = FFVideoSource("E:\Video1.mkv").Spline36Resize(704,396)
Audio1 = FFAudioSource("E:\Video1.mkv")
Video2A = FFVideoSource("E:\Video2.mkv").Spline36Resize(704,396)
Video2B = Video2A.Sec()

NewAudio = \
Audio1.AudioTrim(1.001, 381.422)\ # skipped first 1.001 sec
+Audio1.AudioTrim(384.258, 0) # skipped 2.836 sec

Stacked = StackVertical(Video1, Video2B)
Dubbed = AudioDub(Video2A, NewAudio)

return Stacked
# return Dubbed
# return NewAudio
"Return Stacked" gives you the stacked videos.
"Return Dubbed" gives you the bottom video and the edited audio so you can check your work as you go, or find the next place it loses sync.
"Return NewAudio" gives you just the edited audio.

If you were doing exactly the opposite and adding silence to the audio you want to keep, it'd look something like this.

Code:
Silence = BlankClip(Audio2)
NewAudio = \
Silence.AudioTrim(0, 1.001)\
+Audio2.AudioTrim(0, 381.422)\
+Silence.AudioTrim(0, 2.836)\
+Audio2.AudioTrim(381.422, 0)
When you go back and listen to the audio, if you've cut in a bad place rather than where there's silence etc, you can adjust the end of one AudioTrim and the beginning of the next by the same amount to move the place where it cuts up or down a bit. When it's a case of only adding silence or only cutting each time, even though it probably seems convoluted at first, I've done this often enough to be able to sync audio from one video to another without listening to it until I'm done (my dyslexia with numbers aside, which is pretty bad). It'd be a nightmare to do it this way if you had to edit audio regularly, but when it's only a few times....

I'd probably run the video containing the commercials through something like MKVToolNixGUI first, to cut out as much of the unwanted stuff as you can beforehand and splice the rest back together before editing the audio.

Here's the function I use for displaying the position in seconds over the video. It includes a few wrapper functions, and one of those is Sec(). It requires GRunT.

Position.zip

Last edited by hello_hello; 28th February 2020 at 09:35.
hello_hello is offline   Reply With Quote
Old 12th February 2020, 20:56   #9  |  Link
LeXXuz
21 years and counting...
 
LeXXuz's Avatar
 
Join Date: Oct 2002
Location: Germany
Posts: 716
Quote:
Originally Posted by hello_hello View Post
You can try this method, but it takes a little getting used to. Instead of listening to the audio, you edit it visually.
It assumes the A/V sync of each individual source is fine.
Thank you very much hello_hello for that detailed explanation.
I will try out your method next weekend.
LeXXuz is offline   Reply With Quote
Old 14th February 2020, 09:20   #10  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,823
LeXXuz,
You're welcome, but it occurred to me that when cutting out sections of video, it's probably better to use Trim rather than AudioTrim, as the former cuts both, and by comparing the stacked videos you can see if they're frame for frame identical after applying a Trim and refreshing the preview. I used the Frame() wrapper function to display frame numbers over both videos. I might even use Trim() when adding silence too from now on, as it can add blank frames with the silent audio.

The top frame number should tell you where to cut, but only where to cut. I kept wanting to use it to calculate how much to cut. Maybe that's why I switched to only displaying the time or frame number on the bottom video. Once you know where to cut, you can navigate to the next scene change frame in each video and use the bottom frame number to determine how much to cut. Best of all, if you apply a Trim to cut out frames and then refresh the preview, there's no longer any need to subtract the number of frames you've previously cut from each edit. There's a line in the example script below to uncomment for disabling the displaying of frame numbers globally rather than having to disable them individually. They may prevent the video from playing in real time.

One thing to watch out for, which I hadn't noticed for the two videos I was using as an example until now, is sometimes they were in perfect sync, but a scene change happened on a different frame (a scene would be one or two frames longer for one video than the other). From there they'd be out of sync by one or two frames, or sometimes the opposite would happen and put them back in sync. I thought I was losing my mind, because I picked one of those "scene change" frames as a reference, and what my eyes could see and the math told me was correct differed by 3 frames, initially, then after a few quick scene changes they only differed by one frame. Doing it my old way with AudioTrim, the A/V sync wouldn't have been out enough to notice, and the next edit using the "same frame" as a reference probably would have corrected the sync again. If you have videos that are edited quite differently, even if they appear the same, you could be in for some fun.

Code:
Video1 = FFVideoSource("E:\Video1.mkv").Spline36Resize(704,396)
Audio1 = FFAudioSource("E:\Video1.mkv")
Video2 = FFVideoSource("E:\Video2.mkv").Spline36Resize(704,396)

global Frame = true
# Uncomment the next line to disable the frame numbers globally
# global Frame = false

OldVideoAudio = AudioDub(Video1.Frame(frame=Frame), Audio1)
# NewVideoAudio = OldVideoAudio

Silence = BlankClip(OldVideoAudio) # If you need to use Trim to add blank frames with silence.

NewVideoAudio = \
OldVideoAudio.Trim(24, 9145)\
++OldVideoAudio.Trim(9215, 23318)\
++OldVideoAudio.Trim(23390, 0)

Stacked = StackVertical(NewVideoAudio, Video2.Frame(frame=Frame))
Dubbed = AudioDub(Video2, NewVideoAudio)

return Stacked
# return Dubbed
# return NewVideoAudio.KillVideo()


By the way, I tend to use MPC-HC for this sort of thing because it's easy to save changes to a script and then use Shift+E to tell MPC-HC to re-open it. If MPC-HC locks the script and prevents you from saving changes while the video is open, which is monumentally annoying, try disabling it's Avisynth source filter under Options/Internal Filters. If that doesn't work or prevents it from opening scripts you'll have to use something for editing that ignores the locked status and saves changes. Notepad should ignore any locked status if you can't find a better text editor that'll do the same. Anyway, just a suggestion...

Last edited by hello_hello; 16th February 2020 at 08:13.
hello_hello is offline   Reply With Quote
Old 14th February 2020, 19:43   #11  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
HH, I use Ps-Pad text editor with Avisynth.ini [for syntax hi-liting etc], can set up to use eg F9 to run some eg 32bit viewer (MPC-HC, Vdub x86),
And just close viewer and carry on edit, then eg ALT-F9 to run eg x64 viewer (Potplayer, Vdub x64).

NotepadPlus had same sort of capability.

I also use VDub2 script editor, press F5 in script editor to save and reload script, jump back to current frame, or F7 to save and jump to frame 0.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 14th February 2020 at 19:45.
StainlessS is offline   Reply With Quote
Old 16th February 2020, 18:03   #12  |  Link
Richard1485
Guest
 
Posts: n/a
Quote:
Originally Posted by hello_hello View Post
You're welcome, but it occurred to me that when cutting out sections of video, it's probably better to use Trim rather than AudioTrim, as the former cuts both, and by comparing the stacked videos you can see if they're frame for frame identical after applying a Trim and refreshing the preview.
Yes. That's how I've always done it.
  Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:01.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.