[Howto] Encoding videos

Last updated on 14 years ago
JonL
Before doing this tutorial - download this:
http://realmods.online.fr/MEGUI.7z
Its the MeGUI profiles and scripts we use!

Notes:
This tutorial is heavily based on the excellent one written by Nox1911, hipoonios and RickyC. You'll find the original here for further reference:
http://www.longplays.org/modules/newbb/viewtopic.php?topic_id=264&forum=1

The initial steps (like capturing the game using FRAPS) are described in this topic.

If anything is missing or inaccurate, please tell me.
=====================================

General description

The encoding steps are as follows: you are going to use an AviSynth file to append all captured videos, trim them if need be, and add your signature at the start.
Once this is done, you'll use MeGUI to create two separate files. One contains the video, encoded with the x264 codec (that makes it a lot smaller than the original captured files, while retaining a good quality). The second one contains the audio, encoded with the Nero AAC codec.
The last thing to do is to use mkvmerge to mux (merge) both files into a single, final file.

AviSynth

Download and install AviSynth. Find it here:
http://avisynth.org/

Creating the AVS script

1) Go to the folder where you put all the captured video files. Right click in Windows Explorer and choose New => AviSynth Script. Choose file name. The file extension should be .AVS

2) Edit file with Notepad (any text editor will do). Paste the following in the file:

AviSource("gamename.avi")

Fps=60 #Set to Actual Framerate of the video (Used for timing of the subtitles)
SubsStart=5*Fps # How many seconds into the video before Subtitles show
SubsDura=8*Fps # How long Suptitles show for
SubsY=450 # How many lines down the image to show the subtitles. Up and lower this value to find best position.

PointResize(width*2,height*2) # Double-sizes the video (320x200 -> 640x400

Subtitle("<Insert full game name here>", \
   first_frame=SubsStart, last_frame=SubsStart+SubsDura, \
   y=height-48, size=24, text_color=$ffffff, align=2)
Subtitle("Played By <player name here>", \
   first_frame=SubsStart, last_frame=SubsStart+SubsDura+5, \
   y=height-24, size=24, text_color=$ffffff, align=2)
Subtitle("www.longplays.org", \
   first_frame=SubsStart, last_frame=SubsStart+SubsDura+10, \
   y=height, size=24, text_color=$ffff00, align=2)


ConvertToYV12 (chromaresample="point") # Converts to YV12 colorspace for h264 best for  Video up to 720.

#ConvertToYV12 #use for 720p or higher

FadeOut2(120) # Fades the video out at the end of the video over 120frames (2 seconds at 60 fps)


3) In the AviSource line, you need to indicate all your captured video files. If you have only one video file, just replace gamename by the proper filename.
You're likely to have more than one file, however, so you need to replace this line by something like this:

AviSource("file01.avi")+\
AviSource("file02.avi")+\
...
AviSource("file03.avi")


Notice that all lines finish with +\ except the last one. Replace the file01... file03 by the correct file names, and duplicate lines as needed (if you have 20 files, then you'd end up with 20 lines).

4) Replace <Insert full game here> by the full game designation. Replace <player name here> by your nickname.

5) The signature should appear 2 seconds after the video starts, and should remain on screen 5 seconds. The SubStart line sets up the signature start time, in frame units. This value depends on the game refresh rate that you determined/chose earlier. Let's say the refresh rate is 50Hz. This means that the video contains 50 frames for each second. To set the signature to appear after one second, SubsStart should be set to 50. Set this value according to your refresh rate.

6) The SubsY lines indicates the vertical position of the signature. This default value (450) is set for movies that are 480 pixels high. You may need to set a smaller value if the game resolution is smaller, or set a higher value if you recorded at a higher resolution. As a rule of thumb, set it approximately at 9/10 of the movie height.

7) Save the AVS file. Play it in Windows Media Player (it won't play in VLC though). If everything went fine, your game should appear, with all captured parts seamlessly appended to one another, and the signature should appear during the first few seconds. Skim through the result for a first check.

8) When creating AVS files that append lots of video files (more than 50 or 60), you are likely to run into trouble. The file would not even play anymore, claiming that no codec combination was found to render the file. To bypass this issue, create several .AVS files that regroup less video files. You will be able to append all of them in the final encoding step. In the additional .AVS files, you should remove the Subtitle lines.

