Thursday, December 29, 2011

Quick Start Guide to StaxRip

This tutorial wishes to present a quick start guide of how an mpeg2 standard definition video (capped from satellite broadcasts) can be transcoded into x264 mkv, using StaxRip. The operating system used in this example is Windows 7.

Basic steps

  1. Capping the raw video
  2. Editing the raw video (optional): this will be our source video
  3. Getting StaxRip
  4. Installing StaxRip
  5. Setting up StaxRip to transcode the source, this includes: codec settings, deinterlacing, cropping, bitrate
  6. Transcoding
  7. Checking the output for various errors
  8. Correcting errors (if they occur)
  9. Enjoying the output :)

The source video

This tutorial assumes that we have a finalized source video (i.e., we have edited it, got rid of commercial breaks and other unwanted parts), ready to be transcoded into x264 in StaxRip. I will use a fairly standard tennis video in my examples below, which I recorded from an FTA (free-to-air) DVB satellite channel, JSC Sports 2. This channel broadcasts in standard definition, its quality is farly mediocre, neither outstandingly high nor too crappy. These are the basic properties of the source video (you can get these information using MediaInfo, for example):

  • video container: transport stream (.ts)
  • video codec: mpeg2
  • frame rate & interlacing: 25 fps interlaced
  • storage resolution: 720 x 576 pixels (counted in anamorphic pixels)
  • display resolution: 1047 x 576 pixels (counted in square pixels)
  • display aspect ratio: 16:9 ("widescreen")
  • average bitrate: 4.9 Mbps
  • audio: mp2, 256 Kbps, 48 KHz, stereo
  • size of file: 59.1 MB
Transport stream mpeg2 is how most non-hd channels broadcast over satellite, it is a standard format, and this is how my satellite receiver card is recordig the dvb stream onto the hard disc drive: the dvb data is captured as it is beamed from the satellite, untouched. So, effectively, this is a raw video. In this tutorial the name of the raw file is x264test.ts.

Getting StaxRip

Make sure that you download StaxRip from the official site: http://staxmedia.sourceforge.net/. Go to the project Summary Page: http://sourceforge.net/projects/staxmedia/. Click on Files, and download the latest version. At the time of writing this guide, the latest version is 1.1.7.1_beta:

Installing StaxRip

Installing StaxRip simply means copying the files and folders in the 7z archive to a directory of your choice (there is no separate setup file). You can open up the 7z file in WinRAR for example. Extract all the files into a folder. In our example we will call the folder where we copy the files "StaxRip_1.1.7.1beta":

To launch StaxRip, simply double-click on StaxRip.exe. It is perhaps better to create a shortcut on your desktop:

Transcoding in StaxRip

When you first launch StaxRip after successfully installing it, it will show the Getting Started window:
We will create our own template, so you can tick Don't show this next startup, and click Close. The main window of Staxrip is now visible:
We will modify the various settings here and save it as a new template that we can use over and over again (so we do not have to do all the settings again).

Setting the x264 codec

First, we modify and configure the codec. (Notice that the MKV container was already active, so we don't need to find and select it.) Click on DivXPlus, then click on x264 Film HQ:
With this, we selected the x264 codec. The small window displays the most important settings of the codec that we selected. Next, click on Config Codec:

The window that opens up next is where all the x264 settings can be configured:
Let us first concentrate on the Mode setting. Select Bitrate.
Bitrate and Two Pass both achieve the same thing: with this setting we can aim at a particular file size or a particular (average) bit rate. Bitrate uses only one pass of transcoding, while Two Pass achieves the same thing slower as it requires two passes: the first pass is a quick one (unless you put a tick next to Slow Firstpass – but it is really not necessary): it creates a stats file, which “contains information about every input frame, which can be input to x264 in order to improve the output. The idea is you run a first pass to generate the stats file, and the second pass will create an optimized encode of the video. The improvement is mostly gained from better ratecontrol” (source: Official x264 settings). For average or low-quality SD sources, I usually use the 1-pass Bitrate mode:
The only setting we modify for this basic example is the Frame Options. Tick Deblocking and write -2 for both Strength and Threshold:
No other setting will be modified. Click on OK.

Deinterlacing

Next we will specifiy a deinterlacer filter. Our source is an interlaced video, so it is very important that during transcoding the video is deinterlaced, otherwise the quality will be inferior. Interlacing basically means that each picture frame contains two half pictures or “fields” mixed together, but they are slightly shifted in time. Since there are 25 such frames every second, there are 50 half-fields shown in a video per second (or 60 in the case of NTSC video). StaxRip includes a built-in deinterlacer, but in this tutorial we will use another deinterlacer, which will make sure that the moving scenes in the video will be smooth, fluid, without so-called saw tooth edge distortions (also known as “combing” artifacts). It achieves this by separating the two half fields of each interlaced frames, and placing them after one another (so there is no mixing together, no interlacing) – this is called progressive scanning. Thus, the deinterlacer will create a 50 fps progressive video if the source video was 25 fps interlaced (as in our example); if your source is 30 fps interlaced, the output will be 60 fps progressive). This interlacing method is called progressive “bobbing” or full framerate deinterlacing. The filter that we will use and install into StaxRip is LeakKernelDeint (we will use its Bob module, called LeakKernelBob, to achieve bobbing deinterlacing). (Of course, if your source is not interlaced but progressive, you do not have to use deinterlacing! Put no tick before Field.)

