Compression

Current status

  • mencoder can compress fraps files to xvid
  • xvid and ogg are now working for encoding with transcode, and playback in mplayer
  • Windows:
    • xvid plays back in Windows Media Player through the divx5 codec, afaict (it works).  
      • ogg needs a plugin -- I got it here, called winogg.zip (comes with a 7.1 upgrade to WMP 7 -- see instructions in software directory on spello
       
    • the same site has oggwinamp.zip for WinAmp -- the file in_vorbis.dll, copy to plugin directory
     

Guides

Commands

  • ffplay -stats video.avi > /tmp/outfile 2>&1
  • tcprobe -i filename
  • ffmpeg -formats
  • x264 -v --frames 250 --fps 30 -i 9999 -b 0 -r 5 -q 0 -A all --subme 5 -o test.264 /video-352x288.yuv 352x288
    • x264 -o output.mp4 intermediate.y4m 320x240
       
  • mencoder e* -ffourcc DIVX -ovc lavc -oac mp3lame -lameopts cbr:br=128 -o test.avi
  • mac "01 - Song.ape" "01 - Song.wav" -d (tested to work)
    • monkey's audio codec (lossless) in package mac, built for amd64 on trevi in June 2006)

Software

  • Transcode
  • kmenc15 -- mencoder frontend
  • Divx for Linux (5.0.5 as of late May 2003)
  • MPEG4IP -- details below (the Cisco project)
  • Sampeg -- a family of MPEG encoder programs targeting picture quality
  • cfourcc -- command line tool for changing FourCC in Microsoft RIFF AVI files
  • avi2divx and mpeg2divx -- needs
  • distmp3 -- cluster conversion to mp3 (just reconfigure distmp3)
  • divx4linux at Project Mayo and the win32 binaries
  • FFmpeg -- realtime FFmpeg encoder/decoder (lots of codecs) and FFserver for streaming
    • if ffplay can play a file, you can convert it to dv using "ffmpeg -i your.avi -vcodec copy new.dv"
  • H.264 -- see the VideoLan encoder project still in CVS, but also used by mplayer; cf. mailing list
  • lame (mp3 encoder)
  • mencoder mencoder can compress (and mplayer can play) movies recorded with fraps 3.5
    • mencoder manual -- likely to be updated
    • don't upgrade to the latest Fraps, as mplayer likely doesn't support it yet
    • see their news page for updates)
  • mjpeg tools -- contains Andrew Stevens' mpeg2enc
  • mpegdemux -- separate audio and video
  • MPEG4IP's mp4creator will take an xvid file and turn it into H.264 -- see commands and instructions
    • apt-get -t experimental install libpango1.0-0 (also installs libpango1.0-common)
    • apt-get install mpeg4ip-player mpeg4ip-server (also installs mpeg4ip-libs) (see repository)
    • installed on sigillo 28 Oct 2004
    • installed on clitunno 8 May 2006 (mpeg4ip-utils)
  • Encoding frontends
  • notlame (mp3 encoder)
  • NuppelVideo
  • oggenc -m 80 -M 160 test.wav -o test.ogg (bitrate between 80 and 180 kbps)
    • clitunno does oggenc -- quality seems fine!
    • oggzmerge -o merged.ogg track*ogg (failed -- generates corrupt files)
    • oggzinfo
  • Quicktime on Linux -- see Linux Journal April 2002
    • libquicktime_config -- see available codecs and configure libquicktime
  • RealProducer -- http://www.realnetworks.com/products/producer/features.html (review)
  • ucbmpeg -- MPEG video encoder and analysis tools
    • ucbmpeg-play -- the player
  • VR3 -- LGPL'd video codecs, including a QuickTime plugin (works great)
  • wma2wav -- convert a wma file to a wav file
    • Use alien to build the package
    • Works on sigillo and spello (Nov 2004)
  • x264

Capturing from tv to quicktime using gstreamer

Ronald S. Bultje <rbultje@ro...>, one of the authors of ffenc-mpeg4 in gstreamer, wrote on 2006-11-08,

You need to set the global header flag in the AVCodecContext of ffenc_mpeg4 for Quicktime to play it back. Without it, ffmpeg doesn't write the esds atom, which makes the MPEG-4 stream embeddable in .avi, for example (e.g. divx). However, Quicktime doesn't eat MPEG-4 without global headers (esds atoms).
 
