bing tech leftist search bofh home prawda security links etext music chemistry feminist guatemala home kaestner news study emu my stuff a/v cooking

Avifile Glue for mpeg2_encode by Adam Williams

Note: you are probably looking for news or recent patches/tarballs. The former are to found at the top, right below the toc, the latter at the bottom of this document. Much of the stuff in between has to be considered outdated garbage :-)

Table of Contents

  1. Table of Contents
  2. About
  3. News
  4. To Do
  5. Improvements
  6. References
  7. notes
  8. Precompiled Binaries antiquated
  9. Known Issues
  10. Documentation
  11. Changelog

About avi2mpegpatch/exportvideo

Coded by Roman Hochleitner (roman at mars tuwien ac at) and Alexander Oelzant-Faderler (alexander at oelzant priv at) with help from Josef Schmid and thanks to Sid (Andreas Varga) for the frames counter and extensive testing against all types of input sources (including .vobs).

This started as a simple patch against Adam Williams' heroinewarrior mpeg2_movie to utilize libavifile by Eugene Smith, however the project got out of hand and currently supports Romans Nuppelvideo file format for input and the MJPEGtools mpeg2enc YUV4MPEG format for output.

Originally this project's intent was not to become a new package, but only to provide the previously missing direct avi->mpeg conversion for the GNU/unix/linux community until the core feature (linking against libaviplay) was integrated into the main encoder, but this goal has been abandoned. We currently hope to enable as many encoders as possible with the avi/nuv/qt-reading functionality.


  1. since the new toolame-versions (02h or 02i up) don't have the segfaulting bug anymore, there's no need to use psy model 1 anymore
  2. Nuppelvideo 0.5 supported from .7e-pre3 up
  3. preliminary letterbox-README
  4. It seems avi2mpegpatch works fine with libaviplay 0.6 after applying this small patch to aviplugin.C (integrated as a compile time option from 7e-pre1 up), Erik I. Bolsø reports success (small naming/case issues)
  5. X11/Xvlib.h and X11/Xv.h can be downloaded since they are the only files needed from the XFree86 4.0 install ... hopefully obsolete soon
  6. gzipped the .7. patches which were unzipped but had .gz suffixes
  7. READMEs now available
  8. We discussed the matter of testfiles. DivX trailers can probably be found all around the net, so we provide a test Nuppelvideo file (SAT1 interactive game show).
  9. It seems we finally found the origin of the source we used: Andrew Stevens' encoder that comes with the MJPEGtools is the basis for the current mpeg encoder of the Heroinewarrior project and thus also of the avi/nuv-patched version. There now is a YUVwriter (made out of spare parts from mpeg2_movie) that produces (or at least is supposed to produce, it just got ready) YUV-output suitable for mpeg2enc from the MJPEGtools. exportvideo is a stripped-down version of the mpeg2_movie tree that contains just the files necessary for the exportvideo tool.
  10. Dynamic Loading through the glib/gmodule architecture is now experimentally supported, conditional compilation of the nuv/avi parts is configurable, too. Don't worry, the pre-linked version is still the default and works as expected.

  11. New: versatile audio extractor for all audio types
  12. old (more recent patches see above):
    roman made a complete 1.5-version with nuppelvideo for synced recording without framedrops on a <300Mhz K6 (384x288), so everything current is to be found there

    Coming Attractions: scaling/cutting (new, even more recent patch with letterbox generating code against the nuppelvideo enabled encoder from roman) works

To Do


In addition to the original mpeg2_encode features, the following have been added:

 -D       force deinterlace on (1), off (0), auto (-1, default)
 -S frame#                                      set start frame
 -N frames                       set number of frames to encode
 -G XoutxYout                    scale to this output geometry 
 -g WIDTHxHEIGHT+XOFFxYOFF         scale from this input window
                        (negative numbers produce black borders
                                  - try to use multiples of 16)
 -Y 0|1|2    YUV4MPEG format version: 0 (old, default), 1 (new)
 -a aspectratio                             used with -Y 1 only
 -T timestamptype         set timestamptype (1=time,2=framenum)

A severe bug in the B-frame creation has been worked around which inserted empty frames into mpeg input streams.



Producing an MPEG 1 or 2 compatible video stream from an asf or avi is easily possible with this patch, however for successful production of a video clip an audio stream and multiplexing will be necessary. libavifile comes with a sample program called extractor which reads 500000 bytes of mp3 from a divx, this patch reads all of it into log2.mp3. Now there is also a real audio decompressor, try the new version here! (binary compiled against 0.53)

caveat: version 2 automatically scales to 44100 Hz stereo 16 bps; upsampling of < 8000 Hz Material doesn't sound particularly good (I ought to get a better grip of the resampling code from sox I adapted for this). At least the annoying problem with 48000 kHz movies most players cannot play should be from the past, the downside is that this version is quite slow due to the algorithm used.


avifile_audiodecoder infile.avi outfile.raw


avifile_audiodecoder infile.avi "|toolame -b 224 -m s - outfile.mp2"

Unfortunately the plethora of debug output from libavifile makes it impossible to use stdout directly.

As for the system stream, to our great astonishment the mplexed system streams grew considerably when we padded them for vcd use. The culprit was the mplex-hi program (-lo didn't sync or even play on most players), which used 2048 instead of 2324 for the sector size. After this minor adjustment vcdpad was content only to pad the very last sector and leave the movie unharmed otherwise.

To remain at least partly compliant with VCD standards (and to play the hires-movies on our humble 166MMX pentia) we decided we had to have B-frames, so we obtained optimum results using settings of -1 -m 2 -q 30 for hires movies and -1 -m 2 -q 10 for lo-res cif tv-series. VBR averaged to about 900 kbps using these settings, which enabled us to produce (overburned) VCDs of movies up to 96 minutes.

According to roman the .ax codecs (responsible for output quality/ postprocessing) should be disabled (move away from /usr/lib/win32). Of course this might influence reencoding quality, so YMMV.

Precompiled Binaries antiquated

writes raw audio in whatever samplerate and channel settings the .dll produces, to be fed to toolame or similar
extracts the undecoded audio stream to a file named "log2.mp3" as is, mostly useful for mp3 divxes (source patch against libavifile/samples/extractor/extractor.cpp)

Known Issues



Version 1

Version 2

Version avi-nuv-scal-dyn (#4)

Version 5

Version 6 Wed Apr 4 22:38:01 CEST 2001

Version 7 Thu Apr 5 04:31:30 CEST 2001

Version 7b Tue Apr 24 01:55:13 CEST 2001

Version 7c Thu Apr 26 00:08:26 CEST 2001

Version 7e-pre1 Wed May 9 03:03:32 CEST 2001

This is just an interim version (and the attempt to get away from overwriting files again ... it's an addiction ;))

Version 7e-pre2 Tue May 15 14:11:02 CEST 2001

Version 7e-pre3 Fri Jun 22 04:00:50 CEST 2001

Version 7e-pre4 Don Jul 5 21:35:04 CEST 2001

Version 7e-pre5 Tue Aug 28 20:35:30 CEST 2001

Version 7e-pre6 Thu Oct 4 06:21:17 CEST 2001

Version 7e-pre7 Thu Oct 4 17:15:37 CEST 2001

Version 7e-pre8 Tue Oct 9 16:29:16 CEST 2001

Version 7e-pre9 Fri Oct 26 03:35:27 CEST 2001

modified: Saturday, 30-Sep-2017 00:13:34 CEST, retrieved: Thursday, 01-Jun-2023 06:32:35 CEST HTML 4.0? .. @ !

frames-free pages optimized for use with ©lynx but compatible with any conformant browser