theslime
Well-known member
- Messages
- 1,234
- Reaction score
- 2
- Trophy Points
- 41
How I made an extended edition in Avisynth (and lived to tell the tale): A tutorial using only freeware/open source tools without sacrificing quality
What I did:
Made an extended edition with video and audio editing with Avisynth, Virtualdub and Audacity, and converted to DVD with Aften and HC and DVD styler. (Only freeware)
Background:
I rarely care for extended editions. Less usually is more. But then one day I watched the deleted scenes for one of my favourite films, Martin Scorsese's wonderful After Hours. They were uniformly excellent, adding even more infuriatingly funny plot twists to the whole. A couple of them lacked crucial starting frames (meaning that including them would have taken you out of the experience), or had other problems like lacking music or being dependent on other scenes that had been cut and not included on the DVD. But four of them could be included. And they were great.
So, where to begin? I don't even have iMovie anymore, and I'm broke, so I decided to learn Avisynth, the scriping language from hell, movie editing for programmers (which I'm not by a long shot). There were two reasons I wanted to do this: (1) I like free and open software, and (2) Avisynth has some amazingly powerful functions and plugins (like the two best resizing algorithms currently available), and is currently the only way to edit videowhile not sacrificing quality. I got VirtualBox and an old XP CD out, and got ready.
1) Ripping.
Tools used: DVD fab decrypter.
I started with the only closed source application in this guide - DVD Fab Decrypter. I ripped titles only: main film first, deleted scenes (they were one title) second. I chose to omit unnecessary audio tracks (the film only has a mono English soundtrack). You get folders with VOB files.
2) Index the MPEG2 video for editing.
Tools used: DGIndex
For MPEG2 (DVD-video) to be readable in Avisynth I need to demux and index the files. This is done with DGindex, an open source application. Load the file into the app and take it from there. The main film shows up with a squeezed image (too slim characters on screen) and no black bars, this is good since it shows that the video is anamorphic. Choose demux all. It will output a small .d2v file (dependent on the vob files, so don't delete them) and a larger .ac3 file for the audio (non-dependent).
Next I load up my deleted files. Here I run into my first problem. I notice that the deleted scenes are letterboxed, not anamorphic. After cursing the DVD authoring company - these scenes look beautiful and they were obviously scanned recently (in the noughties, probably) for the sole purpose of being released on DVD and they couldn't even author them anamorphic?? - I decide to crop the black bars in DGindex now to save me the extra Avisynth work later on. Choose demux all. After Hours only has a mono track, and so I'm set for the time being.
3) Preparing the sources for Non-linear editing using Avisynth
Tools used: Avisynth (with DGdecode.dll and Nicaudio.dll), AvsP, Audacity (if necessary)
Now I'm pretty sure this is not a necessary a separate step. However, to avoid an Avisynth script long as your arm under point 5 (much longer than your arm, on second thought) I like to convert the MPEG2/AC3 sources to Lagarith lossless AVI with WAV audio in one script, and make another for the actual editing. It will make the non-linear editing process A LOT simpler to avoid having fifty lines of video conversion script gibberish in the beginning, especially if the sources differ (which these do).
First of all, install Avisynth. Next: copy-paste the DGdecode.dll file from the DGindex folder to the Avisynth plugins folder (should be in program files\avisynth). After that: download the NICAudio Avisynth plugin, and place the .dll in the Avisynth plugins folder. Lastly, install AvsP, the best script editor for Avisynth. Now you have an Avisynth setup that can decode MPEG2 with AC3 audio, with a script editor/error checker.
Next we're going to make the whole thing one file (with the deleted scenes coming after the credits), and in the process smoothing out the differences in quality. Open AvsP. This might take a couple of seconds, as this will start Avisynth in the background, with all plugins from the plugins folder.
Now you have a text window. This is where the fun begins. Choose Insert source from the edit menu and insert the d2v file. Next, Insert source again, view ëall filesû and insert the AC3 file. Change the prefix from ëDirectShowSourceû to ëNicac3Sourceû. Do the same thing for the deleted scenes. Add prefixes for the sources as per this example script (#-lines are comment/notes lines that are not a part of the script:
Now press the bottom left Preview button. You will get a very discouraging error message, prompting you to - if you're like me - give up editing for at least a week. However, the answer is simple. Check the desired aspect ratio, i.e. the ratio of the main clip. In my case this is standard PAL anamorphic 720x576. This means this is the target size for the deleted scenes. Replace the second video line with this one:
This will resize the deleted scenes clip to match the main film. Lanczos4resize is so good, I can honestly not tell the quality difference in this case, even though I really should. (This can be used to crop and zoom in other cases too.)
Now I try again, and I get another discouraging error message, this time concerning number of audio channels. Obviously, the above-mentioned geniuses who authored the DVD decided to encode the mono track as stereo - only for the deleted scenes. Arrrgh. There are more than one ways to do this. If you convert the AC3 files to WAV, you can fold the stereo to mono with open source audio editor Audacity (export as mono WAV). This is a good chance to check if the volume is consistent too, since Audacity features a really simple gain/volume adjustment tool. (There are ways to get one channel in Avisynth out of two channels, but you need to use some arcane commands that are beyond the scope of this guide.) Fix it with Audacity and in Avisynth replace ëNicac3Sourceû with ëWAVSourceû and the new files and you're good to go. Check with preview. If it worked, save the script. (If not, find the error.)
4) Converting to AVI/Lagarith lossless
Tools used: VirtualDub (with AC3 and MPEG2 plugins), Lagarith lossless installer
The best tool for checking, converting etc. video and audio is VirtualDub. Download the latest package. Find the MPEG2 (and the AC3 if you didn't convert to WAV) plugins for VDub by googling. Make a folder called plugins32 in the VirtualDub folder, and put the DLLs there. Next, install the Lagarith lossless codec. Now open VirtualDub and all plugins should load. Open the avs file you saved. If it didn't work, you probably did something wrong with the plugins.
Check that the main video and the deleted scenes look consistent. If not, you have more work to do. (Colour correction, perhaps? There are avisynth colour correction guides online; do a search.) Choose direct stream copy if you converted to WAV under audio conversion settings (convert to WAV if not), and Lagarith under video. Choose to export to AVI. This will take a long time.
5) Non-linear editing.
Tools used: VirtualDub, Avisynth, AvsP
This is where the real fun begins. Not even open source fanatics would claim that Avisynth is a good non-linear editor. However, it gets the job done extremely well if you invest a little effort.
Open the AVI file in VirtualDub. Note down (on paper) where each transition begins and ends. For instance, my first deleted scene comes after frame 60346. Open AvsP. Then I use a dot and then the Trim command with the start and end frame in a paranthesis. Clip2 is the deleted scene and it's situated near the end of the lossless AVI file. Again to/from frame numbers do the job. Then after the deleted scene, the film follows with frame 60347 and up to the next deleted scene is due to be inserted. My next deleted scene illustrates some of the things you can do with Avisynth; I need audio from one scene and video from another. This can be accomplished with the Killvideo and Killaudio commands. Note that the frame count must be identical.
This produces a script like this:
And you're done!
6) Polish up your WAV
Tools used: VirtualDub, Audacity
Open the avs file in VDub again. This time you choose Save WAV. This will export only the audio part of the project. Polishing up the audio can be done with your sequencer/audio editor of choice. I like Audacity, since it's simple and powerful and I know the interface. You may like something else. Just be sure that you keep the original as the first track as a guide right until the very end, or you will screw up the sync.
Check the transitions. You may need crossfades or added music. You may also have to use music or sound that you cut earlier with Avisynth. You'll know what you need. I actually like to edit without video, since it's even easier to tell when something sounds wonky that way.
7) Convert the soundtrack to AC3
Tools used: Wav to AC3 Encoder (an Aften frontend)
The best tool for this is called, unsurprisingly, ëWav to AC3 Encoderû and is an implementation/frontend/GUI of the best freeware AC3 conversion algorithm, Aften.
8) Convert the video to MPEG2 with HCEnc/HCGUI
Tools used: HCGUI
Now I know most people swear by CCE. However, an increasing amount of geeks are coming to the conclusion that HC is more than good enough, and in many cases better. I trust them, as I think my results were great.
Open HCGUI. Load the latest avs file. Type in the target size of the project. You need some room for the AC3 file and for the menu. Calculate this the best you can. Save some megabytes as headroom for the DVD. Choose ëbestû and press the ëmake compliantû button. Make sure it's the same settings you used. Make chapters if you want. This is basically all unless you know what a preset matrix really does. Press encode. This will take a while.
9) Make DVD menu.
Tools used: DVD Styler
I use DVD styler since it's powerful and free, but I don't like it all that much. Use the one you like best that supports m2v+ac3 input. Just make sure you don't re-encode the video. The video/audio should be done and DVD-video compliant.
10) That was about it!
I hope you found some useful tips here. I imagine the video file preparation section would be handy for people wanting to use the Lanczos4resize command but have little scripting knowledge.
I hope it's newbie-friendly enough to make more people use Avisynth. It's daunting, but far from impossible. And Google is your friend, as always.
And I hope that the Avisynth-savvy will add to this guide, and suggest improvements!
PS: My edit turned out good, but the sound is kinda wonky in places. The sound editing was basically impossible with several things happening in the mono mix at once - and the deleted scenes were not scored. Also, there is no released soundtrack LP release with Howard Shore's music that I know of. I won't share it here in its present state.
What I did:
Made an extended edition with video and audio editing with Avisynth, Virtualdub and Audacity, and converted to DVD with Aften and HC and DVD styler. (Only freeware)
Background:
I rarely care for extended editions. Less usually is more. But then one day I watched the deleted scenes for one of my favourite films, Martin Scorsese's wonderful After Hours. They were uniformly excellent, adding even more infuriatingly funny plot twists to the whole. A couple of them lacked crucial starting frames (meaning that including them would have taken you out of the experience), or had other problems like lacking music or being dependent on other scenes that had been cut and not included on the DVD. But four of them could be included. And they were great.
So, where to begin? I don't even have iMovie anymore, and I'm broke, so I decided to learn Avisynth, the scriping language from hell, movie editing for programmers (which I'm not by a long shot). There were two reasons I wanted to do this: (1) I like free and open software, and (2) Avisynth has some amazingly powerful functions and plugins (like the two best resizing algorithms currently available), and is currently the only way to edit videowhile not sacrificing quality. I got VirtualBox and an old XP CD out, and got ready.
1) Ripping.
Tools used: DVD fab decrypter.
I started with the only closed source application in this guide - DVD Fab Decrypter. I ripped titles only: main film first, deleted scenes (they were one title) second. I chose to omit unnecessary audio tracks (the film only has a mono English soundtrack). You get folders with VOB files.
2) Index the MPEG2 video for editing.
Tools used: DGIndex
For MPEG2 (DVD-video) to be readable in Avisynth I need to demux and index the files. This is done with DGindex, an open source application. Load the file into the app and take it from there. The main film shows up with a squeezed image (too slim characters on screen) and no black bars, this is good since it shows that the video is anamorphic. Choose demux all. It will output a small .d2v file (dependent on the vob files, so don't delete them) and a larger .ac3 file for the audio (non-dependent).
Next I load up my deleted files. Here I run into my first problem. I notice that the deleted scenes are letterboxed, not anamorphic. After cursing the DVD authoring company - these scenes look beautiful and they were obviously scanned recently (in the noughties, probably) for the sole purpose of being released on DVD and they couldn't even author them anamorphic?? - I decide to crop the black bars in DGindex now to save me the extra Avisynth work later on. Choose demux all. After Hours only has a mono track, and so I'm set for the time being.
3) Preparing the sources for Non-linear editing using Avisynth
Tools used: Avisynth (with DGdecode.dll and Nicaudio.dll), AvsP, Audacity (if necessary)
Now I'm pretty sure this is not a necessary a separate step. However, to avoid an Avisynth script long as your arm under point 5 (much longer than your arm, on second thought) I like to convert the MPEG2/AC3 sources to Lagarith lossless AVI with WAV audio in one script, and make another for the actual editing. It will make the non-linear editing process A LOT simpler to avoid having fifty lines of video conversion script gibberish in the beginning, especially if the sources differ (which these do).
First of all, install Avisynth. Next: copy-paste the DGdecode.dll file from the DGindex folder to the Avisynth plugins folder (should be in program files\avisynth). After that: download the NICAudio Avisynth plugin, and place the .dll in the Avisynth plugins folder. Lastly, install AvsP, the best script editor for Avisynth. Now you have an Avisynth setup that can decode MPEG2 with AC3 audio, with a script editor/error checker.
Next we're going to make the whole thing one file (with the deleted scenes coming after the credits), and in the process smoothing out the differences in quality. Open AvsP. This might take a couple of seconds, as this will start Avisynth in the background, with all plugins from the plugins folder.
Now you have a text window. This is where the fun begins. Choose Insert source from the edit menu and insert the d2v file. Next, Insert source again, view ëall filesû and insert the AC3 file. Change the prefix from ëDirectShowSourceû to ëNicac3Sourceû. Do the same thing for the deleted scenes. Add prefixes for the sources as per this example script (#-lines are comment/notes lines that are not a part of the script:
Code:
[/SIZE]
[SIZE=3]###script begins[/SIZE]
[SIZE=3]##main film[/SIZE]
[SIZE=3]#mount video source[/SIZE]
[SIZE=3]video1=MPEG2Source("PATH\after_hours\mainfilm.d2v", cpu=0)[/SIZE]
[SIZE=3]#mount main audio source[/SIZE]
[SIZE=3]audio1=Nicac3Source("PATH\after_hours\mainfilm T80 1_0ch 192Kbps DELAY -8ms.ac3")[/SIZE]
[SIZE=3]#the function audiodub dubs video and audio together. Use ëclip1=û to define this as the first part of a larger whole[/SIZE]
[SIZE=3]clip1=AudioDub(video1,audio1)[/SIZE]
[SIZE=3]##deleted scenes[/SIZE]
[SIZE=3]#mount video[/SIZE]
[SIZE=3]video2=MPEG2Source("PATH\after_hours\delscenes_vob\delscenes_crop_3.d2v", cpu=0)[/SIZE]
[SIZE=3]#mount audio[/SIZE]
[SIZE=3]audio2=Nicac3Source("PATH\after_hours\delscenes_vob\delscenes_crop_3 T80 2_0ch 192Kbps DELAY 0ms.ac3")[/SIZE]
[SIZE=3]#second audiodub[/SIZE]
[SIZE=3]clip2=AudioDub(video2,audio2)[/SIZE]
[SIZE=3]##Splice the whole thing together. ëAlignedspliceû aligns clips after one another while preserving sync. [/SIZE]
[SIZE=3]AlignedSplice(clip1,clip2)
Code:
video2=MPEG2Source("PATH\after_hours\delscenes_vob\delscenes_crop_3.d2v", cpu=0).Lanczos4Resize(720,576)
Now I try again, and I get another discouraging error message, this time concerning number of audio channels. Obviously, the above-mentioned geniuses who authored the DVD decided to encode the mono track as stereo - only for the deleted scenes. Arrrgh. There are more than one ways to do this. If you convert the AC3 files to WAV, you can fold the stereo to mono with open source audio editor Audacity (export as mono WAV). This is a good chance to check if the volume is consistent too, since Audacity features a really simple gain/volume adjustment tool. (There are ways to get one channel in Avisynth out of two channels, but you need to use some arcane commands that are beyond the scope of this guide.) Fix it with Audacity and in Avisynth replace ëNicac3Sourceû with ëWAVSourceû and the new files and you're good to go. Check with preview. If it worked, save the script. (If not, find the error.)
4) Converting to AVI/Lagarith lossless
Tools used: VirtualDub (with AC3 and MPEG2 plugins), Lagarith lossless installer
The best tool for checking, converting etc. video and audio is VirtualDub. Download the latest package. Find the MPEG2 (and the AC3 if you didn't convert to WAV) plugins for VDub by googling. Make a folder called plugins32 in the VirtualDub folder, and put the DLLs there. Next, install the Lagarith lossless codec. Now open VirtualDub and all plugins should load. Open the avs file you saved. If it didn't work, you probably did something wrong with the plugins.
Check that the main video and the deleted scenes look consistent. If not, you have more work to do. (Colour correction, perhaps? There are avisynth colour correction guides online; do a search.) Choose direct stream copy if you converted to WAV under audio conversion settings (convert to WAV if not), and Lagarith under video. Choose to export to AVI. This will take a long time.
5) Non-linear editing.
Tools used: VirtualDub, Avisynth, AvsP
This is where the real fun begins. Not even open source fanatics would claim that Avisynth is a good non-linear editor. However, it gets the job done extremely well if you invest a little effort.
Open the AVI file in VirtualDub. Note down (on paper) where each transition begins and ends. For instance, my first deleted scene comes after frame 60346. Open AvsP. Then I use a dot and then the Trim command with the start and end frame in a paranthesis. Clip2 is the deleted scene and it's situated near the end of the lossless AVI file. Again to/from frame numbers do the job. Then after the deleted scene, the film follows with frame 60347 and up to the next deleted scene is due to be inserted. My next deleted scene illustrates some of the things you can do with Avisynth; I need audio from one scene and video from another. This can be accomplished with the Killvideo and Killaudio commands. Note that the frame count must be identical.
This produces a script like this:
Code:
#each clip is an individual scene[/SIZE]
[SIZE=3]clip1=AVISource("PATH\after_hours\edit\mainfilm_new.avi").Trim(0,60346)[/SIZE]
[SIZE=3]clip2=AVISource("PATH\after_hours\edit\mainfilm_new.avi").Trim(120000,122000)[/SIZE]
[SIZE=3]clip3=AVISource("PATH\after_hours\edit\mainfilm_new.avi").Trim(60347,68434)[/SIZE]
[SIZE=3]video4=Killaudio(AVISource("PATH\after_hours\edit\mainfilm_new.avi").Trim(123000,123100))[/SIZE]
[SIZE=3]audio4=Killvideo(AVISource("PATH\after_hours\edit\mainfilm_new.avi").Trim(140000,140100))[/SIZE]
[SIZE=3]clip4=AudioDub(video4,audio4)[/SIZE]
[SIZE=3]clip5=AVISource("PATH\after_hours\edit\mainfilm_new.avi").Trim(68435,119300)[/SIZE]
[SIZE=3]#where 119300 is the last frame of the end credits[/SIZE]
[SIZE=3]AlignedSplice(clip1,clip2,clip3,clip4,clip5)
6) Polish up your WAV
Tools used: VirtualDub, Audacity
Open the avs file in VDub again. This time you choose Save WAV. This will export only the audio part of the project. Polishing up the audio can be done with your sequencer/audio editor of choice. I like Audacity, since it's simple and powerful and I know the interface. You may like something else. Just be sure that you keep the original as the first track as a guide right until the very end, or you will screw up the sync.
Check the transitions. You may need crossfades or added music. You may also have to use music or sound that you cut earlier with Avisynth. You'll know what you need. I actually like to edit without video, since it's even easier to tell when something sounds wonky that way.
7) Convert the soundtrack to AC3
Tools used: Wav to AC3 Encoder (an Aften frontend)
The best tool for this is called, unsurprisingly, ëWav to AC3 Encoderû and is an implementation/frontend/GUI of the best freeware AC3 conversion algorithm, Aften.
8) Convert the video to MPEG2 with HCEnc/HCGUI
Tools used: HCGUI
Now I know most people swear by CCE. However, an increasing amount of geeks are coming to the conclusion that HC is more than good enough, and in many cases better. I trust them, as I think my results were great.
Open HCGUI. Load the latest avs file. Type in the target size of the project. You need some room for the AC3 file and for the menu. Calculate this the best you can. Save some megabytes as headroom for the DVD. Choose ëbestû and press the ëmake compliantû button. Make sure it's the same settings you used. Make chapters if you want. This is basically all unless you know what a preset matrix really does. Press encode. This will take a while.
9) Make DVD menu.
Tools used: DVD Styler
I use DVD styler since it's powerful and free, but I don't like it all that much. Use the one you like best that supports m2v+ac3 input. Just make sure you don't re-encode the video. The video/audio should be done and DVD-video compliant.
10) That was about it!
I hope you found some useful tips here. I imagine the video file preparation section would be handy for people wanting to use the Lanczos4resize command but have little scripting knowledge.
I hope it's newbie-friendly enough to make more people use Avisynth. It's daunting, but far from impossible. And Google is your friend, as always.
And I hope that the Avisynth-savvy will add to this guide, and suggest improvements!
PS: My edit turned out good, but the sound is kinda wonky in places. The sound editing was basically impossible with several things happening in the mono mix at once - and the deleted scenes were not scored. Also, there is no released soundtrack LP release with Howard Shore's music that I know of. I won't share it here in its present state.