Compressing (Re-encoding) files

From Digisaster
Jump to: navigation, search

Back

With compression you can achieve up to 10 times less size and there by save a lot of disk space. The trade-off is that the quality is slightly reduced (Picture noise and compression artefacts) and that fast forwarding/rewinding doesn't work as well as with the native Mpeg2/VOB files. But if you are not fanatical with the picture quality, it's a good deal.

Using VirtualDubMod (Windows)

Please Copy from MPC's KiSS Manual page 51 – 54 and insert here.


MPC's KiSS Manual (Password is Computer2004)

Using Mencoder (Unix)

When compressing video on a Unix system Mencoder is an easy choice. Its a part of the Mplayer packed, that is also used in the KiSS players and therefore 100% compatible. Its also one of most widely used and therefore well supported.

There is a lot of consideration to take in to account when compressing a video. If you want the best possible quality of your compression, you will have to adjust it to the movie, as different movies should have different settings.

Two pass operation

There is no way around a 2 pass compression, if you want this level of compression in a reasonably quality. First pass create a log file (divx2pass.log) and throw the compressed movie output away. The logfile is then used by the 2nd pass to adjust the use of bits in the most effective way.


Recorded TV

Here I try to present the best settings, for an all-round compression of recorded TV on a KiSS player, in PAL 4:3 format. It has taken quiet a while to hit the right settings and there at still room for some improvement. It takes a H... of a long time to encode. But it saves a lot of space.


The complete commands:

Pass 1

 mencoder -oac mp3lame -lameopts cbr:q=2:br=128y -ovc lavc -mc 0 
    -lavcopts vcodec=mpeg4:vmax_b_frames=1:vb_strategy=1:trell:mbd=2:v4mv
    :last_pred=3:predia=2:dia=2:preme=2:precmp=2:cmp=3:subcmp=3:mv0:cbp:vqcomp=0.6
    :dc=10:qns=2:border_mask=0.3:lumi_mask=0.07:scplx_mask=0.1:tcplx_mask=0.1:naq
    :vbitrate=800:vpass=1:turbo 
    -vf crop=688:544:16:16,lavcdeint,hqdn3d=2:1:2,pp=autolevels:fullyrange
    -o/dev/null <input file>

Pass 2

mencoder -oac mp3lame -lameopts cbr:q=2:br=128 -ovc lavc -mc 0 -noodml
   -lavcopts vcodec=mpeg4:vmax_b_frames=1:vb_strategy=1:trell:mbd=2:v4mv
   :last_pred=3:predia=2:dia=2:preme=2:precmp=2:cmp=3:subcmp=3:mv0:cbp:vqcomp=0.6
   :dc=10:qns=2:border_mask=0.3:lumi_mask=0.07:scplx_mask=0.1:tcplx_mask=0.1:naq
   :vbitrate=800:vpass=2
   -vf crop=688:544:16:16,lavcdeint,hqdn3d=2:1:2,pp=autolevels:fullyrange -ffourcc XVID'
   -o<output file> <input file>

Video

-mc 0 Switch to basic A/V sync. Default were designed with the intention of recovering files with broken sync. However, in some cases they can cause unnecessary skipping and duplication of frames, and possibly slight A/V desync. If you experience problems encoding a movie, try removing this option.

-ffourcc XVID Force the four CC code to XVID.The KiSS player don't recognize FMP4 (Default) They are both Mpeg4 formats along with Divx.

-noodml Prevent mencoder from using the newer Open DML extention to the AVI format on files greater then 1GB. Some players including KiSS don't like that.

-ovc lavc This is not very scientific. But I have chosen the 'lavc' codec, because it seems to me to produce the best result, with out tweaking, and because a lot of people use it and praise it. I have tried with the XviD codec, but was unable to get as good a result. My aim has been to use an open/free codec, maybe you can get a better result with a proprietary codec like DivX.

Have a look at mencoders homepage for details

vcodec=mpeg4 compress to MPEG4 format (both XviD and DivX are MPEG4 format)

vmax_b_frames=1 1 is good 2 is bad on KiSS!  :o)

vb_strategy=1 helps in high-motion scenes..

trell find the optimal encoding for each 8x8 block.

mbd=2 Macroblock decision algorithm (high quality mode), encode each macro block in all modes and choose the best. This is slow but results in better quality and file size.

v4mv Allow 4 motion vectors per macroblock. (slightly better quality)

last_pred=3 Number of motion predictors to take from the previous frame. 1-3 or so help at little speed cost. Higher values are slow for no extra gain.

dia=2:predia=2:preme=2 dia: motion search range. Bigger is better and slower. Negative values are a completely different scale. Good values are -1 for a fast encode, or 2-4 for slower. predia: motion search pre-pass. Not as important as dia. Good values are 1 (default) to 4. Requires preme=2 to really be useful.

precmp=2:cmp=3:subcmp=3 Comparison function for motion estimation. 0 is fastest, and sufficient for precmp. For cmp and subcmp, 3 is good for live action. 6 may or may not be slightly better, but is slow.

mv0:cbp Controls the selection of macroblocks. Small speed cost for small quality gain.

vqcomp=0.6 Tweak ratecontrol. What values are good depends on the movie. You can safely leave this alone if you want. Reducing vqcomp puts more bits on low-complexity scenes, increasing it puts them on high-complexity scenes (default: 0.5, range: 0-1. recommended range: 0.5-0.7).

turbo This option really speed things up. Up to 5 times faster. Ofcause it comes at a price. The first pass is less precise and thereby reducing the overall quality. (More testing needed)

dc=10 intra DC precision in bits. This may help reduce the appearance of blocks in flat-colored areas.

qns=2 is very slow, especially when combined with qprd. This option will make the encoder minimize noise due to compression artifacts instead of making the encoded video strictly match the source. Do not use this unless you have already tweaked everything else as far as it will go and the results still are not good enough.