Trimming video files

1) When you recorded the game, you probably did it in separate sessions. That means your captured video is probably made of several video files. At the end of one file and at the start of the next, there may be some unwanted frames that you'd like to trim. Additionally, you may want to hide errors you made. The AVS file allows you to do that.

2) To remove the end of a video file, replace its line with the following:

AviSource("file02.avi")+\

=>
AviSource("file02.avi").trim(1,<end frame here>)+\

Replace <end frame here> with the number of the last frame to display (see below to compute this value).

3) To remove the start of a video file, replace its line with the following:

AviSource("file02.avi")+\

=>
AviSource("file02.avi").trim(<start frame here>,0)+\

Replace <start frame here> with the number of the first frame to display (see below to compute this value).

4) To remove some section in the middle of a video file, replace its line like this:

AviSource("file02.avi")+\

=>
AviSource("file02.avi").trim(1,<first frame to remove>)+\
AviSource("file02.avi").trim(<last frame to remove>,0)+\

This is actually the same process as above and should be self-explanatory.

5) To compute the start or end frame in the lines indicated above, download and install VirtualDub (get it here: http://virtualdub.sourceforge.net/). Open the video file in VirtualDub and use the position bar or any command in the Go menu to go precisely to the desired image. The exact frame number is indicated in the status bar.

6) Play your .AVS file again carefully. Check that everything goes smoothly and that you have removed all parts that should not be seen. The final movie will look exactly like this. Make sure it's perfect!

MeGUI

1) Download and install MeGUI. Get it here:
http://sourceforge.net/projects/megui/


2) MeGUI requires the .NET Framework. If you're using Windows XP, you may need to install it manually. Either run Windows Update and select it in the optional updates, or go to the following page to download it:
http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=0856eacb-4362-4b0d-8edd-aab15c5e04f5
If you are running Windows Vista or Windows Seven, you probably don't need to care about this.

2) Download the neroAacEnc.exe file. Get it here:
http://www.nero.com/eng/downloads-nerodigital-nero-aac-codec.php

(if the URL changes, just Google neroAacEnc.exe) Copy this file in the same folder you installed MeGUI.

2) Run MeGUI. Go to the Options / Update menu. The application should check for components to update. Click Update. Go to the Options / Settings menu. Uncheck Open Preview after AviSynth script selection.

3) In the main window, select the Input tab. In the Video encoding section, in the Encoder settings dropdown, select "X264: *scratchpad*". To the right, click Config.

4) The x264 configuration dialog appears. Down in the Presets section, click New. Type in the name of a new configuration. Choose a name that represents the type of game that you are encording. 2D and 3D games may need different encoding settings, for instance. Older games and newer games may also require different settings. Choose a name (for instance "Old 3D Games"), then click OK.

5) Select the Main tab. Check the Advanced settings checkbox. That makes several additional tabs appear. In the AVC Profiles dropdown, select "High Profile".

6) In the Modes section, select "Const. Quality" in the dropdown, then set the Quality value. This is the most important setting. It has the biggest influence on file size and video quality. The larger the value, the smaller the file. The smaller the value, the better the quality. Choose 30 as a base value. If the generated video looks bad, use a smaller value, like 28. If the file is really too big, set it to 31 or more.

7) (TODO: additional settings may need tweaking. this requires clarifying. take the following with caution) Select the Analysis tab. In the Motion Estimation section, set the M.E. Range value to 32, select "Multi Hex" in the M.E. Algorithm dropdown and set the Subpixel Refinement dropdown to "06 - RD on I/P frames". In the Macroblocks section, select "Custom" in the Partitions dropdown, then check all options in that section.

8) Click on OK to save your settings.

Note:
You may want to experiment with a special .AVS file that you'd have created with just a small part of the movie (about 5 minutes), so that you don't have to wait for hours each time you change encoding settings.

Encoding video

1) Start MeGUI. Select the Input tab. Concentrate on the Video encoding section. Make sure that in the Encoder settings dropdown, your saved settings are selected. Make sure that in the File format dropdown, "MP4" is selected.

