avi2mjpg: versatile AVI/MPEG->PAL/NTSC converter
------------------------------------------------

 
Features:
~~~~~~~~~

-cropping  (with X'ish --geometry)
-scaling   (--scale newwidthxnewheight)
-add borders to so that the width and height are a multiple of 16 (atomatic)
-small speed changes (24fps->25fps)
-anything around 24.5fps -> NTSC with the 3:2 pulldown algorithm
-video preview on Buz/LML33/DC10(+) hardware via TV-out
-framerepeat to double the output framerate (although the player should do this)
-sound resample (n-th degree polynomial interpolation), any output rate
-subtitles (thanks to mplayer, you need special fonts for it to work, read on)
-can read pretty much all avi's


Future:
~~~~~~~

-the program should work in YUV space because then the conversions to and from
 BGR are not required (prettier, faster)
-resuming
-faster scaling algorithm (implement it yourself in scaler.cpp and 
  send it to me)
-interlaced PAL <-> interlaced NTSC


Required software:
~~~~~~~~~~~~~~~~~~

You need (avifile-0.6 or) avifile-0.53.5. 
Note: avifile-0.6 is currently not recommended.

Obtain the source from from
http://avifile.sourceforge.net . You also need some windows DLL files, 
these can also be obtained from http://avifile.sourceforge.net . 
Install the windows binaries in /usr/lib/win32/.

And then compile/install it by doing (in avifile-0.{6,53.5}/ of course):
$./autogen.sh (if avifile-0.6)
$./configure; make
$su
#make install; ldconfig

Test avifile by running aviplay and playing some avi's.


Compiling:
~~~~~~~~~~

Run ./configure; make in the jpeg-mmx/ directory. This directory contains a 
slightly modified libjpeg to handle the BGR frames I get from avifile.

Run ./configure; make in the libmpeg3/ directory and copy libmpeg3.a from
libmpeg3/$ARCH directory to libmpeg3/. My $ARG is i586. So I did:
$ cp libmpeg3/i586/libmpeg3.a libmpeg3/

(you can also put another version of libmpeg3 in this directory, it 
shouldn't matter) This version contains two little changes to get it 
accepted by my C compiler.

Edit config.h.

Then type 'make' in this directory. This should produce 'avi2mjpg'.


Installing:
~~~~~~~~~~~

Just copy avi2mjpg to /usr/local/bin. If you want subtitle support you need
the mplayer font package 'mp_font3.zip'. Get it from http://www.mplayerhq.hu.
Make a directory ~/.mplayer/font and unpack the archive there.


Usage:
~~~~~~

Convert 640x360 DivX DVD backup with subtitilefile to NTSC with:
$ avi2mjpg movie.avi --split 100 -e subtitles.txt -o result%03.avi -f n

Convert 1024x240 DivX DVD backup (24fps) to PAL (cut off the sides and 
scale the width to 768 while keeping the aspect ratio)
$avi2mjpg movie.avi -g 640x240+192+0 -z 768 --split 2000 -o result%04d.avi

I hope these examples are enough to get you started, see avi2mjpg.cpp for 
all the options.


How do we change the fps:
~~~~~~~~~~~~~~~~~~~~~~~~~


If the deviation is small, a small playback speed change is sufficient.
For example 24fps->25fps or 30fps->29.98fps. This is called scaling, 's'.

In other cases we really have to change te number of frames. There are several
methods available:


-3:2 pulldown, 'p', produces 5 output frames from 4 inputframes

This is an algorithm that is used to make 5 interlaced output frames from
4 non-interlaced input frames. (if we want to go from 24fps to 29.98fps we
first perform 3:2 pulldown so that the fps is 30 and then a slight speed 
change as above). For a nice explanation see:
	http://www.digital-digest.com/nickyguides/interlace.htm


-frame repeat, 'r', produces n output frames from 1 inputframe

Just repeat each frame the same number of times (usually 2 or 3). This is
useful for 15fps->30fps or 8.3fps->25fps. This works best for noninterlaced 
input frames.


-inverse 3:2 pulldown, 'i', produces 4 output frames from 5 inputframes

If you perform inverse 3:2 pulldown on interlaced frames that were produced
by 3:2 pulldown you get your original progressive frames back. But it performs
well on non interlaced input. It's primary usage is 30fps->24fps  (and then a
speed change to pal). (see the notes in 30FPSDVD)


-double inverse 3:2 pulldown, 't', produces 8 output frames from 5 inputframes

This first doubles each frame and then performs inverse 3:2 pulldown. Useful
for 15fps->24fps (and then PAL).


-two and three, 'q', produces 5 outputframes from two input frames

Takes the first input frame and outputs it twice and the second gets output
3 times. It may be useful and bearable.


-inverse framerepeat, '--invframerepeat'

Suppose someone produced a 29.98fps stream from 24fps by repeating every
4.99666667th frame (on average). This method allows avi2mjpg to skip the 
inserted frames to recover the original 24 fps (which then can be converted
to PAL or be properly 3:2 pulled down to 30 fps. (this will be handled in the 
decoder, not in the encoder)


We still need 'the' method for PAL<->NTSC (i.e. the one which TV stations use
if they broadcast something that originally is in the wrong standard). The
artefacts of NTSC->PAL (jerky movement) are clearly visible in PAL-land.

The program selects the best method automatically based on the tolerance
setting (--tolerance 5), the maximum allowed speed change. The default is
5 percent. (the 'inverse framerepeat', however,  never gets selected 
automatically)

You can 'force' the method to be used on the on the commandline using the
'--videostrategy' switch. Possible values are listed above (after the name 
of the method).

If you want to convert interlaced NTSC to PAL with this program, your best 
bet is to throw one of the fields away (--halveYRes) and double the y 
resolution again (--doubleYRes) (the -z option in lavplay will not give 
satisfactory results).


Bugreports:
~~~~~~~~~~~

First: read BUGS, to see if I already know about the bug.

If the bug is not mentioned in BUGS...

Second: (if your bug is about a specific file) check if the file plays in
aviplay if it is an AVI and in xmovie (heroines.sourceforge.net) if it is 
an MPEG. Play it in 24bpp mode. If that also doesn't work then it is
a bug in avifile or libmpeg3. If you are sure that the file is correct,
(i.e. plays in M$ mediaplayer or some other player) the maintainers
of avifile and libmpeg3 will probably want to hear about it.

If it still is a bug of avi2mjpg then....

Third: Send a bugreport to snel@phys.uu.nl. Please include full verbose 
output with your bugreport. (-v switch) (hint: use the script(1) command)
Always check wat happens with --noaudio, it may help me finding the bug.


Patches:
~~~~~~~~

Send them to me <snel@phys.uu.nl>.


Credits:
~~~~~~~~

See CREDITS.


License:
~~~~~~~~

The GNU GPL applies. See COPYING.


