Video Encoding

From wiki.gp2x.org

The GP2X, using the default software, has the ability to play two different video formats: DivX, XviD, and two different audio formats: MP3, OGG Vorbis.

MP2x (modified version of the default player) adds the ability to play AAC and AC3 formats.

As of firmware 2.1.0, OGM can also be played by default.This feature was available in earlier firmwares too, but until 2.1.0 .ogm files did not show up in the file browser. To play OGM files in firmwares 2.0.0 and below, rename them to .avi .

Contents

Converting Videos

Main view
File selector
V Filter menu
For converting .avi files for use on the GP2X, Avidemux is an extremely easy-to-use and reliable solution. It can also convert MPEG-compatible DVD rips and files. See it's compatible formats list.

This article will walk you through encoding a video and ripping a DVD.

Installing

Download Avidemux for your platform, it supports all common platforms. Install it from your package manager if you're on Linux, or run the installers on Windows or OS X. Load it up.

Converting

  • First, we'll open a file. If you get a box like this:

Avidemux vopdivx.png

or something similar asking to rebuild the key/IPO frames, or to reconstruct the sound timings, hit Yes. It'll unpack the video, which shouldn't take too long, regardless of your processor:
Avidemux unpack.png

  • Okay, now we want to set the video codec. On the side, click the droplist under Video and choose XviD4, unless you have a good reason otherwise. Under Audio, select Lame.
  • Under Video, choose Filters or V Filter. We want to set the video so it's the correct size for the GP2X screen. Although the GP2X has a clever chip that resizes videos, you can save battery life and space on your SD card by making the resolution 320x240 by default.
  • In the menu, click Add and select MPlayer Resize. Another window will come up, check the 16 Round Up box and drag the slider until the hight text box is 240.
  • The width box might not be 320, which is what we want. We fix this by clicking OK and then Add in the menu again. This time, we select Crop. Use your computer's calculator or work out yourself: (width - 320) / 2.
  • In the crop box, put the result in the Crop Right and Left boxes. This will chop off the sides equally, which might not be to your taste, but that's what the GP2X will do if you don't.
  • Click OK, then Close in the Filter menu. Press F5. You should see a preview box come up showing how the finished video should look. Press Play to see the video in action - don't worry if it appears jittery.
  • Now that you've set everything up, go to File -> Save As.. and save it to what you want, adding a .avi extension.

Congratulations! You've got a converted video ready for your GP2X.

Avidemux Notes

Encoding Options Notes

There are several ways you can set the quality/size of movies on the gp2x.

Video:

Bitrate mode: You can choose between:

Single Pass - Bitrate 
Here you can set the bitrate of the video. ~250-300 is a good number to choose.
Single Pass - Quantizer 
This applies a set compression to each frame. You're less likely to want this one.
Two Pass - File Size 
This allows you to pick the file size that you want to aim for, and is probably the most useful.

Audio:

Choose between mono or joint stereo, then choose a bitrate. Pick one betweeen 32 and 192, depending on how good you want the audio to be, but note that it isn't really worth having one above 128 if you're using headphones. (See below for an explanation of why to choose CBR).

Gp2x Compatibility Notes

  • Don't select "Quarter Pixel" or "Global Motion Compression" options - these produce video that the default gp2x mplayer cannot handle.
  • The GP2x has ability to play subtitles in .srt format but can't support special characters like à,é,û, ç; although MP2x can display subtitles with special characters.
  • The GP2X supports most video sizes, but you will experience choppy playback when playing very high-bitrate files, such as 1024x768 resolution videos. It is therefore advised, to save both (a lot of) battery life and SD card space, to resize to 320x240, or a maximum of 640x480 if you plan on viewing your videos on TV-Out.
  • To avoid synchronisation problems between image and audio when using MP3 you should not use variable bitrate audio compression. Instead, use constant bitrate compression. An SD card with at least 66x speed is recommended for optimal video playback.

Batch Conversions with avidemux

If you have more than one file to convert, you may wish to try a batch conversion. Follow the directions above, but do not save the file. Instead click file, Add to Job List. Give the job a name and select an output location and filename. Then, click file, open and select the next file. You may have to set your filters each time, although the audio and video codec should be retained from the previous job.

Once all of your files are added to the joblist, click file, show joblist. A dialog will appear. If you are satisfied with the joblist, click run all jobs. The files will be converted and saved in a serial queue, and you will not be required to provide any further input.

DVD to GP2X

Note: This is illegal in many countries (in the US under the DMCA, for example). You may or may not wish to read up on your local laws on the matter before proceeding.

Note: you will need about 4 gigs or more of free space on your hard drive in order to do this. You'll need Avidemux and either mencoder or DVD Decrypter for this.