You can autodetect this by seeing whether the caps of the output video (in ffenc_mpeg4) is video/x-divx or video/mpeg,mpegversion=4. With that flag set, Quicktime will be able to play back the resulting stream also (I confirmed this with the 0.8 version, it shouldn't differ nowadays in 0.10). Source

This sort of works, but video is blocky and sound absent:

gst-launch-0.10 avimux name=mux ! filesink location=$DIR/$FIL.avi
v4l2src device=/dev/video$DEV ! \
video/x-raw-yuv,width=640,height=480,framerate=\(fraction\)30000/1001 ! \
ffmpegcolorspace ! ffenc_mpeg4 ! queue ! mux. alsasrc device=hw:$DEV,0 ! \
audio/x-raw-int,channels=2,rate=32000,depth=16 ! audioconvert ! lame ! mux.


Cropping and resizing in mencoder and transcode

  1. Run mplayer with the "-vop cropdetect" option and it spits out a list of crop parameters on the console. These crop parameters are for mencoder so you'll have to convert them for use with transcode.

    Like, for my Spirited Away DVD, it outputs "crop=672:436:24:20". You can then plug these parameters back into mplayer with the "-vop rectangle=<crop params>" option, it'll draw a rectangle in the video at the crop boundaries.
     
  2. If you're using transcode to crop you want to use the -j option for cropping before the filterchain (-Y crops after the resize which is bad). If the mplayer crop parameters are "crop=a:b:c:d" and the pre-crop width and height are w and h, the corresponding transcode parameters are "-j d,c,h-b,w-a". I think that's right. Oh yes, round each of the four transcode parameters up to a multiple of 16.
     
  3. Then resizing. If you're downscaling use the -B option. To resize in multiples of 16 use "-B n,m,16". n is how many blocks of 16 pixels to reduce the height by, and m is how many to reduce width by. Say if my movie was 2.35:1 and anamorphic, I'd probably end up cropping to 720x352 and resizing to 720x304. 352-304=48 so I'd use "-B 3,0,16".

h264 to quicktime

Daniel Rogers <daniel@phasevelocity.org> writes on 8 April 2006 to the x264-devel mailing list,
I encode from dvd (or dvd dump) to H.264 using mencoder specifically:

mencoder cb_d3_6.mpg -ovc x264 -x264encopts bitrate=700:psnr:pass=2:subq=6:me=3:\
frameref=5:bframes=0:nocabac:vbv_maxrate=768:vbv_bufsize=2000:level_idc=13
-vf pullup,softskip,scale=320:-2 -ofps 24000/1001 -o test.m4v -of rawvideo -nosound

But I've also used:
x264encopts bitrate=700:psnr:pass=2:subq=6:me=3:frameref=5:bframes=0:nocabac:level_idc=13
and with avi output.

I remux with ffmepg using:

ffmpeg -i test.m4v -vcodec copy -f mp4 test.m4v

I've also used MP4Box to re-remux the stream hoping to produce better results.(in order for this to work, you need to set -ffourcc 'avc1', write to avi, remux with ffmepg above and then remux again with MP4Box).It didn't.

No matter what, the results of MP4Box -info test.m4v 1 isa H.264 bitstream that reports as 0 bitrate, 0 max bit rate and 0 decoder buffer size.

I've also tried encoding the aac audio at the same time or seperately.I've also tried using -of lavf -lavfopts format=mp4.The audio encodes are also all messed up.(They report a bitrate of 4 or 5 kbps with MP4Box, even though I set it to 128).

These files all crash quicktime.

If I encode with ffmpeg, the files play fine in quicktime, and mp4box reports the expected values for bitrate, max bitrate and decoder buffer size. However ffmpeg won't do all the nice filtering that mencoder does, so I end up doing two encodes, which takes sooo much longer.

 
mpeg4 to h264 using mencoder

The footage that chianti captures can be converted to h264. How long does it take, and what's the resulting quality? These tests show mencoder will do the conversion in a two-pass process that is quite slow -- around three times the program.

Incidentally, on clitunno I'm getting "using cpu capabilities MMX MMXEXT SSE SSE2 3DNow!"

Lorenmer writes (October 2005):

The basic command containing all the important options:

mencoder in.ts -o /dev/null -oac copy -ovc x264 -x264encopts \
 pass=1:bitrate=$N:bframes=3:subq=2
mencoder in.ts -o out.avi -oac copy -ovc x264 -x264encopts \
 pass=2:bitrate=$N:bframes=3:subq=6:frameref=4:8x8dct

On a dual cpu, optionally add 'threads=2', though running 2 independent encodes in parallel is more efficient.

I tried this for the first pass with an odd-sized Bladerunner clip:
mencoder B*avi -o /dev/null -oac copy -ovc x264 -vf scale=656:288  -x264encopts pass=1:bitrate=715:bframes=3:subq=2:threads=2

I chose the bitrate to be equal to the original. That encodes a captured tv file around 28 fps. For the second pass:

mencoder B*avi -o out.avi -oac copy-oac mp3lame
-lameopts cbr:br=64 -ovc x264 -vf scale=656:288 -x264encopts
pass=2:bitrate=800:bframes=3:subq=6:threads=2:frameref=4:8x8dct
This encodes around 18 fps.The resulting file is the exact same size as the original; audio and video quality are both good.

If I take the bitrate down to 400, the encoding rate stays about the same.The size halves and the quality is impressive -- no noticeable degredation from the original. On Chianti, the first pass goes through around 28fps and the second around 17.

Taking it down to 200, the first pass on trevi is 37 and the second 20.The quality is amazingly good -- basically still usable, although there's some degredation in motion scenes. There's lots of room here for compressing files if that's what you want.

You can also lower the audio bitrate with -oac mp3lame.
The codec requires roughly six times the CPU power of divx. The experiments are successful and I now know more about how CPU intensive the codec is.

mpeg4 to h264 using ffmpeg

Marillat points out ffmpeg can also encode to H.264:
$ ffmpeg -formats | grep 264
DE h264 raw H264 video format
DEV DT h264

This works -- and single-pass seems to produce good quality:

ffmpeg -i B*avi -f avi -vcodec h264 -b 400 -s 656x288 -acodec mp3 ffmpeg-400.avi

Incidentally, ffmpeg shows the tv files to have a bitrate of 938 kb/s, not 800 as mencoder says. In this single-pass mode, ffmpeg won't actually achieve the targeted bitrate of 400, at least not with this command. You could ask on the ffmpeg list for help.

ffmpeg encoding doesn't show encoding speed, so use a timer. I wrote a script with a timer, /ssa/TV/scripts/testing/clips/ffmpeg-timed, so that you can run tests automatically.

Using ffmpeg to capture tv -- this works, but drops frames:

ffmpeg -vd /dev/video2 -f avi -vcodec h264 -r 29.97 -b 800 -s 640x480 \
-ad /dev/dsp2 -acodec mp3 -ab 64 -t 10 video.avi
You could try this in a tv script -- you can also try with a different codec, see
ffmpeg -formats | grep EV
For instance, try capturing to fourcc: FFV1.Should the audio codec be mp3lame? See TV-capture for tests (not successful).

dv to xvid and divx5

 On 21 August 2003, Christian Marillat packaged libxvidcore2 0.9.2, which the xvid project had released in early August, and a transcode revision that utilized it. The xvid export codec itself is dated 2003-07-30. With this package, I got the following results:

Codec
File size
Compression
dv
900000000
1:1
divx5
67580486
1:13.32
xvid
66582186
1:13.52

Note that this ratio is a result of the command to keep a bitrate of 2000 -- it may well be that you would conserve the same quality with a lower bitrate (the default is 1800). The encoding speed dropped noticeably between xvid 0.9.1 and 0.9.2 -- from 5.3 fps to 3.3 fps on the 1.2GB CPUs; the 2.0GB CPU is about twice as fast -- that is with several of the most CPU-intensive options enabled (de-interlacing and anti-aliasing are both set to max at 3):
-I 3 -C 3 -V -w 2000 -N 0x55 -b 128
See /usr/local/bin/dv2xvid for details. Essentially I'm using the settings to produce an mpeg4 movie that is of the highest possible quality. So are there quality differences between divx5 and xvid?

On 3 June 2002 I discovered a lot of mjpeg tools, including mpeg2 encoding stuff, but really you should back off. The dv stuff is useful for you, but the TV stuff is marginal and will require too much work.

On 30 May 2002 I compressed a series of *.avi files acquired from the camcorder with dvgrab's --format dv2. About 40 minutes worth of video compressed from 8GB to 600MB in about 400 minutes, using the new divx5 codec. The compression rate is about 15:1 and the time 10:1. The results are brilliant and include impeccable mp3 sound compression. Note that this was done with a CPU running at 800MHz and encoding at 2.2 frames per second, on gubbio. The frame rate on cyberspace is 3.6 frames per second, running at 1.2GHz.

I attempted to get rid of an empty file that divx5 keeps creating. Someone else reported they had to change it to make divx work: "I loaded libdivxencore.so in a text editor, found "c:\trace_b.txt" string and overwrote it with something like /tmp/stupidivx. After that divx5 worked fine, before it was segfaulting."

On 12 December 2001 I compressed 650K video files created by dvgrab   with wm8eutil, the Windows Media 8 compression utility. It too a file of 650K down to 3.4K in 7.5 hours -- an incredible compression, and the quality was excellent. The sound didn't carry through -- see the links page for additional info.

Encoding PSP compatible MP4 files on Linux
http://yogarine.net/

It took me a while to figure out (read: have time to investigate) how to convert any movie into a format that works on the PSP. First of all, if you're using Ubuntu, you need to recompile ffmpeg with FAAC and FAAD support. You can find a great guide for this here: http://po-ru.com/diary/fixing-ffmpeg-on-ubuntu/

After that, it basicly comes down to this:

    * The format must be 'PSP'
    * Width and height must be a multiple of 16
    * Width*height can't be more than 76800.
    * The video codec must be mpeg4
    * The audio codec must be aac
    * Framerate must be 30000/1001 (29,97 fps) or 15000/1001 (14,985 fps)
    * The audio rate must be 24kHz

This means that the optimal size for 16:9 is 368x208. For 4:3 it is 320x240. You could also try 480x160 wich would give a perfect horizontal resolution at the cost of a blurred vertical resolution... Or 272x272 which would give a lower horizontal resolution in favor of a perfect vertical resolution. Handy if a video has a lot of vertical or a lot of horizontal lines... Also, most motion happens along the horizontal axis... So horizontal blurring wont be noticable in most cases. Anyway, using 320x240 will be the best option in most cases. Just make sure you set the -aspect properly (on PSP it should always be 16:9).

Here's an example ffmpeg command:
ffmpeg -i <inputfile> -title "<title>" -acodec aac -ab 96k -ar 24000 -vcodec mpeg4 -b 672k -mbd 2 -aic 2 -cmp 2 -subcmp 2 -flags +4mv+trell -s 320x240 -aspect 16:9 -r 30000/1001 -f psp M4V00001.MP4

The meaning of the options:
-i <inputfile>
-title <title>
-acodec <audio codec>
-ab <audio bitrate in bits per second>
-ar <audio rate>
-vcodec <video codec>
-b <video bitrate in bits per second>
-s <size>
-aspect <aspect>
-r <video fps>
-f <format>

If you're having troubles converting WMV, you might first need to convert it to raw AVI and PCM, using mencoder. Use the following command. If you notice any audio delays after converting, modify the -delay option until the sound is right. If you have any audio delay, most of the time it will be around -0.25.

mencoder -oac pcm -ovc raw -of avi -ofps 30000/1001 -delay 0 <inputfile.wmv> -o <outputfile.avi>

MPEG2

Mpeg2 may play better on older computers, but on the whole it appears to be a slightly inferior encoder. It may have some limited or specialized use, but for my own use and for archiving, mpeg4   should be fine. Just make sure you keep the original uncompressed sources, preferably on DV tapes.

I finally inferred that mpeg-2 encoding is most likely done with components of mjpegtools, which I never installed. I find them at http://mjpeg.sourceforge.net/

dv2jpg converts a DV codec-encoded AVI stream (from dvgrab, for   example) to an mjpeg-encoded AVI stream that can be processed by the mjpeg tools package. The mjpeg AVI can be converted to mpeg video/audio and burned onto a VCD later. Homepage: http://sourceforge.net/projects/dv2jpg/

The MJPEG-Howto, written by Bernhard Praschinger contains a brief   introduction to all the MJPEG-tools. If you don't know where to   start, please start by reading this document, it gives an overview of about everything the tools can do. https://sourceforge.net/docman/display_doc.php?docid=3456&group_id=5776

As of late June 2002, Kino can encode in mpeg2, and gmplayer will   play it, using the libmpeg2 video decoder and the mpeg12 codec. It looks fine!

1770700 Jun 22 divx5-r3.avi transcode with -R3
 4261688 Jun 22 divx5.avi transcode regular
 6289408 Jun 22 mpeg2.mpeg kino with regular mpeg2
 6811648 Jun 22 DVD.mpeg kino with DVD
 65516324 Jun 22 dv.avi kino with dv2 

The kino encodings use various components of mjpegtools; so could   transcode. Encoding mpeg2 seemed significantly faster than divx5.

It may be that you should be using kino's raw for transcoding purposes.

If you select option 8 - DVD, you don't get rescaling, and less   artifacts. This compresses slightly less than 10:1 and looks good. I'll compare it to divx5 -- it looks about the same to me; no striking differences.

Filters

"Currently it is not possible to use all of the Transcode filters on interlaced video material. Therefore, I am forced to use MPlayer for many filtering jobs. All of the filters of MPlayer work with interlaced material, because of the availability of a field separation filter. This filter can put two fields in one image, one in the top half of the frame, the other in the bottom half. Any filter that does not support interlaced video can be used by pre- and postprocessing the video with this field separator, like this:

mplayer .... -vf il=d:d,insert,any,filters,you,want,il=i:i

It would be great if Transcode could do the same." Dik Takken <D.H.J.Takken@phys.uu.nl>

MPEG4IP

See this MPEG4 project -- http://mpeg4ip.sourceforge.net/index.php

Specifically, see this presentation -- really useful for DiMMRA: http://www.mpeg4ip.net/documentation/mpeg4ip_svlug.pdf

Guide: http://www.everwicked.com/content/MPEG4IP_Guide/

Software: http://mpeg4ip.sourceforge.net/downloads/index.php

Killer app of the month, Mpeg4 IP. MPEG4IP provides an end-to-end   system to explore MPEG-4 multimedia. MPEG4IP is developed by Cisco. It provides an MPEG-4 AAC audio encoder, an MP3 encoder, two MPEG-4 video encoders, an MP4 file creator and hinter, an IETF standards-based streaming server, and an MPEG-4 player that can both stream and playback from local file.

OGG

transcode -i F*2.dv -I 3 -C 2 -z -k -w 2000 -y xvid,ogg -m 1.ogg -o
 xvidoggtest.avi

[export_ogg.so] Hint: Now merge the files with
 [export_ogg.so] Hint: ogmmerge -o complete.ogg xvidoggtest.avi 1.ogg

OGMtools http://www.bunkus.org/videotools/ogmtools/

These tools allow information about (ogminfo) or extraction from
 (ogmdemux) or creation of (ogmmerge) OGG media streams. Note that I'll use
 OGM for "OGG media streams".

Download: http://www.bunkus.org/videotools/ogmtools/ogmtools-0.951.tar.bz2

/usr/bin/install -c ogmmerge /usr/local/bin/ogmmerge
 /usr/bin/install -c ogmdemux /usr/local/bin/ogmdemux
 /usr/bin/install -c ogminfo /usr/local/bin/ogminfo
 /usr/bin/install -c ogmsplit /usr/local/bin/ogmsplit
 /usr/bin/install -c dvdxchap /usr/local/bin/dvdxchap

ogmmerge -o complete.ogg xvidoggtest.avi 1.ogg
 Using AVI demultiplexer for xvidoggtest.avi.
 +-> Using video output module for video stream.
 Using OGG/OGM demultiplexer for 1.ogg.
 OGG/OGM demultiplexer (1.ogg): using Vorbis audio output module for stream 1.
 progress: 182/182 frames (100%)

rm/ram RealPlayer files 

For a sample, see the excerpt from Newton Minow's 1961 address at American Rhetoric.

Capturing an rtsp:// file and converting it to mp3 or ogg:

  • mplayer -dumpstream rtsp://<address>
  • mv stream.dump streamdump.rm
  • trplayer streamdump.rm (test that the stream plays)
  • Convert the realmedia audio file to wav:
    • vsound trplayer streamdump.rm OR
    • vsound -a 4 -f output.wav realplayer Minow-1961.rm
  • Do this in chroot on i686 -- doesn't work in amd64
    • trplayer exists for i686, cf. /vc/software/debs
      • needs an ancient libstdc++2.10 (try to recompile?)

    • Realplayer not yet available on amd64
  • Press stop in Realplayer when done -- it will terminate on its own
  • This produces an .au file but converts to .wav
  • Convert the wav file to mp3 (do this in amd64):
    • lame -h vsound.wav streamdump.mp3
  • Convert all the way to ogg (goes via au and wav):
  • vsound -t -s trplayer -q -n streamdump.rm | sox -t au - -t wav - | \
    • oggenc -q 0 -o streamdump.ogg -

Note that the converted files may be much larger and/or lose quality.
You can use trplayer (not in Debian --or kaffeine to play the original captured file.

XVID

Transcode 6.1:

export_xvid:
latest snapshot version
head cvs branch version
export_xvidcvs:
dev-api-3 cvs branch version

export_xvid, export_xvidraw :
XviD stable releases (the first release will be 0.9.0,
and all 0.9.x versions will stay
compatible with transcode-0.6.1)

export_xvidcvs :
XviD dev-xxx-xxx branches (compatibility issues will be common, as both
transcode and xvid-dev
will not always be in sync
in terms of API, features
etc etc) 

According to transcode's printout, I'm using XviD stable. I still don't know if I'm using what I installed separately from XviD's CVS or if these codecs are simply included in transcode.

 

 
 

 

 
top
 
 Debate
 Evolution
 CogSci

Maintained by Francis F. Steen, Communication Studies, University of California Los Angeles

 


 

CogWeb