lumi_mask=0.07 Luminance masking compresses bright areas stronger so it will save bits that can be spent again on other frames, raising overall subjective quality. This is a psychosensory setting that make use of the fact that the human eye notice fewer details in very bright parts of the picture. dark_mask dose the same for dark areas, but that is not recommended to use.

border_mask=0.3 Border mask increases the quantizer for macroblocks which are less than 1/5th of the frame width/height away from the frame border, since they are often visually less important.

scplx_mask=0.1 Spatial complexity masking will raise the quantizers (decreasing quality ) of complex but stationary macroblocks. Imagine a scene with grass (which usually has great spatial complexity), a blue sky and a house; scplx_mask will raise the quantizers of the grass' macroblocks in order to spend more bits on the sky and the house.

tcplx_mask=0.1 Temporal complexity masking raise the quantizers of fast moving object macroblocks. The human eye usually don't have time to see all the details anyway. A side effect is that if the object stops moving, it will look bad for a short while.

naq Normalize adaptive quantization. When using adaptive quantization (*_mask), the average per-MB quantizer may no longer match the requested frame-level quantizer. Naq will attempt to adjust the per-MB quantizers to maintain the proper average.

vbitrate=800 This is the all important option, that determines the size of the file. If you look at some of the best pirates on bit torrents, they have surprisingly good quality with less then 800 Kbps. (one movie on one CD which is 700MB) So its important to tweak all the other options and then turn this knob.
The above setting will produce a fairly good quality with only a little pixelation and some pattern artifacts. Its perfect for movies recorded from TV. 1 hour is about 450 MB. That's a compression of almost 10 times on a 8000Kbps .vob file. You can set vbitrate as low as 400 and get a surprisingly good result. 1 hour are about 300 MB.
1200 Kbps. is very good and almost artifact free. 1500 Kbps. Is the absolute maximum setting with this setup. There is no problems with pixelation. If you don't have a very good TV signal or are encoding a DVD rip. this setting is probably a waist of space. 1 hour is about 900 MB with AC3 audio. You might get into truble with files larger then 2GB, since that is the filesize limit on avi files without the ODML extension, but I haven't tested it.


Filters

crop=688:544:16:16 Crop the edges of the movie. KiSS players record everything in the picture even parts that are not visible on the screen. Black borders or even grey lines between the picture and the border, are very bad for the motion detection and compression. It takes a lot of extra bytes. (or in this case, with fixed average bit rate; reduce quality) This setting is adequate for full screen 4:3 movies. But further cropping is preferable if its a wide screen format, shown as 4:3. See mencoder's homepage for details.

lavcdeint (or pp=fd) Deinterlacing: When recording in PAL, the KiSS player, record interlaced. That mean that evry frame are split in two, show after each other, but at double speed. The first show every odd line in the picture, the second show every even line. Together they are a complete frame/picture. That works well on a regular TV set. But if you want to watch it on a progressive screen like a computer, the real-time deinterlacing often creates artefacts during high motion scenes. Since The KiSS player don't mind, I prefer to deinterlace the movie. I have tried other recommended methods like pullup-softskip, yadif, mcdeint. All produced manny more artefacts the this one. Its actually quite good.

hqdn3d=2:1:2 is a light de-noise filter. It good to have on analog TV signals so you don't waist bandwidth on signal noise.

scale=720:576 Resize the movie to 4:3 even though the cropping made it slightly different. It can be usefull, if the player don't show the movie the right way. In principal scaling should be done by the playing device. It makes the file bigger with no quality gain and the KiSS usually works fine without it.


Audio settings -oac mp3lame instruct the use of the lame MP3 codec. Options are set with -lameopts.

I would normally go with the original A3C format, if I had a better source then TV. Here its not worth the extra 5-10% in file size. So I use MP3 lame codec. Don't know if its the best, but a lot of people talk about it :o)

cbr Constant Bit Rate is apparently very important on the KiSS. Its a shame we cant use ABR (Average Bit Rate). I haven't tested it though... Please do that if you can, and report back here.

br=128 Bit Rate Bitrate has the main influence on sound quality. 128 Kbps seems reasonable to me, It might also be default?

q=2 quality setting. Choose the algorithms to determine the best scalefactors and huffman encoding (noise shaping). 0 is highest quality and 9 are the fastest. Default 5. values of 0 and 1 are slow and may not produce significantly higher quality. So Lame recomments 2 for good quality.

vol=7 Volume can be boosted here if needed. Values 0-10. Some TV stations lower the volume of the movie in order to make an audible impact on the view during commercial break. (Its rather stupid, since you are forced to take action, if you are watching) You might compensate here, if necessary.

-oac copy Gives you the unchanged AC3 surround sound. It will cost a few hundred MB extra on an movie. If you use a high bitrate you should use this as well to geet a better sound quality. (Se File formats under Audio settings)


With these settings, you are able to make compressions that are better then much of the shared material circulating on the net, but not yes as good as the very best. Please share your goodies on compression here.


--Simon Rigét 15:01, 2 December 2007 (CET)

Things to avoid

Maximum of one b-frame (B-VOP)

Symptom: Choppy movie; stops for a few tenths of a second now and then. Mostly in action scenes. Very annoying.


Quarter pixel motion detector (QPEL)

Symptoms: On DP558 the players reply 'Codec not supported'


GMC Global motion compensation

(Don't know the symptom)


Variable bit rate. (VBR) on MP3

Symptom: Supposedly some problem with picture/sound synchronisation. (I Haven't tested it)

The MP3 audio must have constant bit rate (CBR)


OpenDML avi format

Symptoms: 1 can't FF 2. Can't search. 3. Stops after 1Gb