Ripping the DVD

  • Windows:
  1. Run DVD Decrypter.
  2. The program will auto-detect the DVD in the drive, and if the DVD has a copy protection (which it most likely will), the program will ask you what region the DVD is coded for. [1]
  3. The program will also, by default, select all the files on the DVD. Do not deselect any of the files, as some may be needed for encoding, or may contain subtitles.
  4. Click the button at the bottom of the program with the DVD icon and the hard drive icon. [2]
  5. Once the files are completely ripped onto your hard drive, you can find them in the root directory of your hard drive. For instance, if I ripped Hero, the directory of the files should be in the folder. C:\HERO\VIDEO_TS
  • Linux:
  1. Open up a terminal and type
mplayer dvd://1 -dumpstream -dumpfile rippeddvd.vob
  1. This will generate a .VOB file to use.

The files generated will be a myriad of .VOB, .BUP, .IFO, and .SRM files. They can sometimes be played by a media player as if they were a DVD, and include menus, special features, etc. Usually, the file labeled VIDEO_TS.IFO is the file that compiles them all together as the DVD.

Encoding the rip

Load this rippeddvd.vob file into Avidemux by either clicking the "Open" folder icon in the toolbar, or going File->Open.

You will now be presented with a dialog box with a dropdown list of audio stream choices. This is where you pick which audio track on your DVD you want to use for your video. Generally the default, or first in the list is the best choice. Click "OK" to begin indexing the MPEG. This may take a number of minutes depending on the speed of your machine.

Note: Avidemux does not read MPEG streams. It has been designed to read an MPEG 
stream index. An MPEG stream index is a plain text file containing a description 
of the MPEG and the location of frames throughout the stream. This file allows 
Avidemux to random seek and stay accurate. Said otherwise, without the index, 
Avidemux cannot handle MPEG files.

Some DVDs are coded as 23.976 aka FILM (most movies actually). Some others are 
coded as 29.96 (NTSC), soap for example. In the first case, the DVD player does an
operation to convert it on the fly to NTSC format (telecine). So the MPEG header 
always says 29.96 as it will always be the final format.

This means that Avidemux cannot tell the difference between FILM and NTSC. So if 
the MPEG looks progressive (not interlaced) and obvious desync appears (and gets 
worse and worse), use Video->Frame Rate and set it to 23.976.
For PAL MPEG, there is no problem, it is always 25 fps.
If audio is present, Avidemux will try to guesstimate if the video is 23.976 by 
comparing audio and video duration.

You'll probably want to crop the top and bottom black borders from the rip before proceeding.

  1. To crop the video, we must use the video filters. Before selecting the filters however, use the slider bar at the bottom to select a spot in the middle of the movie. The reason for this, is that auto crop feature will adjust the cropping based on the current frame.
  2. Now press the Video Filters button to popup the video filter list.
  3. Add Transformation -> Crop.
  4. Now click the "AutoCrop" button. You'll notice the black areas will now appear in green to show the areas where the video will be cropped.
  5. If you like the way it looks click "OK" and then close the video filters list.

You can now use the rest of the tutorial above to encode the video

Subtitles

The benefit of having separate subtitle files for your file instead of burning them onto the movie is that many movie players can change the font, the color, and the location of the subtitles.

  • Windows
  1. Download and open SubRip.
  2. Under “File” select “Open VOB(S)” A new window pops up. [3]
  3. Click “Open IFO”. Select the folder that your DVD is ripped to, and select the “VTS_01_0.IFO” file, or the same file you encoded earlier. Click “Open”. [4] A window will pop up saying “Closed Captions Found”. [5]
  4. Select which language to use from the drop down menu, and make sure all of the Vob(Sub) files are selected. Then click “Start”. [6]
  5. It might take a while to load the subtitle file, so be patient.
  6. SubRip will ask you to identify the characters that it is highlighting. This is a mighty task for the first few minutes, but after a while, it will recognize all of the characters used. [7]

Some errors do occur, as the last photo illustrates. I suggest downloading Subtitle Workshop. There you can edit to your heart's content the subtitle file, and save it as a SAMI subtitle.

You will then be required to convert the subtitle file to SAMI format. A shareware program called Sub Studio SAMI should be sufficient to convert the subtitle.

  • Linux

Using the MPlayer option -dumpsami one should be able to convert most types of subtitles. This does not include VobSubs, which must be converted to another type of subtitle before SAMI.

VideoLan

VideoLan aka VLC is not only a multi-platform multimedia player but also a powerful, scriptable multimedia converter and streamer.

Here's a Windows batch file converting multiple videos dragged all together on the .bat file one after the other

This script should now create a properly formatted avi file, works on recent versions of vlc.

:loop
if %1=="" goto end
start "Blah" /low /b /wait "C:\Program Files\VideoLAN\VLC\vlc.exe" -vvv %1 :sout=#transcode{vcodec=DIV3,vb=300,acodec=mp3,ab=64,channels=1,audio-sync,width=320,height=240,fps=15}:duplicate{dst=std{access=file,mux=avi,dst=%1_gp2x.avi}} vlc:quit
shift /1
goto loop
:end

