View Page Source

Revision (current)
Last Updated by adelikat on 8/31/2023 1:53 AM
Back to Page


Prior to encoding, you will need to add both the logo and subtitles conforming to the [Encoder Guidelines] to the video.  Depending on the software you are using, you can use either of the following processes to do that.

You will first need to prepare a set of subtitles.  Per the [Encoder Guidelines] this should comprise two subtitles each with length of about 5 seconds for a total of 10 seconds and should normally be timed to roughly coincide with the beginning of game play.

First, you will need to select a segment of the video to display the subtitles over, and make a note of the starting time or frames; you will also need to decide where to display the subtitles on the screen to avoid obscuring the action.

Once you have this information, proceed according to the software you are using.

%%TAB mencoder%%
__Subtitles__%%%
Prepare either a .srt file or a .sub file.

The format of a .srt file is
 1
 hh:mm:ss.sss --> hh:mm:ss.sss
 <game name> in <time>
 by <author>  Rerecord count: <rerecords>
 
 2
 hh:mm:ss.sss --> hh:mm:ss.sss
 This is a tool-assisted recording.
 For details, visit !https://TASvideos.org/

The format of a .sub file is
 {start frame}{end frame}<game name> in <time>|by <author>  Rerecord count: <rerecords>
 {start frame}{end frame}This is a tool-assisted recording.|For details, visit !https://TASvideos.org/

It is slightly easier to use .srt files over .sub files where you know timestamps as opposed to frame numbers, and vice-versa.

__Logo-combining__%%%
The next step is to combine your logo with the video stream you have just created, which will serve as the input for encoding. It is recommended that you use a means of duplicate frame removal in combination with this step, so as to save disk space at no visual quality loss - for example, you may wish to try [user:sgrunt]'s [EncodingGuide/Legacy/DedupC | command-line dedup filter] (instructions for its use in conjunction with this step are provided there).

