View Full Version : XviD with VAQ on Linux?
kinematic
2nd October 2008, 22:04
Does anybody know of a way to compile XviD with the VAQ patch on Linux? Currently there only seems to be an .exe installer available for it.
Sharktooth
3rd October 2008, 00:37
dark_shikari should have the sources
kinematic
5th October 2008, 21:22
I pm'd dark_shikari 3 days ago but no reply. Maybe he doesn't want the VAQ patch to run on Linux?
Can anybody help me obtain the XviD with VAQ patch source code so I can try try to compile it.
Dark Shikari
5th October 2008, 21:29
I'm sorry, I'm lazy.
You can find VAQ patched Xvid code in the build threads, I think.
(I'm also not entirely sure I have the latest version of the patch... I'd have to look around for it, too, as I'm not sure where I put it.)
kinematic
5th October 2008, 21:37
I had a feeling that reply would draw you out :p
I'll go through the build thread but I'd appreciate the latest version of the VAQ patched code if it's not too much trouble :) (and if you still have it)
Dark Shikari
5th October 2008, 21:41
I can't find the diff, but I have plugin_lumimasking.c. I have no idea if this works.
/*****************************************************************************
*
* XVID MPEG-4 VIDEO CODEC
* - XviD plugin: performs a lumimasking algorithm on encoded frame -
*
* Copyright(C) 2002-2003 Peter Ross <pross@xvid.org>
* 2002 Christoph Lampert <gruel@web.de>
*
* This program is free software ; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id: plugin_lumimasking.c,v 1.6 2006/05/06 04:37:15 syskin Exp $
*
****************************************************************************/
#include <stdlib.h>
#include <math.h>
#include "../xvid.h"
#include "../global.h"
#include "../portab.h"
#include "../utils/emms.h"
/*****************************************************************************
* Private data type
****************************************************************************/
typedef struct
{
float *quant;
float *val;
} lumi_data_t;
/*****************************************************************************
* Sub plugin functions
****************************************************************************/
static int lumi_plg_info(xvid_plg_info_t *info);
static int lumi_plg_create(xvid_plg_create_t *create, lumi_data_t **handle);
static int lumi_plg_destroy(lumi_data_t *handle, xvid_plg_destroy_t * destroy);
static int lumi_plg_frame(lumi_data_t *handle, xvid_plg_data_t *data);
static int lumi_plg_after(lumi_data_t *handle, xvid_plg_data_t *data);
/*****************************************************************************
* The plugin entry function
****************************************************************************/
int
xvid_plugin_lumimasking(void * handle, int opt, void * param1, void * param2)
{
switch(opt) {
case XVID_PLG_INFO:
return(lumi_plg_info((xvid_plg_info_t*)param1));
case XVID_PLG_CREATE:
return(lumi_plg_create((xvid_plg_create_t *)param1, (lumi_data_t **)param2));
case XVID_PLG_DESTROY:
return(lumi_plg_destroy((lumi_data_t *)handle, (xvid_plg_destroy_t*)param1));
case XVID_PLG_BEFORE :
return 0;
case XVID_PLG_FRAME :
return(lumi_plg_frame((lumi_data_t *)handle, (xvid_plg_data_t *)param1));
case XVID_PLG_AFTER :
return(lumi_plg_after((lumi_data_t *)handle, (xvid_plg_data_t *)param1));
}
return(XVID_ERR_FAIL);
}
/*----------------------------------------------------------------------------
* Info plugin function
*--------------------------------------------------------------------------*/
static int
lumi_plg_info(xvid_plg_info_t *info)
{
/* We just require a diff quant array access */
info->flags = XVID_REQDQUANTS;
return(0);
}
/*----------------------------------------------------------------------------
* Create plugin function
*
* Allocates the private plugin data arrays
*--------------------------------------------------------------------------*/
static int
lumi_plg_create(xvid_plg_create_t *create, lumi_data_t **handle)
{
lumi_data_t *lumi;
if ((lumi = (lumi_data_t*)malloc(sizeof(lumi_data_t))) == NULL)
return(XVID_ERR_MEMORY);
lumi->quant = (float*)malloc(create->mb_width*create->mb_height*sizeof(float));
if (lumi->quant == NULL) {
free(lumi);
return(XVID_ERR_MEMORY);
}
lumi->val = (float*)malloc(create->mb_width*create->mb_height*sizeof(float));
if (lumi->val == NULL) {
free(lumi->quant);
free(lumi);
return(XVID_ERR_MEMORY);
}
/* Bind the data structure to the handle */
*handle = lumi;
return(0);
}
/*----------------------------------------------------------------------------
* Destroy plugin function
*
* Free the private plugin data arrays
*--------------------------------------------------------------------------*/
static int
lumi_plg_destroy(lumi_data_t *handle, xvid_plg_destroy_t *destroy)
{
if (handle) {
if (handle->quant) {
free(handle->quant);
handle->quant = NULL;
}
if (handle->val) {
free(handle->val);
handle->val = NULL;
}
free(handle);
}
return(0);
}
/*----------------------------------------------------------------------------
* Before plugin function
*
* Here is all the magic about lumimasking.
*--------------------------------------------------------------------------*/
/* Helper function defined later */
static int normalize_quantizer_field(float *in,
int *out,
int num,
int min_quant,
int max_quant);
static int lumi_plg_frame(lumi_data_t *handle, xvid_plg_data_t *data)
{
//Don't apply variance-masking to B-frames.
if (data->type == XVID_TYPE_BVOP) return 0;
int i, j;
/* Arbitrary centerpoint for variance-based AQ. Roughly the same as used in x264. */
float center = 14000;
/* Arbitrary strength for variance-based AQ. */
float strength = 0.2;
/* Do this for all macroblocks individually */
for (j = 0; j < data->mb_height; j++)
{
for (i = 0; i < data->mb_width; i++)
{
int k, l;
unsigned int sum = 0;
unsigned int sum_of_squares = 0;
unsigned char *ptr;
/* Initialize the current quant value to the frame quant */
handle->quant[j*data->mb_width + i] = (float)data->quant;
/* Next steps compute the luminance-masking */
/* Get the MB address */
ptr = data->current.plane[0];
ptr += 16*j*data->current.stride[0] + 16*i;
/* Accumulate sum and sum of squares over the MB */
for (k = 0; k < 16; k++)
for (l = 0; l < 16; l++)
{
int val = ptr[k*data->current.stride[0] + l];
sum += val;
sum_of_squares += val * val;
}
/* Variance = SSD - SAD^2 / (numpixels) */
int variance = sum_of_squares - sum * sum / 256;
handle->val[j*data->mb_width + i] = variance;
}
}
/* Apply the variance masking formula to all MBs */
for (i = 0; i < data->mb_height; i++)
{
for (j = 0; j < data->mb_width; j++)
{
float value = handle->val[i*data->mb_width + j];
float qscale_diff = strength * logf(value / center);
handle->quant[i*data->mb_width + j] *= (1.0 + qscale_diff);
}
}
/* Normalize the quantizer field */
data->quant = normalize_quantizer_field(handle->quant,
data->dquant,
data->mb_width*data->mb_height,
data->quant,
MAX(2,data->quant + data->quant/2));
/* Plugin job finished */
return(0);
}
/*----------------------------------------------------------------------------
* After plugin function (dummy function)
*--------------------------------------------------------------------------*/
static int
lumi_plg_after(lumi_data_t *handle, xvid_plg_data_t *data)
{
return(0);
}
/*****************************************************************************
* Helper functions
****************************************************************************/
#define RDIFF(a, b) ((int)(a+0.5)-(int)(b+0.5))
static int
normalize_quantizer_field(float *in,
int *out,
int num,
int min_quant,
int max_quant)
{
int i;
int finished;
do {
finished = 1;
for (i = 1; i < num; i++) {
if (RDIFF(in[i], in[i - 1]) > 2) {
in[i] -= (float) 0.5;
finished = 0;
} else if (RDIFF(in[i], in[i - 1]) < -2) {
in[i - 1] -= (float) 0.5;
finished = 0;
}
if (in[i] > max_quant) {
in[i] = (float) max_quant;
finished = 0;
}
if (in[i] < min_quant) {
in[i] = (float) min_quant;
finished = 0;
}
if (in[i - 1] > max_quant) {
in[i - 1] = (float) max_quant;
finished = 0;
}
if (in[i - 1] < min_quant) {
in[i - 1] = (float) min_quant;
finished = 0;
}
}
} while (!finished);
out[0] = 0;
for (i = 1; i < num; i++)
out[i] = RDIFF(in[i], in[i - 1]);
return (int) (in[0] + 0.5);
}
kinematic
5th October 2008, 22:01
Only one way to find out...tomorrow that is, now it's time for bed. In any case, thnx for posting it :)
SledgeHammer_999
5th October 2008, 22:18
Have you checked the link in Dark Shikari's first post here?--->http://forum.doom9.org/showthread.php?t=135093
kinematic
6th October 2008, 18:18
Got it to build succesfully. At first it wouldn't build because "make" complained so I copy'n'pasted your source to lumi_masking.c included in the official XviD source code. Next "make" complained again about a missing closing brace at the end......you lazy bum :D
edit:if anybody wants it, here it is
http://rapidshare.com/files/151491870/libxvidcore.so.4.1.rar.html
another edit: Is VAQ only supposed to be used with h263 or can it be used with custom cqm's as well ? (eqm_v3lr or eqm_v3hr) I think I remember reading about h263 somewhere on the forum.
Brother John
6th October 2008, 22:47
It certainly CAN. If it SHOULD is another matter. AQ and CQMs (including the default MPEG matrix) are two different ways to address the same issue, so they MIGHT conflict. It’s never been thoroughly tested though.
kinematic
7th October 2008, 19:46
Well, gonna do some tests to find out but I have a hunch it won't be as good at anamorphic encoding as a cqm specifically designed for it.
DeathTheSheep
25th October 2008, 19:24
How did you manage to do it? When I looked, there was no ./configure script...!
kinematic
26th October 2008, 11:56
The configure script is in build>generic.
To build it with Dark Shikari's VAQ patch you have to copy'n'paste Dark's code to plugin_lumimasking.c contained in the source code. If you put Dark's plugin_lumimasking.c in the sourcecode it won't build. It didn't throw up any error messages so my best guess is it's a version numbering thing.
DeathTheSheep
26th October 2008, 19:46
Actually, it wasn't anywhere in the tarball or CVS... Haha, don't worry, I figured it out. Linux to the rescue... darn autoconfig dependencies. ;)
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.