View Full Version : Having trouble joining audio avs and video avs from same original file
BlueToast
5th February 2014, 03:18
I have four MP4's that I recorded using my phone and have named them 1.mp4, 2.mp4, 3.mp4, and 4.mp4.
When I feed one of them into MeGUI to have it create an AVS script file, I get three files:
1.mp4.avs (renamed to 1_vid.avs)
1.mp4_track1.avs (renamed to 1_aud.avs)
1.mp4.ffindex
1.mp4.avs (presently named as 1_vid.avs)
LoadPlugin("C:\Program Files (x86)\MeGUI\tools\ffms\ffms2.dll")
FFVideoSource("G:\Vine1\1.mp4", threads=1)
#deinterlace
#crop
#resize
#denoise
1.mp4_track1.avs (presently named as 1_aud.avs)
LoadPlugin("C:\Program Files (x86)\MeGUI\tools\ffms\ffms2.dll")
FFAudioSource("G:\Vine1\1.mp4", track=1, cachefile="G:\Vine1\1.mp4.ffindex")
# detected channels: 2 channels
# detected channel positions: 2/0/0
For a start, I'm trying to just bring it together as 1_combined.avs
LoadPlugin("C:\Program Files (x86)\MeGUI\tools\ffms\ffms2.dll")
AudioDub(FFVideoSource("G:\Vine1\1.mp4", threads=1),FFAudioSource("G:\Vine1\1.mp4", track=1, cachefile="G:\Vine1\1.mp4.ffindex"))
I have also tried
vid = FFVideoSource("G:\Vine1\1_vid.avs")
aud = FFAudioSource("G:\Vine1\1_aud.avs")
AudioDub(vid,aud)
No success. :(
What I want to do is take and joined all four parts, then go through and trim out the frames that I don't want (and have it trim them from audio as well).
Practical non-tech savvy POV: I shot a video and I want to cut out parts. (and I'm trying to accomplish this using AViSynth -- learning = good)
EDIT: This is what I presently have
http://www.hlrse.net/Qwerty/vines1_screenshot.png
(There is nothing in wholething-allinone.avs because I'm having trouble figuring out how to combine the _aud and _vid together properly + join each part 1, 2, 3, and 4 + then trim both vid and audio together so they don't fall out and sync and the final product is good)
poisondeathray
5th February 2014, 04:45
If you're loading an .avs, use Import()
or do it this way
aud1=FFAudioSource("G:\Vine1\1.mp4")
vid1=FFVideoSource("G:\Vine1\1.mp4")
video1=AudioDub(vid1,aud1)
aud2=FFAudioSource("G:\Vine1\2.mp4")
vid2=FFVideoSource("G:\Vine1\2.mp4")
video2=AudioDub(vid2,aud2)
aud3=FFAudioSource("G:\Vine1\3.mp4")
vid3=FFVideoSource("G:\Vine1\3.mp4")
video3=AudioDub(vid3,aud3)
aud4=FFAudioSource("G:\Vine1\4.mp4")
vid4=FFVideoSource("G:\Vine1\4.mp4")
video4=AudioDub(vid4,aud4)
video1 ++ video2 ++ video3 ++ video 4
But if your videos (phone videos often are) are VFR, you might have to do other manipulations.
hello_hello
5th February 2014, 19:04
I'm generally too lazy to append files while encoding, and trying to solve any audio sync problems etc. Instead, I encode each section individually and append the output files. If you add the audio to the individual output files (ie MKV), and save each as new MKVs containing video and audio (MKVMergeGUI is probably the easiest to use), you should then be able to open the individual MKVs with MKVMergeGUI and append them for a final, single MKV. There's an option in the x264 encoder configuration called "stitchable". It pays to use it if you plan on appending individual encodes.
If you've already got individual scripts and you want them combined as a single encode, open MeGUI's script creater from the Tools menu and use the first script for the input video. MeGUI will add it to the new script using Import. You can then add the others manually like this:
Import(script1.avs)++Import(script2.avs)++Import(script3.avs) etc.
I just realised you're encoding MP4s. MeGUI's file indexer can't extract the audio from them (I hassled Zathor about that recently, but I don't know if it'll change). If you don't need to re-encode the audio you can use the original. One way is to remux the MP4s as MKVs with MKVMergeGUI and open the MKVs with MeGUI for encoding instead. When MeGUI indexes the MKVs it'll extract the audio instead of creating a script to re-encode it (you can still re-encode the extracted audio if you want to). MeGUI's AutoEncode can add the extracted audio to the output files (use the "x" box in the audio section to clear it before using AutoEncode if you don't want to re-encode the audio).
Or possible the easiest way, assuming you don't want to re-encode the audio.... when MeGUI has finished encoding the original video as separate encoding jobs, open the first output MKV with MKVMergeGUI, add the original MP4, de-select the video stream in the MP4, then mux the newly encoded video and original audio into a new MKV. Do the same for each, then when they're done, open the first MKV, append the rest and MKVMewrgeGUI will output a single MKV for you.
You can do much the same as above if you're wanting to output MP4, but it'll be a bit harder. MeGUI's MP4 muxer will output the encoded video and original audio in an MP4 but it won't join the MP4s as a single file. I think MyMP4Box GUI will. I try to avoid MP4 myself because MKV is much easier to work with.
Are you planning on editing before encoding or editing the encoded version? The former would be preferable. Have you discovered MeGUI's AVS Cutter yet (under the Tools menu)? Create a script as you normally would, open the script with the AVS Cutter and add your "cuts". Only the video you want to keep will be re-encoded, so you're effectively editing as you encode. The AVS Cutter can save a "cuts file" which you'd load into the audio section so the audio and video are encoded the same way. Or if you don't want to re-encode the audio, the audio cutter/joiner under the Tools menu uses the same "cuts file".
BlueToast
6th February 2014, 02:03
One way is to remux the MP4s as MKVs with MKVMergeGUI and open the MKVs with MeGUI for encoding instead. When MeGUI indexes the MKVs it'll extract the audio instead of creating a script to re-encode it (you can still re-encode the extracted audio if you want to). MeGUI's AutoEncode can add the extracted audio to the output files (use the "x" box in the audio section to clear it before using AutoEncode if you don't want to re-encode the audio).Thanks to your insight and informative post, I've used AVS Cutter to input trims and create .clt cut files.
However, I am stuck on this part with MKVMergeGUI. So I have gone through all four .avs part files for the video and gotten AVS Cutter to insert the trims.
I have four .clt files I can use for audio but I don't want to re-encode them ... actually, perhaps it doesn't even matter because the next thing is this: how do I join it all together into one MKV without any out-of-sync issues?
If I encode the videos and want to use the original audio, a cutting still has to take place somewhere but you didn't say where/when/how. :( It would either result in an unplayable MKV or an MKV whose audio has a longer duration than the video and is out of sync with cut sections ... for just one of the four parts (haven't asked how to join the four parts).
X_x pardon me for my ignorance.. I'm trying to learn and understand how this works at the same time.
EDIT:
This works
Import("script1.avs")
This doesn't work
Import("script1.avs")++Import("script2.avs")++Import("script3.avs")
EDIT2: If I re-encode the audio using the .clt cut files, how will I join the audio into one final audio file that I would mux with the joined MKVs?
EDIT3: Ultimately, for learning this properly, I would like to do this as 'right' as possible with one AVS script + muxing action to do it all in one shot that is as clean as possible with no re-encoding (or least amount possible). It wouldn't be right to re-encode --> re-encode again --> re-encode one more time etcetera to get myself to the final result. I'd like to do this the way it should be done with the least amount of quality lost and least amount of redundant work (several steps and multiple/different avs per step). Do you know what I mean?
poisondeathray
6th February 2014, 03:27
Did you consider joining the files with other programs, and then editing with GOP accuracy ? - so you don't have to re-encode audio or video at all. Or using a smart rendering program to get frame accuracy (with only a few frames re-encoded)
BlueToast
6th February 2014, 03:37
The reason I'm doing it with MeGUI and AViSynth scripting is for the challenge. :) I enjoy it for some reason. It's totally hard, inconvenient, and hateful -- but I like it. ^_^
poisondeathray
6th February 2014, 03:57
If you want to do it in one step, join it first as suggested above (either with other program or in the script), then do the edits in the script, then encode the whole thing once . Encoding once reduces your risk to several potential issues - rather than encoding mulitple files and attempting to join them which often don't join properly or with glitches
If you haven't discovered avspmod yet, it is simple to do edits in there with the trim editor and keyboard shortcuts
hello_hello
6th February 2014, 04:33
Thanks to your insight and informative post, I've used AVS Cutter to input trims and create .clt cut files.
However, I am stuck on this part with MKVMergeGUI. So I have gone through all four .avs part files for the video and gotten AVS Cutter to insert the trims.
I have four .clt files I can use for audio but I don't want to re-encode them ... actually, perhaps it doesn't even matter because the next thing is this: how do I join it all together into one MKV without any out-of-sync issues?
If I encode the videos and want to use the original audio, a cutting still has to take place somewhere but you didn't say where/when/how. :( It would either result in an unplayable MKV or an MKV whose audio has a longer duration than the video and is out of sync with cut sections ... for just one of the four parts (haven't asked how to join the four parts).
In theory..... ;)
You'd need to extract the audio from the MP4 files. MyMP4BoxGUI (http://www.videohelp.com/tools/My-MP4Box-GUI) should be able to do that for you. Or remux the original MP4s as MKVs with MKVMergeGUI (part of MKVToolNix (http://www.videohelp.com/tools/MKVtoolnix)) and extract the audio from the MKVs. You can get MeGUI to extract it by opening each MKV and indexing it as though you were going to encode it. If you do it that way and there's an audio delay involved, MeGUI will write the delay value to the extracted stream so you can use it later when muxing.
Or, MKVExtractGUI-2 (http://www.videohelp.com/tools/MKVExtractGUI-2) can extract the audio. Put it in MeGUI's mkvmerge subfolder, or if you have MKVToolNix (http://www.videohelp.com/tools/MKVtoolnix) installed in another location, put it there.
I prefer MKVCleaver myself but it doesn't work properly with the latest MKVToolNix. To work around that, read my comment in the comments section on the MKVCleaver page here (http://www.videohelp.com/tools/MKVcleaver). Anyway....
Once the audio is exacted from each MP4, open it using MeGUI's Audio Cutter. It's under the Tools menu. I did mention it in my last post. Use it to open the audio and load the appropriate cuts file. It'll cut the audio and rejoin the sections to output a single "cut" audio file. Repeat the process for each file and when that's done you should have four new "edited" audio streams.
Open each newly encoded output file, add the "edited" audio and save each as new file (MP4 or MKV). MeGUI's muxers should happily do that for you. If all went well the audio of each new MKV/MP4 will be in sync with the encoded video.
Finally, open the first "new" MP4/MKV containing audio and encoded video with MKVMergeGUI, add the second, third and fourth MP4/MKV, but use the "append" button for adding the rest, not the "add" button, and when you remux that, with any luck you'll have a single MKV containing audio which is still in sync. If you want MP4 rather than MKV try appending the files with MyMP4BoxGUI. When you append files the way I suggested using MKVMergeGUI, if there's an audio delay used in any of the files or the video and audio streams aren't exactly the same length, MKVMergeGUI should take that into account when muxing and not put the audio out of sync. Even if the end result is a final MKV with little "gaps" in the audio stream where the individual files were joined it shouldn't effect playback. I've appended MKVs where the audio stream was a fraction longer than the video and it still played with the audio in sync. If memory serves me correctly, video playback paused briefly where the two files were originally joined, then resumed again when the audio "caught up".
I don't know how clever MP4Box is as I hardly ever use it so I don't know how well it'd append MP4s where the audio and video streams are different lengths.
Depending on the type of audio, there's a slight chance you'll hear a small "glitch" where it was cut (nothing to do with appending the MKVs, just the cutting and rejoining of the audio). If that's the case then the only way to stop it happening would be to re-encode it. And the type of audio needs to be the same when you append the files or it won't work. If the MP4s contain different types of audio you'll need to re-encode some/all of them to a common format.
I've no idea why appending imported scripts didn't work. Did Avisynth offer some sort of error? Each script should output video of the same resolution in order to join them that way. And probably the same frame rate. Did you use the full path for each script?
I just created a couple of scripts myself for testing and importing them this way worked fine.
Import("D:\script1.avs")++Import("D:\script2.avs")
PS If you were to re-encode the video and audio as single files, you should be able to encode the video by importing and joining the original scripts as per my example. Each script could contain it's own "cuts".
You should be able to encode the audio as a single file the same way, except the individual scripts would use FFAudioSource() instead of FFVideoSource(). When MeGUI creates a script for audio encoding, it may use FFmpegSource2(), but that's still fine. In theory you'd add the same cuts to the audio scripts as the individual video scripts. Then you'd use Import to create a single script for audio encoding the same way the video encoding was done. Doing it that way should encode the audio as a single file to match the video without requiring a clt file. I'm pretty sure that'd work..... :)
BlueToast
7th February 2014, 02:04
Thank you much!!! :D
Thanks to you guys I was able to pull this off and post this: https://www.youtube.com/watch?v=UZzrrFnD6Ng
(I also included in the description what I did to put this together)
hello_hello
7th February 2014, 08:03
I also included in the description what I did to put this together
Wow..... you made the whole process sound so complicated! :D
hello_hello
7th February 2014, 08:28
A couple of thoughts which might come in handy.
- Doing one AVS at a time in MeGUI, I open them and set it to do an x264 Unrestricted encode at 4096 Kbps into RAWAVC file format
If, in MeGUI's settings, the option "x264, use external muxer" is unchecked, and you select MKV as the output format rather than RAWAVC, the encoded video will be written directly to an MKV. It won't be indexed properly (which might make opening it a little slower then usual), but that'll be fixed when it's remuxed with the audio, however writing directly to MKV gives you the ability to open the output file while the encoding is still in progress. Handy if you want to preview the encoded video before it's finished.
- I test the final MKV with MPlayer (free), PowerDVD (not free), and VLC Player (free) for quality assurance
I noticed MPC-HC wasn't mentioned in you list of players. I mention it now, in case you're not aware (and nothing to do with the fact I prefer it to the players you mentioned, of course ;)), MPC-HC can open Avisynth scripts, allowing you to preview the Avisynth output in a player before it's encoded. Sometimes MeGUI's preview can be a little limiting. Often I'll create a few scripts with different resizing or noise filtering etc and run them all maximised on my monitor or TV so I can switch between them. I put a shortcut to MPC-HC in the Windows SendTo folder which makes opening scripts in the player nice and easy. I don't think any of the players you mentioned can open AVS scripts.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.