Note that it could easily adapted to be a *nix script.

Mencoder

You can also use mencoder to encode your videos. Here is a similar batch file that uses mencoder in place of VLC. Just like the VLC batch, you can drag and drop multiple files onto it, and go to sleep. It took 45 minutes to transcode a 45 minute television episode using this batch.

:loop
if %1=="" goto end
start "Blah" /high /b /wait "c:\mplayer\mencoder.exe" %1 -o "C:\gp2xVideoConverter\%~n1_gp2x.avi" -ovc xvid -xvidencopts bitrate=300 -vop scale=320:240 -ofps 30 -oac mp3lame -lameopts abr:br=128 mode=3
shift /1
goto loop
:end

Note that this batch file assumes you've installed mplayer to c:\mplayer\. You will have to adjust the path if you installed it elsewhere. The transcoded video can be placed in any folder you like, just adjust the -o argument to point to the appropriate folder. Save time by having the script place the video right on your SD card!

Note+ that mencoder is started with a low priority thread to make the transcoding while doing other tasks non-migraine inducing. If you want to encode videos faster and don't mind your computer responding like a wounded turtle, you can change the /low to /high or even /realtime if you want your computer to respond like a potted plant, but finish during your lunch break.

Note++ because the %~n1 variable is used to pull just the filename portion of the %1 passed-parameter this script will only work on Windows 2000 or higher.

Caution: This is for an older version of mencoder. This script will not work with the latest version. use -vf instead of -vop. Use cbr (constant bit rate) so video and audio stay in sync. Can do two pass encoding to shave ~30megs off a file too.

FFMpeg

You can alse use ffmeg to encode your videos. Here is another batch file that uses ffmpeg in place of VLC or mencoder. It took ~10 minutes to encode a 45 minute tv show with 60% reduction in size at high priority using this batch.

:loop
if %1=="" goto end
start "Blah" /high /b /wait "c:\gp2xVideoConverter\ffmpeg.exe" -i %1 -f avi -vcodec xvid -b 300k -s 320x240 -r 30 -acodec mp3 -ar  44100 -ab 128k -ac 1 -async 44100 "C:\gp2xVideoConverter\%~n1_gp2x.avi"
shift /1
goto loop
:end

Note that this batch file expects to be run from the folder c:\gp2xVideoConverter\ and have ffmpeg.exe residing in the same. The transcoded video can be placed in any folder you like, just adjust the final argument to point to the appropriate folder. Save time by having the script place the video right on your SD card!

Note+ that ffmpeg is started with a low priority thread to make the transcoding while doing other tasks non-migraine inducing. If you want to encode videos faster and don't mind your computer responding like a wounded turtle, you can change the /low to /high or even /realtime if you want your computer to respond like a potted plant, but finish during your smoke break.

Note++ because the %~n1 variable is used to pull just the filename portion of the %1 passed-parameter this script will only work on Windows 2000 or higher.

Mac OS

Manual Transcoding

MPlayer can read directly from, and convert from, encrypted DVDs. The best way to confirm this is to attempt to play the DVD in mplayer. That being said, the following step is optional, but it does allow for quicker encoding.

Extracting VOBs

You can use mplayer as with Linux, or follow these instructions:

  1. Download OSeX
  2. Select the correct title, and choose the angles, audio tracks, and subtitle tracks you want.
  3. Hit "Begin"
  4. Specify where you want the information extracted
  5. Wait.
  6. Convert the files as above

Converting Subtitles

Unfortunately, on Mac OS X, there are nowhere near the amounf of subtitle tools for Mac OS X compared to Linux, and even that pales in comparison to Windows. However, there are enough tools to convert DVD subtitles to SAMI subtitles for use with the GP2X.

  1. Download D-Subtitler
  2. Install MPlayer. You can install the MPlayerOSX binaries and they should do fine The MPlayer Soure compiling also works, but is not neccessary for this.
  3. Use D-Subtitler to extract the subtitles from the extracted VOBs (Extracting subtitles from an encrypted DVD will not work)
  4. Feed D-Subtitler with the proper identification of characters as it requests it
  5. When the SRT editor comes up, spell check it, and confirm that the OCR engine properly identified all the letters (Often 1's, 0's, O's, l's and I's confuse the engine and will produce rather odd results)
  6. Once the SRT subtitle file is saved, Open MPlayerOSX or a Terminal.
  7. Activate MPlayer with the following options:
-ovc null -vo null -oac null -ao null -noframedrop -dumpsami

In MPlayerOSX there should be an option to specify additional options. That is where you insert that line.

Supported Formats

This is a list of supported video format and settings for the factory shipped GP2X video player. Through testing I found some sizes and settings for MPEG didn't work, this list is to help people avoid running into format problems.

Tested, worked: XviD, DivX 3.11, 4.x, 5.x, 6.x (all as .avi)

Tested, did not work: DivX 1.x, 2.x, 3.0-.3.1, .mp4, .VOB

Personal tools