2) Click on "..." next to the AviSynth Script field. Browse for your .AVS file.

3) In the Video output field is the name of the file that MeGUI is about to generate. I suggest that you click on "...", select a different folder to avoid confusion, and append "_Video" to the name.

4) Click on Enqueue. If you have more than one .AVS file, follow steps 2 to 4 for each one of them. Before processing the queue, you may also add the audio processing jobs described in the next section.

5) Select the Queue tab. Click Start. This operation takes a fair amount of time (several hours, depending on your computer speed). You may want to do this during the night.

6) When processing is complete, check the Status column. For each encoding job, it should read "Done". If it reads "Error", then check your .AVS file to see if it plays without error.

Encoding audio

1) Start MeGUI. Select the Input tab. Concentrate on the Audio section. Make sure that in the Encoder settings dropdown, "NERO AAC: *scratchpad*" is selected. Make sure that in the Extension dropdown, "MP4-AAC" is selected.

2) Click on "..." next to the Audio Input field. Browse for your .AVS file.

3) In the Audio output field is the name of the file that MeGUI is about to generate. I suggest that you click on "...", select a different folder to avoid confusion, and append "_Audio" to the name.

4) Click on Enqueue. If you have more than one .AVS file, follow steps 2 to 4 for each one of them.

5) Select the Queue tab. Click Start. This operation is a lot faster than the video encoding job.

6) When processing is complete, check the Status column. For each encoding job, it should read "Done". If it reads "Error", then check your .AVS file to see if it plays without error.

mkvmerge GUI

1) mkvmerge GUI is part of a set of MKV related tools name MkvToolNix. Download and install them. Get them here (scroll down for Windows version):
http://www.bunkus.org/videotools/mkvtoolnix/downloads.html


Muxing video and audio

1) Run mkvmerge GUI. Select the Input tab. Click Add. Browse for the x264 encoded video MP4 file that you have generated in the previous step. If you have more than one .AVS file, click on Append and select in sequence each additional video MP4 file.

2) Click on Add. Browse for the AAC encoded audio MP4 file that you have generated in the previous step. If you have more than one .AVS file, click on Append and select in sequence each additional audio MP4 file.

3) Next to the Output Filename field, click Browse and choose the name of the final MKV movie to generate.

4) Click Start Muxing. This operation should be fairly quick.

5) Play the resulting file. Skim through it to look for playback errors and sound desynchronization.

Creating more than one movie

If the game is logically split into episodes or chapters, you may decide to submit several separate movies. To do this, follow the above steps with the following differences:

1) Create separate .AVS files for each episode. You may create more than one .AVS file per episode, but make sure that two episodes are not in the same .AVS file.

2) When creating the final files using mkvmerge GUI, do not click on Append. Instead, generate each episode separately.
Connor
A trick for extracting a sequence from the middle of a movie is to not use;
AviSource("file02.avi").trim(1,)+\ 
AviSource("file02.avi").trim(,0)+\


but instead use;

orig=AviSource("file02.avi")
a=Trim(orig, 1,)
b=Trim(orig, ,0)
a+b


(by the way, shouldn't the first trim also use '0' not '1'? AviSynth indexes the frames beginning at 0, so that will drop the first frame of the clip.

Anyway, this only loads the clip once, which is a lot faster if it is big, and will also work very well if you have lots of small clips that need cutting, since it basically at least halves the amount of file-loads used.

The "a+b" at the end is used to actually output something, putting AviSource and Trim into a variable like I do doesn't give any output.

Also, by splitting the two sections into two variables, it becomes much easier to do things like;
Dissolve(a, b, 25)

which will merge the end of clip 'a' into the beginning of clip 'b' with a dissolve effect during 25 frames. Or;
FadeOut(a, 12)
FadeIn(b, 12)

to fade-to-black between the clips for a total of 24 frames.
You can view all discussion threads in this forum.
You cannot start a new discussion thread in this forum.
You cannot reply in this discussion thread.
You cannot start on a poll in this forum.
You cannot upload attachments in this forum.
You cannot download attachments in this forum.