Raffriff's awesome VirtualDub tutorial

Discussion in 'Video Encoding' started by raffriff, Oct 27, 2011.

  1. raffriff

    raffriff Moderator Staff Member Site Contributor

    I'm going to show you how to encode a video with VirtualDub with the best possible quality (assuming we want to upload to a site like YouTube) using H.264, and also show you how to batch process multiple videos.

    EDIT as of today (September 2013) I'd recommend getting the 32-bit version of VirtualDub for maximum compatibility with codecs and plug-ins. Look on this page for version 1.10.x (experimental), 32-bit (x86).

    If you don't use VirtualDub but you're looking for good H.264 settings, see this post.

    If you need a good H.264 encoder, get x264vfw. If you need a good AC3 encoder, get AC3 ACM.
    [Updated Jan '14 to recommend AC3 over MP3 audio. Or use uncompressed PCM. See below]

    Ready? OK!

    Installing VirtualDub: there's no installation. Unzip to any folder and run VirtualDub.exe; make your own shortcuts and file associations. Then install x264vfw.

    Run VirtualDub.
    Select File|Open Video File...
    VDub-Tut-01-avi-open-mnu.jpg

    If you have some clips (say Fraps 4GB AVI segments) you want to join together:
    1. rename your files with FrapsJoin first, so they are in a form VirtualDub understands
      (file names must end with serial numbers, in order)
    2. File|Open Video File; select 1st clip
    3. File|Append Avi Segment; check "Autodetect additional segments";
    4. select next clip, and all the clips in the series will be added to the timeline.
    Now you see your video in two windows, like this:
    (they are called input and output: before and after filter processing, as explained below)
    VDub-Tut-02-vdub-main.jpg

    I don't use the VirtualDub Input windows at all. I'm just interested in the output.
    To disable the Input pane, select View|Layout|Output pane only

    Right-click the windows to zoom in & out.
    Drag the scrollbar to move around the timeline.
    You probably won't be able to see a smooth playback of the video if you're looking at a high definition capture file.

    You can encode a selected portion of the timeline, using the home and end keys to select in & out points. This is good for making short test videos.

    Save as AVI...

    UPDATE 18-Jan-2013: save to MP4 instead of to AVI (seems to be more YouTube friendly)
    VirtualDub: save direct to MP4 (Fraps to YouTube)
    (this is an advanced technique)​

    OK, set the audio compression:
    VDub-Tut-05-aud-cmp-mnu.jpg

    You'll see a list of encoders installed on your machine; most are either low quality, or restricted to use by a particular program. There's two ways to go with audio compression:
    • AC3, stereo of course, constant bit rate (important), and about 96-128 kbps, more or less.
    • Uncompressed PCM makes your files maybe 10-15% bigger, but it's much more compatible with all players and video editors. Recommended for archive & intermediate files - see here.
    VDub-Tut-06-aud-cmp-cfg.jpg
    (explained a little more clearly @ post #23)

    Now the video compression:
    VDub-Tut-07-vid-cmp-mnu.jpg

    Choose H.264 - normally x264vfw unless you already have a different flavor installed.
    Make sure Force keyframes is not checked.
    VDub-Tut-08-vid-cmp-sel.jpg

    Here are the H.264 settings I currently use for Fraps to YouTube:

    [EDIT - moved all H.264 settings to this post to avoid duplication;
    in short: get x264vfw. Mode=Constant Ratefactor, Ratefactor=19. Uncompressed audio]​

    And I should add: check "VirtualDub hack" in your x264vfw options.

    (...continued in next post)

    last updated Jan 11, 2014
     
    Last edited: Jan 11, 2014
    kool123, norritt, pluto1 and 5 others like this.
  2. raffriff

    raffriff Moderator Staff Member Site Contributor

    OK now we want to add some filters to enhance the video a bit: (note full processing mode has to be checked to use filters)
    VDub-Tut-10-flt-mnu.jpg

    At first we have an empty filter list; hit the Add button:
    VDub-Tut-11-flt-add.jpg

    The first one we'll add is the levels filter:
    VDub-Tut-12-flt-lvl-add.jpg

    We boost the white levels a bit to help the video "pop". I usually set Input "white" to 240 as shown, maybe 220 for a dark source. For really dark scenes you might want to move the middle triangle (gamma) to the left a bit - not too much [1.2 to 1.3]! Hit "Show Preview" to see the effect as you make adjustments:
    VDub-Tut-13-flt-lvl-cfg.jpg

    Caution - check to make sure this actually improves your video. This has the potential to show slight banding on smooth color contours (like a clear blue sky). If it's objectionable, don't use it.

    For more on color correction of dark videos see this post. [Also this post.]

    Note you can quickly turn the filter on & off without removing it permanently - just
    uncheck the check box for that filter in the filter list.

    Next we add the HSV filter, and use it to boost saturation (110% - 120%); this helps overcome losses though the encoding process, and through the online re-encoding process.
    VDub-Tut-14-flt-hsv-cfg.jpg

    For the same reason, we need to add the sharpen filter, set to about 10-15% (no picture; use the preview windows and just add a little sharpness - the video should look just a little too sharp).

    UPDATE - add the "alias format" filter: Color space ="Rec. 709 (HD)". Component range ="No change". This fixes a slight desaturation of red colors.

    If you want to upsize say, a 1280x720 video to 1920x1080, add a resize filter. Set "Filter mode" to "Lanczos3" for maximum sharpness.

    UPDATE - crop & resize examples:
    1. You have 1280x800 (16:10 aspect) and want to upload 1280x720 (16:9) for YouTube
      • Add a Null transform filter
      • Click Cropping...
      • We need to reduce the height by (800-720) or 80 pixels;
        let's take 40 pix off the top & bottom:
        vdub-crop-720.png
    2. You have 1680x1050 (16:10) and want to upload 1920x1080 (16:9) for YouTube
      • Add a resize filter
        vdub-resize+crop-1080.png
      • Select "Absolute" size mode
      • Aspect ratio = same as source
      • Enter "1920" for the new width
      • (this will automatically set height to 1200)
      • Mode = bicubic
      • Framing = Letterbox/crop to 1920x1080
      • (this will automatically crop 120 pix from top & bottom)
    UPDATE April 2012 - I always load these filters:
    • null transform for cropping
    • alias format for color adjustment
    • HSV for boosting saturation; also it is useful even with all settings at "normal" - it somehow helps make the preview colors more accurate
    • levels for brightness & gamma boosting
    • two preconfigured resize filters (bilinear for smooth downscaling, bicubic for sharp upscaling)
    • box blur looks good, but somehow doesn't translate to YouTube. I keep trying to find a setting that works.
    • sharpen helps on YouTube if not overdone.
    • ffvdub is a collection of even more filters; most importantly for me, an Avisynth script host. Also color curves. (ffvdub is part of ffdshow tryouts)
    • temporal smoother is good at denoising and deflickering, which helps compressibility.
    • Kagayaki does a wild starburst filter effect; still searching for settings I can actually use.
    virtualdub_common_filters1.png virtualdub_common_filters2.png

    I preload the filters so they are ready to be enabled if needed with the following trick:
    • Set up v-dub the way you want, including standard filters and compression settings
    • Click File, Save Settings, save under My Documents\VirtualDub as "virtualdub_default.vcf"
    • Load the settings at any time by clicking File, Load Settings
    • Load settings automatically by modifying the shortcut you use to launch VirtualDub, adding /s"<path to settings file>".
    (...to be continued)
     
    odddotheheak and Kilwa like this.
  3. raffriff

    raffriff Moderator Staff Member Site Contributor

    Now I'm going to talk about the video frame rate options:
    VDub-Tut-21-vid-rate-mnu.jpg

    This won't be used by most people, but I want to point out a few things here:
    1. "Change so video and audio durations match" - this has been said to fix the audio sync problem.
      I never tried it myself. It won't work with multiple files on the timeline, unfortunately.
    2. "Process every other frame (decimate by 2)" - this is for converting a 60 fps capture file to 30 fps
      (if you don't do it YouTube will anyway)
    3. "Convert to X fps" - this is for converting say 50 fps to 30 or any other combination.
      Note this works by dropping or repeating frames - there are higher quality ways to do this.
    VDub-Tut-22-vid-rate-dlg.jpg
     
    Last edited: Jan 26, 2014
    odddotheheak and Kilwa like this.
  4. raffriff

    raffriff Moderator Staff Member Site Contributor

    There's an extremely useful File Information feature; this tells you the encoder type, the exact length and framerate, etc...
    VDub-Tut-42-avi-info-mnu.jpg

    also if your capture file is dropping frames: (this is a sign you're trying to capture more pixels than your system can handle)
    VDub-Tut-43-avi-info-dlg3.jpg
    Seeing a few dropped frames is normal.

    NOTE: for benchmark testing, actual recorded FPS =
    Number of key frames / Length x fps
    example: 4821 kf / 5187 fr x 30.00 fps = 27.88 fps, recorded​
    ...
     
    odddotheheak and Kilwa like this.
  5. raffriff

    raffriff Moderator Staff Member Site Contributor

    OK, now we're ready to encode.

    To encode a single file, use File|Save as AVI:
    VDub-Tut-41-file-save.jpg

    To batch encode, we use File|Queue Batch Operation|Save as AVI. When you "save" the file, nothing happens right away; your job is added to the job list. Your compression settings, filter settings and in & out points are all saved as part of the job:
    VDub-Tut-45-job-add.jpg
    Default hot key is {Ctrl}+{Shift}+{F7}, but you can change it in "Preferences," "Keyboard shortcuts." I use {Ctrl}+{Shift}+S.

    To see your job list, use File|Job Control:
    VDub-Tut-46-job-ctl-mnu.jpg

    Now you see the job control window. You can manage your jobs here; when you're ready, hit Start:
    VDub-Tut-47-job-ctl-dlg.jpg

    ... to shut down the computer when everything is done, use Options|When Finished

    (continued)
     
    Last edited: Jan 26, 2014
    odddotheheak and Kilwa like this.
  6. raffriff

    raffriff Moderator Staff Member Site Contributor

    To remember all the compression & filter settings for next time, use File|Save Settings:
    VDub-Tut-51-save-settings.jpg

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    VirtualDub can do a lot more than that: it can do simple editing for example. There are tons of filters available for it. It can also do screen capture. I'll let you learn about that on your own. (EDIT see post #21)

    That's all! Questions, suggestions & corrections welcome! I learned a lot from this series of video tutorials, and from reading frapsforum of course!
    - raffriff
     
    Last edited: Jan 26, 2014
    odddotheheak and Kilwa like this.
  7. Regarding the "append *.avi segment" feature of Virtualdub:

    Unfortunately, Virtualdub is unable to append all the fraps-generated segments automatically. Segments must have names like: name.00.avi, name.01.avi, name.02.avi, etc.

    I made a small Visual Basic Script that renames corresponding fraps avi segment files (schema: "program YYYY-MM-DD HH-MM-SS-ms.avi") to a virtualdub-friendly scheme: "program YYYY-MM-DD HH-MM-SS.nn.avi", where the date is identical in all segments - it is the date of the first avi, and nn=00..99.

    Additionally, it writes a *.js which can be loaded with Avidemux as project file. This project file contains commands for Avidemux to load all corresponding segments as one task, so you have this feature for Avidemux as well.

    The script must be started from the command line in the directory where your original *.avi files from Fraps are located. It detects sets of corresponding *.avi files and renames them. If you stopped recording for a few seconds and restarted recording, the script detects that and begins counting at 00 for the second set.
    If you run the script over the directory again, it will not process renamed files again. Single files that are not part of a longer recording session, are not renamed as well.

    After you renamed your *.avi files, load the *.00.avi file with Virtualdub. Then choose "Append *.avi segments" from the menu and point to the *.01.avi file. Check "detect additional segments". All remaining segments from 01..99 should now be loaded by Virtualdub.

    The worst this script could do to your files is giving them new names. It doesn't copy, move or delete anything. It only renames files if the naming scheme matches.

    The script works only for filesets that are created by the more recent versions of Fraps, since the naming scheme of segmented *.avi files was changed slightly in one of the last updates.

    Save the script code from below as "renavi.vbs".

    Code:
    ' renavi.vbs - rename fraps-generated avi files to virtualdub-understandable
    ' segment names
    
    option explicit
    
    ' system
    dim wshshell, fso ' WSHShell, FileSystemObject
    
    ' return zero-padded number
    function zstr(number, digits)
    
      zstr = right(string(digits, "0") & cstr(number), digits)
    
    end function
    
    sub ad_final(adscript, savename, dpath)
    
      if adscript is nothing then exit sub
    
      adscript.writeline ""
      adscript.writeline "//app.save(""" & dpath & savename & """);"
      adscript.close
      set adscript = nothing
    
    end sub
     
    sub main
    
      set wshshell = CreateObject("WScript.Shell")
      set fso = CreateObject("Scripting.FileSystemObject")
    
      ' search for "* YYYY-MM-DD HH-MM-SS-ms.avi"
      dim d, f, regex, matches, match
    
      wscript.echo "renavi start"
    
      set regex = new regexp
      regex.pattern = "^(.*) (\d\d\d\d-\d\d-\d\d) (\d\d-\d\d-\d\d)-\d\d\.avi$"
    
      dim prevdate, groupdate, firstname, newname, index, date, prev
      dim adscript, dpath, savename
      set adscript = nothing
      index = 0
      prevdate = 0
      set d = fso.GetFolder(".")
      dpath = d.path
      if right(dpath, 1) <> "\" then dpath = dpath & "\"
      dpath = replace(dpath, "\", "/")
      for each f in d.files
        set matches = regex.execute(f.name)
        for each match in matches
          date = cdate(match.submatches(1) & " " & replace(match.submatches(2), "-", ":"))
    
          if groupdate <> f.DateLastModified then
            index = 0
            groupdate = f.DateLastModified
          end if
          if date < prevdate then index = 0
    
          if index = 0 then
            ad_final adscript, savename, dpath
            firstname = match.submatches(0) & " " & match.submatches(1) & " " & match.submatches(2)
          end if
    
    '      wscript.echo date & " " & f.DateCreated & " " & f.DateLastModified
    '      wscript.echo "name=" & f.name
    '      wscript.echo "date            = " & date
    '      wscript.echo "DateCreated      = " & f.DateCreated
    '      wscript.echo "DateLastModified = " & f.DateLastModified
    
          if index = 1 then
            ' rename first video to *.00.** as well
            newname = firstname & "." & zstr(0, 2) & ".avi"
            wscript.echo "rename " & prev.name & " to " & newname
            prev.name = newname
    
            ' start avidemux script
            set adscript = d.createtextfile("load " & firstname & ".js", true)
            adscript.writeline "//AD"
            adscript.writeline ""
            adscript.writeline "var app = new Avidemux();"
            adscript.writeline ""
            adscript.writeline "app.load(""" & dpath & newname & """);"
            savename = dpath & firstname & " compressed.mp4"
    
          end if
          if index > 0 then
            newname = firstname & "." & zstr(index, 2) & ".avi"
            wscript.echo "rename " & f.name & " to " & newname
            f.name = newname
    
            adscript.writeline "app.append(""" & dpath & newname & """);"
          end if
    
          index = index + 1
          prevdate = date
          set prev = f
        next
    
      next
      ad_final adscript, savename, dpath
      wscript.echo "renavi end"
    
    end sub
    
    main
    
     
    raffriff likes this.
  8. raffriff

    raffriff Moderator Staff Member Site Contributor

    Hooray! :) That's something I've been thinking about.
    Can't test your script right now - will evaluate as soon as possible.

    For people of the GUI persuasion needing to rename files, I posted a suggestion here.

    It's actually more work to use the GUI app than it would be to use this script.
    The GUI (Rename Master) does have undo/redo, so there's that.
    (EDIT my post above now recommends IrfanView as a better file renamer for this use)

    Koala, does that sound right to you, or are you able to do it in one step?
    Is V-Dub choosy about the name format?
     
  9. raffriff

    raffriff Moderator Staff Member Site Contributor

    Note to self & future tutorial makers - here's what I want to do *next* time:
    • Make a bunch of place-holder posts first, so no one can 'interrupt' you. (I was lucky this time)
    • Start filling in your posts, but skip every other one, so you can squeeze in any changes later.
    • On frapsforum, you can only attach 8 images max per post, so plan ahead.
    • Short posts are better anyway - they let people jump to a precise topic.
    UPDATE
    • Make sure your guide is focused on a specific subject area.
    • Put the guide in its own thread with a good title.
    • Try to make your title include search terms that someone might use to find the information you are presenting.
     
  10. Two steps required, as far as I know. First you File|Open Video File the first clip, and after that you append the others in one take with File|Append Avi Segment with activated "Autodetect ...".

    Virtualdub requires this naming scheme: <something>.00.avi, <something>.01.avi, <something>.02.avi etc. In this case, <something> must be the same for every clip. Because of that, my script gives all segments the same <something>, which is the date from the first clip, the starting timestamp of the recording session.
    If there is a hole in the numbering, virtualdub stops appending. If you have 00, 01, 02, 04, 05, 06, Virtualdub appends up to 02. Then you can append 04 manually and Virtualdub imports the remaining up to 06.

    Actually, the very first file (.00.avi) isn't required to contain numbers. It could be named <anything>.avi. But the segments you append must adhere to the naming scheme.

    I'm sorry that I cannot help command-line-phobic fellows, but I haven't figured out yet how to bring this renaming feature into the Explorer. It could perhaps be something you associate *.avi files with in Explorer. Not as default, but as optional program.

    Until then, put the script into the directory where Fraps saves its files and start it every time you need to import a sequence of newly created clips.
     
  11. ciarlo2006

    ciarlo2006 Site Contributor Well-Known Member

    Good tut.

    When I used StaxRip I spent a good month or so constantly trying to figure out the perfect settings for fast paced game videos, as it's completely different to movies and animation etc. I wish I kept the profile, since StaxRip did an update and it stopped working and I couldn't be bothered with it anymore, otherwise I would have passed on the H264 command line for reference.

    I know that qmin and qmax were the most important part for the quality to size ratio and the rest worked around them.

    Edit: Just remembered the video site I was co-running, I based the config off of my profile, with some minor tweaks, but I'll try and get a hold of it if you wish to have a look.

    Example of quality to file size: http://www.u4eatube.com/uploads/wUgKWaxcaOwmLiEqauWEJ.flv

    It's 17MB at 960x540.
     
  12. In audio compression, ther is no option called 'Lame MP3' help!:p:)
     
  13. raffriff

    raffriff Moderator Staff Member Site Contributor

    OK it seems you need lame_enc.dll, which is not included in the link I gave - sorry.
    Lame as it comes from Sourceforge is command line only.

    The LAME build you want is here: LAME ACM (rarewares.org)
    (no it's not a "warez" site!) NOTE: there's no "setup" program; follow the instructions!

    I had lame_enc.dll automatically installed somehow.
    That's why I didn't notice this problem - LAME "just worked" for me.
     
  14. raffriff

    raffriff Moderator Staff Member Site Contributor

    I tweaked your script a little -- hope you don't mind! The main new features are: (1) this script creates a batch file to undo the changes made. (2) you tell it what folder to work on by drag and drop. It also a gives you a chance to name the group of files whatever you want.

    The new script is too large for a forum post, so I put it on GitHub - here it is:
    Github.com/XyKyWyKy/FrapsJoin (look for the "ZIP" button)

    Check the README and the INI file for installation and usage. Info & tutorial here [link].
     
  15. raffriff,

    I have never had any experience with VBS scripts or anything, but I came across this script and it would be hugely useful for me. I am not afraid to use the command prompt, I am just inexperienced.

    As of right now, whenever I try to run your program via the "Open with..." method (that is all I have tried), I get a permission denied error after confirming the name. Do you have any idea why this might be?
     
  16. raffriff

    raffriff Moderator Staff Member Site Contributor

    Hey there - do you:
    • record long walkthroughs or let's play videos
    • want the final video in fixed length segments for YouTube etc.
    Here's what you need to do:
    1. Join all the 4GB segments into one master video (if using Fraps 3.4.7 or earlier)
      ...
      1. Append ALL videos for the walkthrough (using Append AVI segment - see post #1)
      2. Create a intermediate master video with Direct stream copy:
        select Video menu, Direct stream copy and Audio menu, Direct stream copy.
        Open the master file in VirtualDub again.
        ...
    2. Break the video into segments for uploading with VirtualDub:
      ...
      1. Position time line cursor at start; set edit "in" point: {Home}
      2. Position cursor at 15 minutes, or whatever your time limit is
        (or less; choose a nice place to cut)
      3. Set edit "out" point: {End}
      4. File menu, Queue batch operation, Save AVI (see post #5)
        • make a name like "XYZ Part 1"
        • nothing happens yet, but the "Job" is "queued"
        • you should see your video under File menu, Job control
      5. Keep time line cursor where it is; set "in": {Home}
      6. Move to next 15 minute cut point, {End}
      7. File menu, Queue batch operation, Save AVI
      8. (REPEAT...)
      9. File menu, Job control : you should see all your 15 min videos!
      10. Hit Start to begin encoding!
    Originally posted ->here.

    updated Apr 30 2012
     
  17. So this means that if I had two files from FRAPS (because it split the video), and I used the "Append .avi Segment" option, and I want to encode them together into one file, I have to use the "file|Queue Batch Operation|Save as AVI" and THEN click "File|Save as AVI"? I just want to make sure I'm doing this right, it was kind of hard to understand that part of the post.
     
  18. raffriff

    raffriff Moderator Staff Member Site Contributor

    Hi lLienO, I was trying to explain two different methods. Maybe I should have said...
    • To save one output file, joining one or more source files (the usual way)
      1. Open the first source file; Append any additional source files
      2. Set In and Out points (optional)
      3. Add filters (optional)
      4. Select compression settings
      5. Save as AVI...
      6. The encoding starts right away...
    • On the other hand, Batch Encoding is for encoding a number of videos - usually overnight.
      1. Follow steps 1-4 above
      2. File|Queue Batch Operation|Save as AVI...
      3. Nothing seems to happen, but a "job" has been added to the "queue"
      4. Repeat to add more jobs...
      5. When ready to encode, File|Job Control, Start
      6. Each "job" will be encoded with its own settings...
     
  19. Awesome article raffriff.

    I read all. Nicest walktrough with VD.

    Thanks for share.


    Claudio
     
  20. raffriff

    raffriff Moderator Staff Member Site Contributor

    Thanks Claudio and welcome. After giving it the title 'awesome,' (joking) I was a little nervous! I had to do my best to make it so!
     

Share This Page