/*****************************************************************************
*
* - XviD 1.x export module for mplayer/mencoder -
*
* Copyright(C) 2003 Marco Belli <elcabesa@inwind.it>
* 2003-2004 Edouard Gomez <ed.gomez@free.fr>
*
* 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
*
****************************************************************************/
/*****************************************************************************
* Includes
****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <math.h>
#include <limits.h>
#include <time.h>
#include "../config.h"
#include "../mp_msg.h"
#ifdef HAVE_XVID4
#include "codec-cfg.h"
#include "stream.h"
#include "demuxer.h"
#include "stheader.h"
#include "muxer.h"
#include "img_format.h"
#include "mp_image.h"
#include "vf.h"
#include <xvid.h>
#include <stdio.h>
#include <stdarg.h>
#include <limits.h>
#include <assert.h>
#include "m_option.h"
#define XVID_FIRST_PASS_FILENAME "xvid-twopass.stats"
#define FINE (!0)
#define BAD (!FINE)
#define MAX_ZONES 64
// Profile flag definitions
#define PROFILE_ADAPTQUANT 0x00000001
#define PROFILE_BVOP 0x00000002
#define PROFILE_MPEGQUANT 0x00000004
#define PROFILE_INTERLACE 0x00000008
#define PROFILE_QPEL 0x00000010
#define PROFILE_GMC 0x00000020
#define PROFILE_4MV 0x00000040
#define PROFILE_DXN 0x00000080
// Reduce code duplication in profiles[] array
#define PROFILE_S (PROFILE_4MV)
#define PROFILE_AS (PROFILE_4MV|PROFILE_ADAPTQUANT|PROFILE_BVOP|PROFILE_MPEGQUANT|PROFILE_INTERLACE|PROFILE_QPEL|PROFILE_GMC)
typedef struct
{
char *name; ///< profile name
int id; ///< mpeg-4 profile id; iso/iec 14496-2:2001 table G-1
int width; ///< profile width restriction
int height; ///< profile height restriction
int fps; ///< profile frame rate restriction
int max_objects; ///< ??????
int total_vmv_buffer_sz; ///< macroblock memory; when BVOPS=false, vmv = 2*vcv; when BVOPS=true, vmv = 3*vcv
int max_vmv_buffer_sz; ///< max macroblocks per vop
int vcv_decoder_rate; ///< macroblocks decoded per second
int max_acpred_mbs; ///< percentage
int max_vbv_size; ///< max vbv size (bits) 16368 bits
int max_video_packet_length; ///< bits
int max_bitrate; ///< bits per second
int vbv_peakrate; ///< max bits over anyone second period; 0=don't care
int dxn_max_bframes; ///< dxn: max consecutive bframes
unsigned int flags; ///< flags for allowed options/dxn note the definitions for PROFILE_S and PROFILE_AS
} profile_t;
// Code taken from Libavcodec and ve_lavc.c to handle Aspect Ratio calculation
typedef struct xvid_rational_s{
int num;
int den;
} XVIDRational;
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) >= 0 ? (a) : (-(a)))
static int64_t xvid_gcd(int64_t a, int64_t b){
if(b) return xvid_gcd(b, a%b);
else return a;
}
static int xvid_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max){
int exact=1, sign=0;
int64_t gcd;
assert(den != 0);
if(den < 0){
den= -den;
nom= -nom;
}
if(nom < 0){
nom= -nom;
sign= 1;
}
gcd = xvid_gcd(nom, den);
nom /= gcd;
den /= gcd;
if(nom > max || den > max){
XVIDRational a0={0,1}, a1={1,0};
exact=0;
for(;;){
int64_t x= nom / den;
int64_t a2n= x*a1.num + a0.num;
int64_t a2d= x*a1.den
|