To get LeakKernelDeint, go to http://avisynth.org/mediawiki/External_filters#Deinterlacing. Click on the Plugin link for LeakKernelDeint: http://leak.no-ip.org/AviSynth/LeakKernelDeint/. Download LeakKernelDeint_1.5.4.zip. We will install LeakKernelDeint into a folder where StaxRip can automatically load this filter from. This folder can be found if you click Tools > Directories > Plugins. Extract all the content of LeakKernelDeint_1.5.4.zip into the folder that opens up
Now, we create the filter profile for LeakKernelBob in StaxRip. Right-click the Filters list and select Profiles... from the context menu.
A window opens up showing the filter profile definitions. Write this line right below [Field]: LeakKernelBob = LeakKernelBob(order=1,sharp=true) After writing in this line, click OK.
Now, we can select the LeakKernelBob deinterlacer filter when we click on the Field inside Filters:
Before we save all these settings as a template, make sure that you have NO tick before Crop in the Filters (it is always advisable to set the cropping manually, not automatically):

Saving the settings into a template

It is time to save all these settings as a template. Click Project > Save as Template. A small window opens up. Give a name to your template, e.g. SD x264-mkv Leak. If you want this template to open up whenever you start StaxRip, tick Load template on startup (this is a good idea if you use these settings a lot...). Click OK.
Now, close Staxrip, then start it again. All your settings will open up as you saved them into the SD x264-mkv Leak template.

Loading the source

It's time to load the source file into StaxRip. In our case, the source is x264test.ts. Simply drag the file into the Source field of StaxRip:
Now, StaxRip will start demuxing the ts file, and will be ready to start the transcoding.
If, however, the following window pops up, do the following:
Close the warning. Go to Tools > Settings. Select Demuxing. Make sure there are NO ticks before DGIndexNV. (I usually do not tick ProjectX either as I do not fix Mpeg-2 sources inside Staxrip). After unticking, click OK.
Now, you can drop your file to the Source field, Staxrip will demux it, and it is now really ready to transcode. (Notice that StaxRip has created a folder next to the source file. This folder contains various helping files for StaxRip for the transocding. You can delete this folder after the transoding has finished successfully.)

Cropping

The next step is to check if it is necessary to crop the video. Click on Crop:
The Crop window opens up, showing the first frame of the source video. Now, if you see black bars on the top/bottom or left/right, you should crop the video, otherwise the transcoding into x264 will not be efficient enough. In our example, it is necessary to crop (look at the black bars at the edges):
Move your cursor to the edge where the black bar is. A blue bar will occur. Use the + or - key to move that edge/margin (one click on the + or - key moves the edge by 2 pixels). Important: the value for “Mod” must always be 16/16 after cropping! In our case the original resolution was 720x576 pixels. After cropping the four edges by -8 pixels, we get 704x560 pixels, which is Mod 16/16 (there are no errors). Close the window.
Notice that the main window now shows the cropped values (and that there are no errors):

Specifying the bitrate, begin transcoding

Last, we specify the Target settings. We will give 1600 for the Video Bitrate. For medium/low-quality SD mpeg-2 sources a value between 1300–1800 Kbps is enough (you may want to experiment with the values depending on the quality of your source); notice that the approximate output size is also automatically given:
The Audio settings (at the bottom) can remain as they are: we will use the default 96 kbps AAC audio codec.
Click on Next. The Job window pops up, click on Start. The transcoding begins. First the audio is being transcoded:
Then the transcoding into x264 is being done.
Finally, mkvmerge merges the x264 video and AAC audio into an mkv “container”. The transcoding has finished, the output is x264test.mkv. Play the file, check if everything is fine. If you open up the file in Mediainfo, it shows that the output is indeed x264 with AAC audio, and it is 50 fps progressive (thanks to the LeakKernelBob deinterlacer filter).

Congratulations! You have transcoded an mpeg2 SD file into x264!

3 comments:

  1. Hey! I just wanted to ask if you ever have any problems with hackers?
    My last blog (wordpress) was hacked and I ended up losing many months of hard work due
    to no back up. Do you have any solutions to prevent hackers?


    Take a look at my blog - Louis Vuitton Pas Cher

    ReplyDelete
  2. what s the best settings 4 high quality but with minimum size ( as possible )

    ReplyDelete
  3. finally i can properly using staxrip :) thx

    ReplyDelete