Assuming your logo is {{logo.avi}}, your raw video dump is {{raw.avi}}[#1], and your subtitle file is {{subtitle.srt}}, use the following command line to combine your logo, subtitles, and raw video:
 mencoder logo.avi raw.avi -sub subtitle.srt -subpos 98 -subalign 2 -oac copy -ovc x264 -x264encopts crf=0:fullrange=on -sws 9 -o in.avi

* __{{-sub subtitle.srt}}__: this is the subtitle file.
* __{{-subpos 98}}__: Specifies the vertical position of the subtitle in percentage of the height.  If you want subtitles at the top, specify {{-subpos 2}} instead.
* __{{-subalign 2}}__: Indicates that the bottom of the subtitles is aligned with the above position; this is used with subtitles at the bottom of the screen.  For top-aligned subtitles, use {{-subalign 0}} instead.
* __{{-oac copy}}__: Specifies the audio codec to use; in this case it just copies the input audio tracks directly.  This doesn't always work - try {{-oac pcm}} if it doesn't work.
* __{{-ovc x264 -x264encopts crf=0:fullrange=on}}__: This transcodes the video to lossless x264, placing it into the YV12 colour space...
* __{{-sws 9}}__: ...using a Lanczos scaling algorithm - in this case, it is used for chroma resampling from RGB32 to YV12.  x264 expects YV12 input, and this ensures that a known (and preferred) chroma resampling algorithm is used for transcoding to that colour space.
* __{{-o in.avi}}__: This is the output file name.

Once this is done, you will need to extract the audio track for audio encoding using {{mplayer}}:
 mplayer -ao pcm:fast:file=audio.wav -vc dummy -vo dummy in.avi
* __{{-ao pcm:fast:file.audio.wav}}__: Dumps the audio track as a WAV to audio.wav.
* __{{-vc dummy -vo dummy}}__: Disables video output and display (this speeds up the video extraction process).

%%TAB AVISynth%%
You will not need to logo-combine with AVISynth per se in that there is no intermediate file - instead, you will be using two scripts.

These scripts employ the [http://akuvian.org/src/avisynth/dedup/|DeDup plugin] for duplicate frame removal; you generally need to place the plugin (and the support DLLs from the bottom of that page) in one of: the same directory as the scripts, your /Windows/System32 directory, or your AVISynth plugins directory (which of these is necessary seems to vary from system to system).

Here are the contents of the first script, which you can save as, for example, {{script1.avs}}:
%%SRC_EMBED avs
LoadPlugin("DeDup.dll")
#Open the source
a = AVISource("movie.avi")
#Defines how long the logo goes for and the source of the logo
b = ImageSource(file="logo.png", start=0, end=119, fps=a.FrameRate).ConvertToRGB24()
#Adds blank audio to the logo
c = BlankClip(b, audio_rate=a.AudioRate, channels=a.AudioChannels, sample_type="16bit")
d = AudioDub(b, c).Lanczos4Resize(c.width, c.height).AssumeFPS(a.FrameRateNumerator, a.FrameRateDenominator)
#Adds the logo and movie together
last = d + a
#Below are the subtitles, text_color is usually set to 00FFFFFF, but for the sake of looking somewhat interesting, the 00
#is set to 30 to make them slightly transparent. \n is a line separator, first_frame and last_frame give the time frame for
#how long the subtitles last.
Subtitle("Super Example Bros. by Heavy Weapons Guy\nPlaying time: 4:48.07\nRerecord count: 9001", y=165, align=8, first_frame=737, last_frame=1037, size=13.0, text_color=$30FFFFFF, halo_color=$00000000, lsp=1)
Subtitle("This is a tool-assisted recording.\nFor details, visit https://TASVideos.org/", y=180, align=8, first_frame=1038, last_frame=1338, size=15.0, text_color=$30FFFFFF, halo_color=$00000000, lsp=1)
#Converts the video to a colourspace that can be read by direct264 or x264
ConvertToYV24(chromaresample="point", matrix="PC.601")
ConvertToYV12(chromaresample="lanczos4", matrix="PC.601")
#This should match the "log" file name in the other script
DupMC(log="dup.txt")
%%END_EMBED

Here are the contents of the second script ({{script2.avs}}):
%%SRC_EMBED avs
LoadPlugin("DeDup.dll")
#Open the source
a = AVISource("movie.avi")
#Defines how long the logo goes for and the source of the logo
b = ImageSource(file="logo.png", start=0, end=119, fps=a.FrameRate).ConvertToRGB24()
#Adds blank audio to the logo
c = BlankClip(b, audio_rate=a.AudioRate, channels=a.AudioChannels, sample_type="16bit")
d = AudioDub(b, c).Lanczos4Resize(c.width, c.height).AssumeFPS(a.FrameRateNumerator, a.FrameRateDenominator)
#Adds the logo and movie together
last = d + a
#Below are the subtitles, text_color is usually set to 00FFFFFF, but for the sake of looking somewhat interesting, the 00
#is set to 30 to make them slightly transparent. \n is a line separator, first_frame and last_frame give the time frame for
#how long the subtitles last.
Subtitle("Super Example Bros. by Heavy Weapons Guy\nPlaying time: 4:48.07\nRerecord count: 9001", y=165, align=8, first_frame=737, last_frame=1037, size=13.0, text_color=$30FFFFFF, halo_color=$00000000, lsp=1)
Subtitle("This is a tool-assisted recording.\nFor details, visit https://TASVideos.org/", y=180, align=8, first_frame=1038, last_frame=1338, size=15.0, text_color=$30FFFFFF, halo_color=$00000000, lsp=1)
#Converts the video to a colourspace that can be read by direct264 or x264
ConvertToYV24(chromaresample="point", matrix="PC.601")
ConvertToYV12(chromaresample="lanczos4", matrix="PC.601")
#TODO: Explain the individual parts of the scripts, and can maxdrops be set higher higher without breaking the video?
#The filenames of the logs should probably be changed to make sense, also,
#as long as "log" is consistent with the other script.
DeDup(threshold=0.00001, trigger2=100, show=false, dec=true, decwhich=0, maxcopies=20, maxdrops=20, log="dup.txt", times="times.txt")
%%END_EMBED

Note that the scripts are virtually identical except for the last lines; you may consider combining them into one script controlled by a variable (done with some of the other encoding scripts currently in use).

You will want to specify the appropriate input movie file in place of {{movie.avi}} and your own logo in place of {{logo.png}} (this script assumes you are using a still frame logo).

If your movie file is in multiple parts, adjust your script to load all of them (e.g. {{a2 = AVISource("movie_part2.avi")}}) and include them on the {{last =}} line ({{last = d + a + a2 + [[...]]}})[2].

Remember to update the subtitles to reflect the current run; this includes choosing appropriate frames at which to display them.

Prior to the actual encoding step, you will need to generate two information files containing duplicate frame information ({{dup.txt}}) and time codes ({{times.txt}}) from the first and second scripts respectively; these are needed for the final encoding pass. It is fastest to use VirtualDub for this purpose:
# Load {{script1.avs}} into VirtualDub;
# Immediately select ''File -> Run video analysis pass'' (this generates {{dup.txt}});
# Load {{script2.avs}} into VirtualDub ({{times.txt}} is generated simply by loading the script).

Another approach for this is to use {{x264}}:
 x264 --crf 0 --keyint infinite --fullrange on -o NUL script1.avs
 x264 --crf 0 --keyint infinite --fullrange on --frames 1 -o NUL script2.avs

{{--crf 0}} signifies lossless encoding; it is used here to get a gauge of how suited your video is for lossless compression. This method is useful for checking if lossless encoding might be suitable for the final encode; if the bit rate that it output from this is less than around 400 kbit/s (platform-dependent) you might try specifying {{--crf 0}} instead of {{--crf 20}} during the actual encoding step.

You will also need to extract the audio; you can use VirtualDub for this purpose - while you have the (second) script loaded, go to the ''File'' menu and select ''Save WAV...''.
%%TAB_END%%

If you are encoding to AAC audio (to any container), you will need to remove a small amount of silence from the beginning of your extracted audio track to account for a delay introduced as part of the encoding process.  This delay depends on the audio sampling rate and the value you specify for {{-q}}:
||Audio||Delay at {{-q 0.25}} (ms)||Delay at {{-q 0.50}} (ms)||
|44.1KHz|-105|-59|
|48KHz|-97|-54|
|f kHz|-4672/f|-2624/f|

You can extract the value of this delay after encoding the file using MP4Box (see next page); if a value for your sampling rate isn't listed, try encoding a small test clip first and use that to extract the audio delay.

For Windows users, you can remove the delay in ''VirtualDub'' by selecting the Interleave option from the Audio menu and delaying the audio track by a negative amount of milliseconds.

A more precise method is to use SoX. The delay can be removed using (replace 4672s with 2624s if using {{-q 0.50}}. Note that this value is positive):
 sox audio.wav audio-fixed.wav trim 4672s
This reads from __{{audio.wav}}__ and writes to __{{audio-fixed.wav}}__ stripping off the first 4672 samples.

----
Next page: [EncodingGuide/Legacy/Encoding|Encoding]%%%
Previous page: [EncodingGuide/VideoDumping|VideoDumping]

[1]: If you have multiple video files, specify all of them on the following command line.

[2]: The use of ++ (or AlignedSplice) is always incorrect when dealing with lossless emulator dumps.  It mangles the sound track; if your dump has a/v desync with + (or UnalignedSplice), then it must be fixed in some other way (if it can be fixed at all).