How do I replace a section of audio in an MPEG2 file?

stevehiner

New member
While recording a show one of those required government warnings came up on screen and muted the show. Unfortunately someone at the network must have screwed up and the show stayed muted for a good 15 minutes or so, long after the warning banner went away.

I have managed to get WAV files of the audio for the part of the show that was muted. I'm wondering if there is a straight forward way to replace the audio sections of the MPEG2 with the WAV files I have.

I believe I can do it by saving the muted sections of the video as elementary streams then rejoin the elementary video with the WAV file to create a new file. I'm guessing that's going to be kinda a nightmare to get the audio synchronized so I'm wondering if there is a better way. Doing it that way feels like working in the dark since I'd have to guess at the audio offset when joining them together, create the final video, guess at another offset (wash, rinse, repeat).

Shall I just man-up and do it the hard way or is there a more elegant solution?
 

Dan203

Senior Developer
Staff member
Actually your plan will work OK. Once you mux the audio with the video clip open it up in VideoReDo and you can adjust the sync interactively using the Tools->Adjust Audio dialog. Then save again. Then use the joiner to put the chunks back together. The biggest issue is that you're going to have to make all the audio streams in the 3 chunks match. If the original show is AC3 then the only way to do that in VideoReDo would be to save all 3 chunks with MP2 audio first, then join them.

Alternatively you could use another tool like Audicty, or a more high end video editor like Premiere or Vegas to do it.
 

stevehiner

New member
Ok, I trimmed up the videos to a good place to sync audio and saved them as elementary streams. Using Audacity I trimmed up the wav file to pretty closely match the video so I shouldn't have to adjust the sync too much and exported it as wav, mp3 and mp2 to get my bases covered.

The original source video is MPEG2 recorded from an HDHomeRun and according to VRD the audio is:
Audio Stream: 1 (Primary) Codec : MPEG
MPEGLayer : Layer 2
Channels : 2.0
PES Stream Id : xC0
Bit rate : 224 Kbps
Sampling rate : 48000
Sample size : 16 bits

I opened the elementary stream multiplexer and selected my m2v video file. I deleted the mpa audio file it auto selected since that would be from the original show and it's basically empty. I selected the mp2 version of the edited audio and VRD says "Can not mux files" but it doesn't say why.

It will let me select the wav version of the audio but based on what you said that will cause problems when I try to join the files back together. At the bottom of the Elementary Stream Muxer it does say the profile is MPEG-2 and an audio recode is required. I'm going to try it anyway in the hopes that it will work but I'd love to hear what I did wrong if this won't work.
 

Dan203

Senior Developer
Staff member
When saving the muxer just set the audio format to MP2 and you'll be fine. That will convert the WAV to the same format as your other files. You'll also want to set the audio bitrate to 224000 so that it matches the other files as well.
 

stevehiner

New member
The muxing went well. One of the segments was spot-on and didn't require any adjustment, the other one required a little audio sync work but VRD's audio tool made that really easy. I tweaked the audio sync in the one file and saved it. Then I opened the first segment, added it to the joiner list, opened the second segment, added it to the joiner list and saved the file. It looked and sounded great.

Then I opened the original file and selected up to the start of the first segment and added it to the joiner list. Open the fixed file and added it to the joiner list. Then I opened the original file and selected the remainder of the video after the audio problem and added it to the joiner list.

Everything seemed to be going well then I saved the joiner list. At about 60% of the way through the save, about the point when it would have hit the corrected segment I got an error: "VideoMalloc: no more memory."

I'm running version 5.1.2.740. I realize this might be due to using the wav files since VRD wouldn't let me use the mp2 file. VRD is currently using 3.8GB private bytes and 2.1GB working set so the error seems to be accurate. Good job guarding the rest of VRD from that error though. I was able to acknowledge several out of memory errors and close VRD nicely. I thought I'd have to kill the process but it handled a bad situation quite nicely.
 

stevehiner

New member
I just saw your reply and I didn't change the audio bitrate so maybe that played into the memory issue. I'm out of time on my lunch break so I'll have to try it again another time.
 

stevehiner

New member
I couldn't help myself...

I opened the joined fixed segments and found that the audio format was LPCM. I saved them as MPEG-2 and modified the profile to output MP2 224K then I joined them all again. This time the join worked beautifully. Not only that but the BeyondTV metadata survived all this messing around.

Thank you so much for the help!
 
Top Bottom