annotate libmpcodecs/ve_xvid4.c @ 14174:18d902312b20

Mention how to concatenate files with -vo yuv4mpeg and -fixed-vo.
author diego
date Fri, 17 Dec 2004 18:41:41 +0000
parents 5a786c7e4df4
children acf3241be19b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1 /*****************************************************************************
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
2 *
13610
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
3 * - XviD 1.x export module for mplayer/mencoder -
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
4 *
13610
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
5 * Copyright(C) 2003 Marco Belli <elcabesa@inwind.it>
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
6 * 2003-2004 Edouard Gomez <ed.gomez@free.fr>
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
7 *
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
11 * (at your option) any later version.
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
12 *
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
16 * GNU General Public License for more details.
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
17 *
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
21 *
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
22 ****************************************************************************/
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
23
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
24 /*****************************************************************************
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
25 * Includes
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
26 ****************************************************************************/
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
27
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
28 #include <stdio.h>
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
29 #include <stdlib.h>
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
30 #include <string.h>
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
31 #include <errno.h>
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
32 #include <math.h>
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
33 #include <limits.h>
11920
886e33d9dd10 psnr and debug option added
iive
parents: 11912
diff changeset
34 #include <time.h>
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
35
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
36 #include "../config.h"
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
37 #include "../mp_msg.h"
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
38
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
39 #ifdef HAVE_XVID4
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
40
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
41 #include "codec-cfg.h"
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
42 #include "stream.h"
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
43 #include "demuxer.h"
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
44 #include "stheader.h"
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
45
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
46 #include "muxer.h"
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
47
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
48 #include "img_format.h"
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
49 #include "mp_image.h"
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
50 #include "vf.h"
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
51
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
52 #include <xvid.h>
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
53 #include <stdio.h>
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
54 #include <stdarg.h>
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
55 #include <limits.h>
11912
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
56 #include <assert.h>
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
57
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
58 #include "m_option.h"
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
59
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
60 #define XVID_FIRST_PASS_FILENAME "xvid-twopass.stats"
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
61 #define FINE (!0)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
62 #define BAD (!FINE)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
63
11912
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
64 // Code taken from Libavcodec and ve_lavc.c to handle Aspect Ratio calculation
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
65
13610
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
66 typedef struct xvid_rational_s{
11912
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
67 int num;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
68 int den;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
69 } XVIDRational;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
70
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
71 #define MAX(a,b) ((a) > (b) ? (a) : (b))
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
72 #define ABS(a) ((a) >= 0 ? (a) : (-(a)))
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
73
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
74
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
75 static int64_t xvid_gcd(int64_t a, int64_t b){
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
76 if(b) return xvid_gcd(b, a%b);
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
77 else return a;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
78 }
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
79
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
80 static int xvid_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max){
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
81 int exact=1, sign=0;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
82 int64_t gcd;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
83
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
84 assert(den != 0);
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
85
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
86 if(den < 0){
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
87 den= -den;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
88 nom= -nom;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
89 }
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
90
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
91 if(nom < 0){
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
92 nom= -nom;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
93 sign= 1;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
94 }
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
95
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
96 gcd = xvid_gcd(nom, den);
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
97 nom /= gcd;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
98 den /= gcd;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
99
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
100 if(nom > max || den > max){
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
101 XVIDRational a0={0,1}, a1={1,0};
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
102 exact=0;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
103
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
104 for(;;){
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
105 int64_t x= nom / den;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
106 int64_t a2n= x*a1.num + a0.num;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
107 int64_t a2d= x*a1.den + a0.den;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
108
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
109 if(a2n > max || a2d > max) break;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
110
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
111 nom %= den;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
112
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
113 a0= a1;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
114 a1= (XVIDRational){a2n, a2d};
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
115 if(nom==0) break;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
116 x= nom; nom=den; den=x;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
117 }
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
118 nom= a1.num;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
119 den= a1.den;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
120 }
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
121
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
122 assert(xvid_gcd(nom, den) == 1);
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
123
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
124 if(sign) nom= -nom;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
125
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
126 *dst_nom = nom;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
127 *dst_den = den;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
128
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
129 return exact;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
130 }
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
131
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
132
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
133 static XVIDRational xvid_d2q(double d, int max){
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
134 XVIDRational a;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
135 int exponent= MAX( (int)(log(ABS(d) + 1e-20)/log(2)), 0);
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
136 int64_t den= 1LL << (61 - exponent);
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
137 xvid_reduce(&a.num, &a.den, (int64_t)(d * den + 0.5), den, max);
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
138
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
139 return a;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
140 }
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
141
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
142
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
143
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
144 /*****************************************************************************
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
145 * Configuration options
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
146 ****************************************************************************/
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
147
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
148 static int xvidenc_bitrate = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
149 static int xvidenc_pass = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
150 static float xvidenc_quantizer = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
151
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
152 static int xvidenc_packed = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
153 static int xvidenc_closed_gop = 1;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
154 static int xvidenc_interlaced = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
155 static int xvidenc_quarterpel = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
156 static int xvidenc_gmc = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
157 static int xvidenc_trellis = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
158 static int xvidenc_cartoon = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
159 static int xvidenc_hqacpred = 1;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
160 static int xvidenc_chromame = 0;
11912
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
161 static int xvidenc_chroma_opt = 0;
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
162 static int xvidenc_vhq = 0;
13610
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
163 static int xvidenc_bvhq = 0;
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
164 static int xvidenc_motion = 6;
11912
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
165 static int xvidenc_turbo = 0;
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
166 static int xvidenc_stats = 0;
11912
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
167 static int xvidenc_max_key_interval = 0; /* Let xvidcore set a 10s interval by default */
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
168 static int xvidenc_frame_drop_ratio = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
169 static int xvidenc_greyscale = 0;
11920
886e33d9dd10 psnr and debug option added
iive
parents: 11912
diff changeset
170 static int xvidenc_debug = 0;
886e33d9dd10 psnr and debug option added
iive
parents: 11912
diff changeset
171 static int xvidenc_psnr = 0;
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
172
11912
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
173 static int xvidenc_max_bframes = 2;
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
174 static int xvidenc_bquant_ratio = 150;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
175 static int xvidenc_bquant_offset = 100;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
176 static int xvidenc_bframe_threshold = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
177
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
178 static int xvidenc_min_quant[3] = {2, 2, 2};
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
179 static int xvidenc_max_quant[3] = {31, 31, 31};
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
180 static char *xvidenc_intra_matrix_file = NULL;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
181 static char *xvidenc_inter_matrix_file = NULL;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
182 static char *xvidenc_quant_method = NULL;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
183
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
184 static int xvidenc_cbr_reaction_delay_factor = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
185 static int xvidenc_cbr_averaging_period = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
186 static int xvidenc_cbr_buffer = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
187
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
188 static int xvidenc_vbr_keyframe_boost = 0;
11912
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
189 static int xvidenc_vbr_overflow_control_strength = 5;
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
190 static int xvidenc_vbr_curve_compression_high = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
191 static int xvidenc_vbr_curve_compression_low = 0;
11912
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
192 static int xvidenc_vbr_max_overflow_improvement = 5;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
193 static int xvidenc_vbr_max_overflow_degradation = 5;
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
194 static int xvidenc_vbr_kfreduction = 0;
11586
efe910b068fc xvid 1.0 beta2
iive
parents: 11491
diff changeset
195 static int xvidenc_vbr_kfthreshold = 0;
11912
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
196 static int xvidenc_vbr_container_frame_overhead = 24; /* mencoder uses AVI container */
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
197
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
198 static char *xvidenc_par = NULL;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
199 static int xvidenc_par_width = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
200 static int xvidenc_par_height = 0;
11912
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
201 static float xvidenc_dar_aspect = 0.0f;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
202 static int xvidenc_autoaspect = 0;
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
203
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
204 m_option_t xvidencopts_conf[] =
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
205 {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
206 /* Standard things mencoder should be able to treat directly */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
207 {"bitrate", &xvidenc_bitrate, CONF_TYPE_INT, 0, 0, 0, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
208 {"pass", &xvidenc_pass, CONF_TYPE_INT, CONF_RANGE, 1, 2, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
209 {"fixed_quant", &xvidenc_quantizer, CONF_TYPE_FLOAT, CONF_RANGE, 1, 31, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
210
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
211 /* Features */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
212 {"quant_type", &xvidenc_quant_method, CONF_TYPE_STRING, 0, 0, 0, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
213 {"me_quality", &xvidenc_motion, CONF_TYPE_INT, CONF_RANGE, 0, 6, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
214 {"chroma_me", &xvidenc_chromame, CONF_TYPE_FLAG, 0, 0, 1, NULL},
13853
5a786c7e4df4 have each XviD's option flag have its (no)counterpart
gpoirier
parents: 13675
diff changeset
215 {"nochroma_me", &xvidenc_chromame, CONF_TYPE_FLAG, 0, 1, 0, NULL},
11912
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
216 {"chroma_opt", &xvidenc_chroma_opt, CONF_TYPE_FLAG, 0, 0, 1, NULL},
13853
5a786c7e4df4 have each XviD's option flag have its (no)counterpart
gpoirier
parents: 13675
diff changeset
217 {"nochroma_opt", &xvidenc_chroma_opt, CONF_TYPE_FLAG, 0, 1, 0, NULL},
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
218 {"vhq", &xvidenc_vhq, CONF_TYPE_INT, CONF_RANGE, 0, 4, NULL},
13610
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
219 {"bvhq", &xvidenc_bvhq, CONF_TYPE_INT, CONF_RANGE, 0, 1, NULL},
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
220 {"max_bframes", &xvidenc_max_bframes, CONF_TYPE_INT, CONF_RANGE, 0, 20, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
221 {"bquant_ratio", &xvidenc_bquant_ratio, CONF_TYPE_INT, CONF_RANGE, 0, 200, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
222 {"bquant_offset", &xvidenc_bquant_offset, CONF_TYPE_INT, CONF_RANGE, 0, 200, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
223 {"bf_threshold", &xvidenc_bframe_threshold, CONF_TYPE_INT, CONF_RANGE, -255, 255, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
224 {"qpel", &xvidenc_quarterpel, CONF_TYPE_FLAG, 0, 0, 1, NULL},
13853
5a786c7e4df4 have each XviD's option flag have its (no)counterpart
gpoirier
parents: 13675
diff changeset
225 {"noqpel", &xvidenc_quarterpel, CONF_TYPE_FLAG, 0, 1, 0, NULL},
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
226 {"gmc", &xvidenc_gmc, CONF_TYPE_FLAG, 0, 0, 1, NULL},
13853
5a786c7e4df4 have each XviD's option flag have its (no)counterpart
gpoirier
parents: 13675
diff changeset
227 {"nogmc", &xvidenc_gmc, CONF_TYPE_FLAG, 0, 1, 0, NULL},
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
228 {"trellis", &xvidenc_trellis, CONF_TYPE_FLAG, 0, 0, 1, NULL},
13853
5a786c7e4df4 have each XviD's option flag have its (no)counterpart
gpoirier
parents: 13675
diff changeset
229 {"notrellis", &xvidenc_trellis, CONF_TYPE_FLAG, 0, 1, 0, NULL},
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
230 {"packed", &xvidenc_packed, CONF_TYPE_FLAG, 0, 0, 1, NULL},
13853
5a786c7e4df4 have each XviD's option flag have its (no)counterpart
gpoirier
parents: 13675
diff changeset
231 {"nopacked", &xvidenc_packed, CONF_TYPE_FLAG, 0, 1, 0, NULL},
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
232 {"closed_gop", &xvidenc_closed_gop, CONF_TYPE_FLAG, 0, 0, 1, NULL},
13853
5a786c7e4df4 have each XviD's option flag have its (no)counterpart
gpoirier
parents: 13675
diff changeset
233 {"noclosed_gop", &xvidenc_closed_gop, CONF_TYPE_FLAG, 0, 1, 0, NULL},
11491
5af505348795 use the old names for 4 options
iive
parents: 11437
diff changeset
234 {"interlacing", &xvidenc_interlaced, CONF_TYPE_FLAG, 0, 0, 1, NULL},
13853
5a786c7e4df4 have each XviD's option flag have its (no)counterpart
gpoirier
parents: 13675
diff changeset
235 {"nointerlacing", &xvidenc_interlaced, CONF_TYPE_FLAG, 0, 1, 0, NULL},
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
236 {"cartoon", &xvidenc_cartoon, CONF_TYPE_FLAG, 0, 0, 1, NULL},
13853
5a786c7e4df4 have each XviD's option flag have its (no)counterpart
gpoirier
parents: 13675
diff changeset
237 {"nocartoon", &xvidenc_cartoon, CONF_TYPE_FLAG, 0, 1, 0, NULL},
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
238 {"hq_ac", &xvidenc_hqacpred, CONF_TYPE_FLAG, 0, 0, 1, NULL},
13853
5a786c7e4df4 have each XviD's option flag have its (no)counterpart
gpoirier
parents: 13675
diff changeset
239 {"nohq_ac", &xvidenc_hqacpred, CONF_TYPE_FLAG, 0, 1, 0, NULL},
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
240 {"frame_drop_ratio", &xvidenc_frame_drop_ratio, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
241 {"max_key_interval", &xvidenc_max_key_interval, CONF_TYPE_INT, CONF_MIN, 0, 0, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
242 {"greyscale", &xvidenc_greyscale, CONF_TYPE_FLAG, 0, 0, 1, NULL},
13853
5a786c7e4df4 have each XviD's option flag have its (no)counterpart
gpoirier
parents: 13675
diff changeset
243 {"nogreyscale", &xvidenc_greyscale, CONF_TYPE_FLAG, 0, 1, 0, NULL},
11912
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
244 {"turbo", &xvidenc_turbo, CONF_TYPE_FLAG, 0, 0, 1, NULL},
11920
886e33d9dd10 psnr and debug option added
iive
parents: 11912
diff changeset
245 {"debug", &xvidenc_debug, CONF_TYPE_INT , 0 ,0,-1,NULL},
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
246 {"stats", &xvidenc_stats, CONF_TYPE_FLAG, 0, 0, 1, NULL},
11920
886e33d9dd10 psnr and debug option added
iive
parents: 11912
diff changeset
247 {"psnr", &xvidenc_psnr , CONF_TYPE_FLAG, 0, 0, 1, NULL},
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
248
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
249
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
250 /* section [quantizer] */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
251 {"min_iquant", &xvidenc_min_quant[0], CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
252 {"max_iquant", &xvidenc_max_quant[0], CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
253 {"min_pquant", &xvidenc_min_quant[1], CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
254 {"max_pquant", &xvidenc_max_quant[1], CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
255 {"min_bquant", &xvidenc_min_quant[2], CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
256 {"max_bquant", &xvidenc_max_quant[2], CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
257 {"quant_intra_matrix", &xvidenc_intra_matrix_file, CONF_TYPE_STRING, 0, 0, 100, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
258 {"quant_inter_matrix", &xvidenc_inter_matrix_file, CONF_TYPE_STRING, 0, 0, 100, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
259
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
260 /* section [cbr] */
11491
5af505348795 use the old names for 4 options
iive
parents: 11437
diff changeset
261 {"rc_reaction_delay_factor", &xvidenc_cbr_reaction_delay_factor, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL},
5af505348795 use the old names for 4 options
iive
parents: 11437
diff changeset
262 {"rc_averaging_period", &xvidenc_cbr_averaging_period, CONF_TYPE_INT, CONF_MIN, 0, 0, NULL},
5af505348795 use the old names for 4 options
iive
parents: 11437
diff changeset
263 {"rc_buffer", &xvidenc_cbr_buffer, CONF_TYPE_INT, CONF_MIN, 0, 0, NULL},
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
264
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
265 /* section [vbr] */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
266 {"keyframe_boost", &xvidenc_vbr_keyframe_boost, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
267 {"curve_compression_high", &xvidenc_vbr_curve_compression_high, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
268 {"curve_compression_low", &xvidenc_vbr_curve_compression_low, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
269 {"overflow_control_strength", &xvidenc_vbr_overflow_control_strength, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
270 {"max_overflow_improvement", &xvidenc_vbr_max_overflow_improvement, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
271 {"max_overflow_degradation", &xvidenc_vbr_max_overflow_degradation, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
272 {"kfreduction", &xvidenc_vbr_kfreduction, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL},
11586
efe910b068fc xvid 1.0 beta2
iive
parents: 11491
diff changeset
273 {"kfthreshold", &xvidenc_vbr_kfthreshold, CONF_TYPE_INT, CONF_MIN, 0, 0, NULL},
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
274 {"container_frame_overhead", &xvidenc_vbr_container_frame_overhead, CONF_TYPE_INT, CONF_MIN, 0, 0, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
275
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
276 /* Section Aspect Ratio */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
277 {"par", &xvidenc_par, CONF_TYPE_STRING, 0, 0, 0, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
278 {"par_width", &xvidenc_par_width, CONF_TYPE_INT, CONF_RANGE, 0, 255, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
279 {"par_height", &xvidenc_par_height, CONF_TYPE_INT, CONF_RANGE, 0, 255, NULL},
11912
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
280 {"aspect", &xvidenc_dar_aspect, CONF_TYPE_FLOAT, CONF_RANGE, 0.1, 9.99, NULL},
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
281 {"autoaspect", &xvidenc_autoaspect, CONF_TYPE_FLAG, 0, 0, 1, NULL},
13853
5a786c7e4df4 have each XviD's option flag have its (no)counterpart
gpoirier
parents: 13675
diff changeset
282 {"noautoaspect", &xvidenc_autoaspect, CONF_TYPE_FLAG, 0, 1, 0, NULL},
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
283
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
284 /* End of the config array */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
285 {NULL, 0, 0, 0, 0, 0, NULL}
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
286 };
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
287
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
288 /*****************************************************************************
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
289 * Module private data
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
290 ****************************************************************************/
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
291
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
292 typedef struct _xvid_mplayer_module_t
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
293 {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
294 /* Instance related global vars */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
295 void *instance;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
296 xvid_gbl_init_t init;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
297 xvid_enc_create_t create;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
298 xvid_enc_frame_t frame;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
299 xvid_plugin_single_t onepass;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
300 xvid_plugin_2pass1_t pass1;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
301 xvid_plugin_2pass2_t pass2;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
302
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
303 /* This data must survive local block scope, so here it is */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
304 xvid_enc_plugin_t plugins[7];
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
305 xvid_enc_zone_t zones[1];
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
306
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
307 /* MPEG4 stream buffer */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
308 muxer_stream_t *mux;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
309
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
310 /* Stats accumulators */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
311 int frames;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
312 long long sse_y;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
313 long long sse_u;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
314 long long sse_v;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
315
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
316 /* Min & Max PSNR */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
317 int min_sse_y;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
318 int min_sse_u;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
319 int min_sse_v;
11920
886e33d9dd10 psnr and debug option added
iive
parents: 11912
diff changeset
320 int min_framenum;
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
321 int max_sse_y;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
322 int max_sse_u;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
323 int max_sse_v;
11920
886e33d9dd10 psnr and debug option added
iive
parents: 11912
diff changeset
324 int max_framenum;
11912
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
325
11920
886e33d9dd10 psnr and debug option added
iive
parents: 11912
diff changeset
326 int pixels;
13610
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
327
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
328 /* DAR/PAR and all that thingies */
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
329 int d_width;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
330 int d_height;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
331 FILE *fvstats;
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
332 } xvid_mplayer_module_t;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
333
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
334 static void dispatch_settings(xvid_mplayer_module_t *mod);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
335 static int set_create_struct(xvid_mplayer_module_t *mod);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
336 static int set_frame_struct(xvid_mplayer_module_t *mod, mp_image_t *mpi);
13610
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
337 static void update_stats(xvid_mplayer_module_t *mod, xvid_enc_stats_t *stats);
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
338 static void print_stats(xvid_mplayer_module_t *mod);
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
339 static void flush_internal_buffers(xvid_mplayer_module_t *mod);
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
340 static const char *par_string(int parcode);
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
341 static const char *errorstring(int err);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
342
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
343 /*****************************************************************************
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
344 * Video Filter API function definitions
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
345 ****************************************************************************/
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
346
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
347 /*============================================================================
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
348 * config
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
349 *==========================================================================*/
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
350
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
351 static int
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
352 config(struct vf_instance_s* vf,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
353 int width, int height, int d_width, int d_height,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
354 unsigned int flags, unsigned int outfmt)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
355 {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
356 int err;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
357 xvid_mplayer_module_t *mod = (xvid_mplayer_module_t *)vf->priv;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
358
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
359 /* Complete the muxer initialization */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
360 mod->mux->bih->biWidth = width;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
361 mod->mux->bih->biHeight = height;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
362 mod->mux->bih->biSizeImage =
13610
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
363 mod->mux->bih->biWidth * mod->mux->bih->biHeight * 3 / 2;
12061
656a1b45b309 Use aspect from encoder for AVI vprp header
ranma
parents: 11929
diff changeset
364 mod->mux->aspect = (float)d_width/d_height;
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
365
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
366 /* Message the FourCC type */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
367 mp_msg(MSGT_MENCODER, MSGL_INFO,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
368 "videocodec: XviD (%dx%d fourcc=%x [%.4s])\n",
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
369 width, height, mod->mux->bih->biCompression,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
370 (char *)&mod->mux->bih->biCompression);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
371
13610
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
372 /* Total number of pixels per frame required for PSNR */
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
373 mod->pixels = mod->mux->bih->biWidth*mod->mux->bih->biHeight;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
374
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
375 /*--------------------------------------------------------------------
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
376 * Dispatch all module settings to XviD structures
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
377 *------------------------------------------------------------------*/
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
378
11912
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
379 mod->d_width = d_width;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
380 mod->d_height = d_height;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
381
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
382 dispatch_settings(mod);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
383
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
384 /*--------------------------------------------------------------------
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
385 * Set remaining information in the xvid_enc_create_t structure
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
386 *------------------------------------------------------------------*/
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
387
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
388 if(set_create_struct(mod) == BAD)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
389 return(BAD);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
390
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
391 /*--------------------------------------------------------------------
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
392 * Encoder instance creation
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
393 *------------------------------------------------------------------*/
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
394
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
395 err = xvid_encore(NULL, XVID_ENC_CREATE, &mod->create, NULL);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
396
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
397 if(err<0) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
398 mp_msg(MSGT_MENCODER, MSGL_ERR,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
399 "xvid: xvidcore returned a '%s' error\n", errorstring(err));
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
400 return(BAD);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
401 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
402
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
403 /* Store the encoder instance into the private data */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
404 mod->instance = mod->create.handle;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
405
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
406 return(FINE);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
407 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
408
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
409 /*============================================================================
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
410 * uninit
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
411 *==========================================================================*/
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
412
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
413 static void
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
414 uninit(struct vf_instance_s* vf)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
415 {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
416
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
417 xvid_mplayer_module_t *mod = (xvid_mplayer_module_t *)vf->priv;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
418
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
419 /* Destroy xvid instance */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
420 xvid_encore(mod->instance, XVID_ENC_DESTROY, NULL, NULL);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
421
13610
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
422 /* Display stats (if any) */
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
423 print_stats(mod);
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
424
13610
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
425 /* Close PSNR file if ever opened */
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
426 if (mod->fvstats) {
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
427 fclose(mod->fvstats);
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
428 mod->fvstats = NULL;
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
429 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
430
13610
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
431 /* Free allocated memory */
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
432 if(mod->frame.quant_intra_matrix)
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
433 free(mod->frame.quant_intra_matrix);
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
434
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
435 if(mod->frame.quant_inter_matrix)
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
436 free(mod->frame.quant_inter_matrix);
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
437
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
438 if(mod->mux->bih)
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
439 free(mod->mux->bih);
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
440
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
441 free(vf->priv);
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
442 vf->priv=NULL;
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
443
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
444 return;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
445 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
446
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
447 /*============================================================================
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
448 * control
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
449 *==========================================================================*/
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
450
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
451 static int
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
452 control(struct vf_instance_s* vf, int request, void* data)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
453 {
13610
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
454 xvid_mplayer_module_t *mod = (xvid_mplayer_module_t *)vf->priv;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
455
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
456 switch(request){
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
457 case VFCTRL_FLUSH_FRAMES:
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
458 if(mod)/*paranoid*/
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
459 flush_internal_buffers(mod);
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
460 break;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
461 }
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
462 return(CONTROL_UNKNOWN);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
463 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
464
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
465 /*============================================================================
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
466 * query_format
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
467 *==========================================================================*/
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
468
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
469 static int
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
470 query_format(struct vf_instance_s* vf, unsigned int fmt)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
471 {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
472 switch(fmt){
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
473 case IMGFMT_YV12:
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
474 case IMGFMT_IYUV:
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
475 case IMGFMT_I420:
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
476 return(VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
477 case IMGFMT_YUY2:
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
478 case IMGFMT_UYVY:
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
479 return(VFCAP_CSP_SUPPORTED);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
480 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
481 return(BAD);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
482 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
483
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
484 /*============================================================================
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
485 * put_image
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
486 *==========================================================================*/
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
487
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
488 static int
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
489 put_image(struct vf_instance_s* vf, mp_image_t *mpi)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
490 {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
491 int size;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
492 xvid_enc_stats_t stats;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
493 xvid_mplayer_module_t *mod = (xvid_mplayer_module_t *)vf->priv;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
494
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
495 /* Prepare the stats */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
496 memset(&stats,0,sizeof( xvid_enc_stats_t));
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
497 stats.version = XVID_VERSION;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
498
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
499 /* -------------------------------------------------------------------
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
500 * Set remaining information in the xvid_enc_frame_t structure
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
501 * NB: all the other struct members were initialized by
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
502 * dispatch_settings
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
503 * -----------------------------------------------------------------*/
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
504
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
505 if(set_frame_struct(mod, mpi) == BAD)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
506 return(BAD);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
507
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
508 /* -------------------------------------------------------------------
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
509 * Encode the frame
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
510 * ---------------------------------------------------------------- */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
511
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
512 size = xvid_encore(mod->instance, XVID_ENC_ENCODE, &mod->frame, &stats);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
513
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
514 /* Analyse the returned value */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
515 if(size<0) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
516 mp_msg(MSGT_MENCODER, MSGL_ERR,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
517 "xvid: xvidcore returned a '%s' error\n", errorstring(size));
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
518 return(BAD);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
519 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
520
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
521 /* If size is == 0, we're done with that frame */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
522 if(size == 0) return(FINE);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
523
13610
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
524 /* xvidcore returns stats about encoded frame in an asynchronous way
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
525 * accumulate these stats */
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
526 update_stats(mod, &stats);
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
527
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
528 /* xvidcore outputed bitstream -- mux it */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
529 muxer_write_chunk(mod->mux,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
530 size,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
531 (mod->frame.out_flags & XVID_KEYFRAME)?0x10:0);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
532
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
533 return(FINE);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
534 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
535
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
536 /*============================================================================
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
537 * vf_open
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
538 *==========================================================================*/
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
539
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
540 static int
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
541 vf_open(vf_instance_t *vf, char* args)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
542 {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
543 xvid_mplayer_module_t *mod;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
544 xvid_gbl_init_t xvid_gbl_init;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
545 xvid_gbl_info_t xvid_gbl_info;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
546
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
547 /* Setting libmpcodec module API pointers */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
548 vf->config = config;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
549 vf->control = control;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
550 vf->uninit = uninit;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
551 vf->query_format = query_format;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
552 vf->put_image = put_image;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
553
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
554 /* Allocate the private part of the codec module */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
555 vf->priv = malloc(sizeof(xvid_mplayer_module_t));
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
556 mod = (xvid_mplayer_module_t*)vf->priv;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
557
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
558 if(mod == NULL) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
559 mp_msg(MSGT_MENCODER,MSGL_ERR,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
560 "xvid: memory allocation failure (private data)\n");
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
561 return(BAD);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
562 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
563
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
564 /* Initialize the module to zeros */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
565 memset(mod, 0, sizeof(xvid_mplayer_module_t));
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
566 mod->min_sse_y = mod->min_sse_u = mod->min_sse_v = INT_MAX;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
567 mod->max_sse_y = mod->max_sse_u = mod->max_sse_v = INT_MIN;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
568
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
569 /* Bind the Muxer */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
570 mod->mux = (muxer_stream_t*)args;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
571
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
572 /* Initialize muxer BITMAP header */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
573 mod->mux->bih = malloc(sizeof(BITMAPINFOHEADER));
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
574
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
575 if(mod->mux->bih == NULL) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
576 mp_msg(MSGT_MENCODER,MSGL_ERR,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
577 "xvid: memory allocation failure (BITMAP header)\n");
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
578 return(BAD);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
579 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
580
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
581 mod->mux->bih->biSize = sizeof(BITMAPINFOHEADER);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
582 mod->mux->bih->biWidth = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
583 mod->mux->bih->biHeight = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
584 mod->mux->bih->biPlanes = 1;
13610
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
585 mod->mux->bih->biBitCount = 12;
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
586 mod->mux->bih->biCompression = mmioFOURCC('X','V','I','D');
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
587
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
588 /* Retrieve information about the host XviD library */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
589 memset(&xvid_gbl_info, 0, sizeof(xvid_gbl_info_t));
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
590 xvid_gbl_info.version = XVID_VERSION;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
591
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
592 if (xvid_global(NULL, XVID_GBL_INFO, &xvid_gbl_info, NULL) < 0) {
13610
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
593 mp_msg(MSGT_MENCODER,MSGL_WARN, "xvid: could not get information about the library\n");
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
594 } else {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
595 mp_msg(MSGT_MENCODER,MSGL_INFO, "xvid: using library version %d.%d.%d (build %s)\n",
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
596 XVID_VERSION_MAJOR(xvid_gbl_info.actual_version),
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
597 XVID_VERSION_MINOR(xvid_gbl_info.actual_version),
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
598 XVID_VERSION_PATCH(xvid_gbl_info.actual_version),
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
599 xvid_gbl_info.build);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
600 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
601
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
602 /* Initialize the xvid_gbl_init structure */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
603 memset(&xvid_gbl_init, 0, sizeof(xvid_gbl_init_t));
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
604 xvid_gbl_init.version = XVID_VERSION;
11920
886e33d9dd10 psnr and debug option added
iive
parents: 11912
diff changeset
605 xvid_gbl_init.debug = xvidenc_debug;
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
606
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
607 /* Initialize the xvidcore library */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
608 if (xvid_global(NULL, XVID_GBL_INIT, &xvid_gbl_init, NULL) < 0) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
609 mp_msg(MSGT_MENCODER,MSGL_ERR, "xvid: initialisation failure\n");
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
610 return(BAD);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
611 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
612
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
613 return(FINE);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
614 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
615
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
616 /*****************************************************************************
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
617 * Helper functions
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
618 ****************************************************************************/
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
619
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
620 static void *read_matrix(unsigned char *filename);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
621
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
622 static void dispatch_settings(xvid_mplayer_module_t *mod)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
623 {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
624 xvid_enc_create_t *create = &mod->create;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
625 xvid_enc_frame_t *frame = &mod->frame;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
626 xvid_plugin_single_t *onepass = &mod->onepass;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
627 xvid_plugin_2pass2_t *pass2 = &mod->pass2;
11912
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
628 XVIDRational ar;
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
629
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
630 const int motion_presets[7] =
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
631 {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
632 0,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
633 0,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
634 0,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
635 0,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
636 XVID_ME_HALFPELREFINE16,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
637 XVID_ME_HALFPELREFINE16 | XVID_ME_ADVANCEDDIAMOND16,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
638 XVID_ME_HALFPELREFINE16 | XVID_ME_EXTSEARCH16 |
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
639 XVID_ME_HALFPELREFINE8 | XVID_ME_USESQUARES16
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
640 };
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
641
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
642
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
643 /* -------------------------------------------------------------------
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
644 * Dispatch all settings having an impact on the "create" structure
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
645 * This includes plugins as they are passed to encore through the
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
646 * create structure
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
647 * -----------------------------------------------------------------*/
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
648
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
649 /* -------------------------------------------------------------------
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
650 * The create structure
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
651 * ---------------------------------------------------------------- */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
652
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
653 create->global = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
654
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
655 if(xvidenc_packed)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
656 create->global |= XVID_GLOBAL_PACKED;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
657
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
658 if(xvidenc_closed_gop)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
659 create->global |= XVID_GLOBAL_CLOSED_GOP;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
660
11920
886e33d9dd10 psnr and debug option added
iive
parents: 11912
diff changeset
661 if(xvidenc_psnr)
886e33d9dd10 psnr and debug option added
iive
parents: 11912
diff changeset
662 xvidenc_stats = 1;
886e33d9dd10 psnr and debug option added
iive
parents: 11912
diff changeset
663
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
664 if(xvidenc_stats)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
665 create->global |= XVID_GLOBAL_EXTRASTATS_ENABLE;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
666
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
667 create->num_zones = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
668 create->zones = NULL;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
669 create->num_plugins = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
670 create->plugins = NULL;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
671 create->num_threads = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
672 create->max_bframes = xvidenc_max_bframes;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
673 create->bquant_ratio = xvidenc_bquant_ratio;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
674 create->bquant_offset = xvidenc_bquant_offset;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
675 create->max_key_interval = xvidenc_max_key_interval;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
676 create->frame_drop_ratio = xvidenc_frame_drop_ratio;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
677 create->min_quant[0] = xvidenc_min_quant[0];
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
678 create->min_quant[1] = xvidenc_min_quant[1];
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
679 create->min_quant[2] = xvidenc_min_quant[2];
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
680 create->max_quant[0] = xvidenc_max_quant[0];
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
681 create->max_quant[1] = xvidenc_max_quant[1];
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
682 create->max_quant[2] = xvidenc_max_quant[2];
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
683
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
684
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
685 /* -------------------------------------------------------------------
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
686 * The single pass plugin
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
687 * ---------------------------------------------------------------- */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
688
13675
d4cba4c4c54c Bitrate setting option in ve_xvid4.c doesn't follow the rules described
rathann
parents: 13610
diff changeset
689 if (xvidenc_bitrate > 16000) onepass->bitrate = xvidenc_bitrate;
d4cba4c4c54c Bitrate setting option in ve_xvid4.c doesn't follow the rules described
rathann
parents: 13610
diff changeset
690 else onepass->bitrate = xvidenc_bitrate*1000;
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
691 onepass->reaction_delay_factor = xvidenc_cbr_reaction_delay_factor;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
692 onepass->averaging_period = xvidenc_cbr_averaging_period;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
693 onepass->buffer = xvidenc_cbr_buffer;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
694
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
695 /* -------------------------------------------------------------------
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
696 * The pass2 plugin
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
697 * ---------------------------------------------------------------- */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
698
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
699 pass2->keyframe_boost = xvidenc_vbr_keyframe_boost;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
700 pass2->overflow_control_strength = xvidenc_vbr_overflow_control_strength;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
701 pass2->curve_compression_high = xvidenc_vbr_curve_compression_high;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
702 pass2->curve_compression_low = xvidenc_vbr_curve_compression_low;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
703 pass2->max_overflow_improvement = xvidenc_vbr_max_overflow_improvement;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
704 pass2->max_overflow_degradation = xvidenc_vbr_max_overflow_degradation;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
705 pass2->kfreduction = xvidenc_vbr_kfreduction;
11586
efe910b068fc xvid 1.0 beta2
iive
parents: 11491
diff changeset
706 pass2->kfthreshold = xvidenc_vbr_kfthreshold;
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
707 pass2->container_frame_overhead = xvidenc_vbr_container_frame_overhead;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
708
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
709 /* -------------------------------------------------------------------
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
710 * The frame structure
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
711 * ---------------------------------------------------------------- */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
712 frame->vol_flags = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
713 frame->vop_flags = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
714 frame->motion = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
715
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
716 frame->vop_flags |= XVID_VOP_HALFPEL;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
717 frame->motion |= motion_presets[xvidenc_motion];
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
718
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
719 if(xvidenc_stats)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
720 frame->vol_flags |= XVID_VOL_EXTRASTATS;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
721
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
722 if(xvidenc_greyscale)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
723 frame->vop_flags |= XVID_VOP_GREYSCALE;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
724
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
725 if(xvidenc_cartoon) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
726 frame->vop_flags |= XVID_VOP_CARTOON;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
727 frame->motion |= XVID_ME_DETECT_STATIC_MOTION;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
728 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
729
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
730 if(xvidenc_intra_matrix_file != NULL) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
731 frame->quant_intra_matrix = (unsigned char*)read_matrix(xvidenc_intra_matrix_file);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
732 if(frame->quant_intra_matrix != NULL) {
13610
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
733 mp_msg(MSGT_MENCODER, MSGL_INFO, "xvid: Loaded Intra matrix (switching to mpeg quantization type)\n");
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
734 if(xvidenc_quant_method) free(xvidenc_quant_method);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
735 xvidenc_quant_method = strdup("mpeg");
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
736 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
737 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
738 if(xvidenc_inter_matrix_file != NULL) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
739 frame->quant_inter_matrix = read_matrix(xvidenc_inter_matrix_file);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
740 if(frame->quant_inter_matrix) {
13610
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
741 mp_msg(MSGT_MENCODER, MSGL_INFO, "\nxvid: Loaded Inter matrix (switching to mpeg quantization type)\n");
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
742 if(xvidenc_quant_method) free(xvidenc_quant_method);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
743 xvidenc_quant_method = strdup("mpeg");
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
744 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
745 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
746 if(xvidenc_quant_method != NULL && !strcasecmp(xvidenc_quant_method, "mpeg")) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
747 frame->vol_flags |= XVID_VOL_MPEGQUANT;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
748 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
749 if(xvidenc_quarterpel) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
750 frame->vol_flags |= XVID_VOL_QUARTERPEL;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
751 frame->motion |= XVID_ME_QUARTERPELREFINE16;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
752 frame->motion |= XVID_ME_QUARTERPELREFINE8;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
753 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
754 if(xvidenc_gmc) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
755 frame->vol_flags |= XVID_VOL_GMC;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
756 frame->motion |= XVID_ME_GME_REFINE;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
757 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
758 if(xvidenc_interlaced) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
759 frame->vol_flags |= XVID_VOL_INTERLACING;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
760 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
761 if(xvidenc_trellis) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
762 frame->vop_flags |= XVID_VOP_TRELLISQUANT;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
763 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
764 if(xvidenc_hqacpred) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
765 frame->vop_flags |= XVID_VOP_HQACPRED;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
766 }
11912
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
767 if(xvidenc_chroma_opt) {
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
768 frame->vop_flags |= XVID_VOP_CHROMAOPT;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
769 }
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
770 if(xvidenc_motion > 4) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
771 frame->vop_flags |= XVID_VOP_INTER4V;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
772 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
773 if(xvidenc_chromame) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
774 frame->motion |= XVID_ME_CHROMA_PVOP;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
775 frame->motion |= XVID_ME_CHROMA_BVOP;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
776 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
777 if(xvidenc_vhq >= 1) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
778 frame->vop_flags |= XVID_VOP_MODEDECISION_RD;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
779 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
780 if(xvidenc_vhq >= 2) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
781 frame->motion |= XVID_ME_HALFPELREFINE16_RD;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
782 frame->motion |= XVID_ME_QUARTERPELREFINE16_RD;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
783 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
784 if(xvidenc_vhq >= 3) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
785 frame->motion |= XVID_ME_HALFPELREFINE8_RD;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
786 frame->motion |= XVID_ME_QUARTERPELREFINE8_RD;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
787 frame->motion |= XVID_ME_CHECKPREDICTION_RD;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
788 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
789 if(xvidenc_vhq >= 4) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
790 frame->motion |= XVID_ME_EXTSEARCH_RD;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
791 }
13610
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
792 if(xvidenc_bvhq >= 1) {
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
793 #if XVID_API >= XVID_MAKE_API(4,1)
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
794 frame->vop_flags |= XVID_VOP_RD_BVOP;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
795 #endif
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
796 }
11912
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
797 if(xvidenc_turbo) {
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
798 frame->motion |= XVID_ME_FASTREFINE16;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
799 frame->motion |= XVID_ME_FASTREFINE8;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
800 frame->motion |= XVID_ME_SKIP_DELTASEARCH;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
801 frame->motion |= XVID_ME_FAST_MODEINTERPOLATE;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
802 frame->motion |= XVID_ME_BFRAME_EARLYSTOP;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
803 }
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
804
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
805 /* motion level == 0 means no motion search which is equivalent to
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
806 * intra coding only */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
807 if(xvidenc_motion == 0) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
808 frame->type = XVID_TYPE_IVOP;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
809 } else {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
810 frame->type = XVID_TYPE_AUTO;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
811 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
812
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
813 frame->bframe_threshold = xvidenc_bframe_threshold;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
814
11912
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
815 /* PAR related initialization */
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
816 frame->par = XVID_PAR_11_VGA; /* Default */
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
817
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
818 if(xvidenc_dar_aspect > 0)
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
819 ar = xvid_d2q(xvidenc_dar_aspect * mod->mux->bih->biHeight / mod->mux->bih->biWidth, 255);
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
820 else if(xvidenc_autoaspect)
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
821 ar = xvid_d2q((float)mod->d_width / mod->d_height * mod->mux->bih->biHeight / mod->mux->bih->biWidth, 255);
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
822 else ar.num = ar.den = 0;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
823
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
824 if(ar.den != 0) {
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
825 if(ar.num == 12 && ar.den == 11)
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
826 frame->par = XVID_PAR_43_PAL;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
827 else if(ar.num == 10 && ar.den == 11)
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
828 frame->par = XVID_PAR_43_NTSC;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
829 else if(ar.num == 16 && ar.den == 11)
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
830 frame->par = XVID_PAR_169_PAL;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
831 else if(ar.num == 40 && ar.den == 33)
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
832 frame->par = XVID_PAR_169_NTSC;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
833 else
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
834 {
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
835 frame->par = XVID_PAR_EXT;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
836 frame->par_width = ar.num;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
837 frame->par_height= ar.den;
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
838 }
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
839
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
840 } else if(xvidenc_par != NULL) {
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
841 if(strcasecmp(xvidenc_par, "pal43") == 0)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
842 frame->par = XVID_PAR_43_PAL;
11912
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
843 else if(strcasecmp(xvidenc_par, "pal169") == 0)
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
844 frame->par = XVID_PAR_169_PAL;
11912
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
845 else if(strcasecmp(xvidenc_par, "ntsc43") == 0)
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
846 frame->par = XVID_PAR_43_NTSC;
11912
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
847 else if(strcasecmp(xvidenc_par, "ntsc169") == 0)
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
848 frame->par = XVID_PAR_169_NTSC;
11912
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
849 else if(strcasecmp(xvidenc_par, "ext") == 0)
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
850 frame->par = XVID_PAR_EXT;
11912
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
851
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
852 if(frame->par == XVID_PAR_EXT) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
853 if(xvidenc_par_width)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
854 frame->par_width = xvidenc_par_width;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
855 else
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
856 frame->par_width = 1;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
857
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
858 if(xvidenc_par_height)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
859 frame->par_height = xvidenc_par_height;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
860 else
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
861 frame->par_height = 1;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
862 }
11912
8eb96d751dcd new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents: 11586
diff changeset
863 }
13610
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
864
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
865 /* Display par information */
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
866 mp_msg(MSGT_MENCODER, MSGL_INFO, "xvid: par=%d/%d (%s), displayed=%dx%d, sampled=%dx%d\n",
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
867 ar.num, ar.den, par_string(frame->par),
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
868 mod->d_width, mod->d_height, mod->mux->bih->biWidth, mod->mux->bih->biHeight);
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
869 return;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
870 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
871
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
872 static int set_create_struct(xvid_mplayer_module_t *mod)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
873 {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
874 int pass;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
875 xvid_enc_create_t *create = &mod->create;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
876
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
877 /* Most of the structure is initialized by dispatch settings, only a
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
878 * few things are missing */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
879 create->version = XVID_VERSION;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
880
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
881 /* Width and Height */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
882 create->width = mod->mux->bih->biWidth;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
883 create->height = mod->mux->bih->biHeight;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
884
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
885 /* FPS */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
886 create->fincr = mod->mux->h.dwScale;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
887 create->fbase = mod->mux->h.dwRate;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
888
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
889 /* Encodings zones */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
890 memset(mod->zones, 0, sizeof(mod->zones));
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
891 create->zones = mod->zones;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
892 create->num_zones = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
893
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
894 /* Plugins */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
895 memset(mod->plugins, 0, sizeof(mod->plugins));
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
896 create->plugins = mod->plugins;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
897 create->num_plugins = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
898
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
899 /* -------------------------------------------------------------------
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
900 * Initialize and bind the right rate controller plugin
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
901 * ---------------------------------------------------------------- */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
902
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
903 /* First we try to sort out configuration conflicts */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
904 if(xvidenc_quantizer != 0 && (xvidenc_bitrate || xvidenc_pass)) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
905 mp_msg(MSGT_MENCODER, MSGL_ERR,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
906 "xvid: you can't mix Fixed Quantizer Rate Control"
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
907 " with other Rate Control mechanisms\n");
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
908 return(BAD);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
909 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
910
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
911 if(xvidenc_bitrate != 0 && xvidenc_pass == 1) {
13610
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
912 mp_msg(MSGT_MENCODER, MSGL_WARN,
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
913 "xvid: bitrate setting is ignored during first pass\n");
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
914 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
915
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
916 /* Sort out which sort of pass we are supposed to do
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
917 * pass == 1<<0 CBR
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
918 * pass == 1<<1 Two pass first pass
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
919 * pass == 1<<2 Two pass second pass
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
920 * pass == 1<<3 Constant quantizer
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
921 */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
922 #define MODE_CBR (1<<0)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
923 #define MODE_2PASS1 (1<<1)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
924 #define MODE_2PASS2 (1<<2)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
925 #define MODE_QUANT (1<<3)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
926
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
927 pass = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
928
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
929 if(xvidenc_bitrate != 0 && xvidenc_pass == 0)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
930 pass |= MODE_CBR;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
931
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
932 if(xvidenc_pass == 1)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
933 pass |= MODE_2PASS1;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
934
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
935 if(xvidenc_bitrate != 0 && xvidenc_pass == 2)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
936 pass |= MODE_2PASS2;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
937
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
938 if(xvidenc_quantizer != 0 && xvidenc_pass == 0)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
939 pass |= MODE_QUANT;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
940
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
941 /* We must be in at least one RC mode */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
942 if(pass == 0) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
943 mp_msg(MSGT_MENCODER, MSGL_ERR,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
944 "xvid: you must specify one or a valid combination of "
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
945 "'bitrate', 'pass', 'quantizer' settings\n");
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
946 return(BAD);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
947 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
948
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
949 /* Sanity checking */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
950 if(pass != MODE_CBR && pass != MODE_QUANT &&
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
951 pass != MODE_2PASS1 && pass != MODE_2PASS2) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
952 mp_msg(MSGT_MENCODER, MSGL_ERR,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
953 "xvid: this code should not be reached - fill a bug "
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
954 "report\n");
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
955 return(BAD);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
956 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
957
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
958 /* This is a single pass encoding: either a CBR pass or a constant
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
959 * quantizer pass */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
960 if(pass == MODE_CBR || pass == MODE_QUANT) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
961 xvid_plugin_single_t *onepass = &mod->onepass;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
962
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
963 /* There is not much left to initialize after dispatch settings */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
964 onepass->version = XVID_VERSION;
13675
d4cba4c4c54c Bitrate setting option in ve_xvid4.c doesn't follow the rules described
rathann
parents: 13610
diff changeset
965 if (xvidenc_bitrate > 16000) onepass->bitrate = xvidenc_bitrate;
d4cba4c4c54c Bitrate setting option in ve_xvid4.c doesn't follow the rules described
rathann
parents: 13610
diff changeset
966 else onepass->bitrate = xvidenc_bitrate*1000;
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
967
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
968 /* Quantizer mode uses the same plugin, we have only to define
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
969 * a constant quantizer zone beginning at frame 0 */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
970 if(pass == MODE_QUANT) {
11929
d870d266634e allow using of float fixed_quant
iive
parents: 11920
diff changeset
971 XVIDRational squant;
d870d266634e allow using of float fixed_quant
iive
parents: 11920
diff changeset
972 squant = xvid_d2q(xvidenc_quantizer,128);
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
973
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
974 create->zones[create->num_zones].mode = XVID_ZONE_QUANT;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
975 create->zones[create->num_zones].frame = 0;
12806
2a02e3dc8ba3 fix 10l fixed_quant bug reported by Michael
iive
parents: 12061
diff changeset
976 create->zones[create->num_zones].increment = squant.num;
2a02e3dc8ba3 fix 10l fixed_quant bug reported by Michael
iive
parents: 12061
diff changeset
977 create->zones[create->num_zones].base = squant.den;
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
978 create->num_zones++;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
979
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
980 mp_msg(MSGT_MENCODER, MSGL_INFO,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
981 "xvid: Fixed Quant Rate Control -- quantizer=%d/%d=%2.2f\n",
11929
d870d266634e allow using of float fixed_quant
iive
parents: 11920
diff changeset
982 squant.num,
d870d266634e allow using of float fixed_quant
iive
parents: 11920
diff changeset
983 squant.den,
d870d266634e allow using of float fixed_quant
iive
parents: 11920
diff changeset
984 (float)(squant.num)/(float)(squant.den));
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
985
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
986 } else {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
987 mp_msg(MSGT_MENCODER, MSGL_INFO,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
988 "xvid: CBR Rate Control -- bitrate=%dkbit/s\n",
13675
d4cba4c4c54c Bitrate setting option in ve_xvid4.c doesn't follow the rules described
rathann
parents: 13610
diff changeset
989 xvidenc_bitrate>16000?xvidenc_bitrate/1000:xvidenc_bitrate);
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
990 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
991
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
992 create->plugins[create->num_plugins].func = xvid_plugin_single;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
993 create->plugins[create->num_plugins].param = onepass;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
994 create->num_plugins++;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
995 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
996
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
997 /* This is the first pass of a Two pass process */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
998 if(pass == MODE_2PASS1) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
999 xvid_plugin_2pass1_t *pass1 = &mod->pass1;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1000
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1001 /* There is not much to initialize for this plugin */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1002 pass1->version = XVID_VERSION;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1003 pass1->filename = XVID_FIRST_PASS_FILENAME;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1004
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1005 create->plugins[create->num_plugins].func = xvid_plugin_2pass1;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1006 create->plugins[create->num_plugins].param = pass1;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1007 create->num_plugins++;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1008
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1009 mp_msg(MSGT_MENCODER, MSGL_INFO,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1010 "xvid: 2Pass Rate Control -- 1st pass\n");
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1011 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1012
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1013 /* This is the second pass of a Two pass process */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1014 if(pass == MODE_2PASS2) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1015 xvid_plugin_2pass2_t *pass2 = &mod->pass2;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1016
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1017 /* There is not much left to initialize after dispatch settings */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1018 pass2->version = XVID_VERSION;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1019 pass2->filename = XVID_FIRST_PASS_FILENAME;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1020
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1021 /* Positive bitrate values are bitrates as usual but if the
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1022 * value is negative it is considered as being a total size
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1023 * to reach (in kilobytes) */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1024 if(xvidenc_bitrate > 0) {
13675
d4cba4c4c54c Bitrate setting option in ve_xvid4.c doesn't follow the rules described
rathann
parents: 13610
diff changeset
1025 if(xvidenc_bitrate > 16000) pass2->bitrate = xvidenc_bitrate;
d4cba4c4c54c Bitrate setting option in ve_xvid4.c doesn't follow the rules described
rathann
parents: 13610
diff changeset
1026 else pass2->bitrate = xvidenc_bitrate*1000;
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1027 mp_msg(MSGT_MENCODER, MSGL_INFO,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1028 "xvid: 2Pass Rate Control -- 2nd pass -- bitrate=%dkbit/s\n",
13675
d4cba4c4c54c Bitrate setting option in ve_xvid4.c doesn't follow the rules described
rathann
parents: 13610
diff changeset
1029 xvidenc_bitrate>16000?xvidenc_bitrate/1000:xvidenc_bitrate);
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1030 } else {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1031 pass2->bitrate = xvidenc_bitrate;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1032 mp_msg(MSGT_MENCODER, MSGL_INFO,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1033 "xvid: 2Pass Rate Control -- 2nd pass -- total size=%dkB\n",
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1034 -xvidenc_bitrate);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1035 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1036
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1037 create->plugins[create->num_plugins].func = xvid_plugin_2pass2;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1038 create->plugins[create->num_plugins].param = pass2;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1039 create->num_plugins++;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1040 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1041
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1042 return(FINE);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1043 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1044
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1045 static int set_frame_struct(xvid_mplayer_module_t *mod, mp_image_t *mpi)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1046 {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1047 xvid_enc_frame_t *frame = &mod->frame;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1048
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1049 /* Most of the initialization is done during dispatch_settings */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1050 frame->version = XVID_VERSION;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1051
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1052 /* Bind output buffer */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1053 frame->bitstream = mod->mux->buffer;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1054 frame->length = -1;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1055
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1056 /* Frame format */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1057 switch(mpi->imgfmt) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1058 case IMGFMT_YV12:
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1059 case IMGFMT_IYUV:
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1060 case IMGFMT_I420:
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1061 frame->input.csp = XVID_CSP_USER;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1062 break;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1063 case IMGFMT_YUY2:
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1064 frame->input.csp = XVID_CSP_YUY2;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1065 break;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1066 case IMGFMT_UYVY:
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1067 frame->input.csp = XVID_CSP_UYVY;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1068 break;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1069 default:
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1070 mp_msg(MSGT_MENCODER, MSGL_ERR,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1071 "xvid: unsupported picture format (%s)!\n",
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1072 vo_format_name(mpi->imgfmt));
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1073 return(BAD);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1074 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1075
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1076 /* Bind source frame */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1077 frame->input.plane[0] = mpi->planes[0];
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1078 frame->input.plane[1] = mpi->planes[1];
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1079 frame->input.plane[2] = mpi->planes[2];
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1080 frame->input.stride[0] = mpi->stride[0];
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1081 frame->input.stride[1] = mpi->stride[1];
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1082 frame->input.stride[2] = mpi->stride[2];
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1083
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1084 /* Force the right quantizer -- It is internally managed by RC
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1085 * plugins */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1086 frame->quant = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1087
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1088 return(FINE);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1089 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1090
13610
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1091 static void
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1092 flush_internal_buffers(xvid_mplayer_module_t *mod)
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1093 {
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1094 int size;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1095 xvid_enc_frame_t *frame = &mod->frame;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1096
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1097 if (mod->instance == NULL)
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1098 return;/*encoder not inited*/
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1099
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1100 /* Init a fake frame to force flushing */
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1101 frame->version = XVID_VERSION;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1102 frame->bitstream = mod->mux->buffer;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1103 frame->length = -1;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1104 frame->input.csp = XVID_CSP_NULL;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1105 frame->input.plane[0] = NULL;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1106 frame->input.plane[1] = NULL;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1107 frame->input.plane[2] = NULL;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1108 frame->input.stride[0] = 0;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1109 frame->input.stride[1] = 0;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1110 frame->input.stride[2] = 0;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1111 frame->quant = 0;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1112
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1113 /* Flush encoder buffers caused by bframes usage */
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1114 do {
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1115 xvid_enc_stats_t stats;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1116 memset(&stats, 0, sizeof(xvid_enc_stats_t));
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1117 stats.version = XVID_VERSION;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1118
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1119 /* Encode internal buffer */
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1120 size = xvid_encore(mod->instance, XVID_ENC_ENCODE, &mod->frame, &stats);
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1121
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1122 if (size>0) {
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1123 /* Update stats */
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1124 update_stats(mod, &stats);
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1125
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1126 /* xvidcore outputed bitstream -- mux it */
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1127 muxer_write_chunk(mod->mux, size,
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1128 (mod->frame.out_flags & XVID_KEYFRAME)?0x10:0);
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1129 }
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1130 } while (size>0);
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1131 }
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1132
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1133 #define SSE2PSNR(sse, nbpixels) \
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1134 ((!(sse)) ? 99.99f : 48.131f - 10*(double)log10((double)(sse)/(double)((nbpixels))))
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1135 static void
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1136 update_stats(xvid_mplayer_module_t *mod, xvid_enc_stats_t *stats)
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1137 {
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1138 if(xvidenc_stats && stats->type > 0) {
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1139 mod->sse_y += stats->sse_y;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1140 mod->sse_u += stats->sse_u;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1141 mod->sse_v += stats->sse_v;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1142
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1143 if(mod->min_sse_y > stats->sse_y) {
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1144 mod->min_sse_y = stats->sse_y;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1145 mod->min_sse_u = stats->sse_u;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1146 mod->min_sse_v = stats->sse_v;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1147 mod->min_framenum = mod->frames;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1148 }
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1149
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1150 if(mod->max_sse_y < stats->sse_y) {
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1151 mod->max_sse_y = stats->sse_y;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1152 mod->max_sse_u = stats->sse_u;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1153 mod->max_sse_v = stats->sse_v;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1154 mod->max_framenum = mod->frames;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1155 }
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1156
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1157 if (xvidenc_psnr) {
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1158 if (!mod->fvstats) {
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1159 char filename[20];
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1160 time_t today2;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1161 struct tm *today;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1162 today2 = time (NULL);
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1163 today = localtime (&today2);
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1164 sprintf (filename, "psnr_%02d%02d%02d.log", today->tm_hour, today->tm_min, today->tm_sec);
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1165 mod->fvstats = fopen (filename,"w");
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1166 if (!mod->fvstats) {
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1167 perror ("fopen");
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1168 /* Disable PSNR file output so we don't get here again */
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1169 xvidenc_psnr = 0;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1170 }
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1171 }
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1172 fprintf (mod->fvstats, "%6d, %2d, %6d, %2.2f, %2.2f, %2.2f, %2.2f %c\n",
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1173 mod->frames,
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1174 stats->quant,
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1175 stats->length,
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1176 SSE2PSNR (stats->sse_y, mod->pixels),
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1177 SSE2PSNR (stats->sse_u, mod->pixels / 4),
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1178 SSE2PSNR (stats->sse_v, mod->pixels / 4),
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1179 SSE2PSNR (stats->sse_y + stats->sse_u + stats->sse_v,(double)mod->pixels * 1.5),
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1180 stats->type==1?'I':stats->type==2?'P':stats->type==3?'B':stats->type?'S':'?'
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1181 );
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1182 }
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1183 mod->frames++;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1184 }
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1185 }
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1186
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1187 static void
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1188 print_stats(xvid_mplayer_module_t *mod)
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1189 {
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1190 if (mod->frames) {
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1191 mod->sse_y /= mod->frames;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1192 mod->sse_u /= mod->frames;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1193 mod->sse_v /= mod->frames;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1194
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1195 mp_msg(MSGT_MENCODER, MSGL_INFO,
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1196 "The value 99.99dB is a special value and represents "
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1197 "the upper range limit\n");
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1198 mp_msg(MSGT_MENCODER, MSGL_INFO,
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1199 "xvid: Min PSNR y : %.2f dB, u : %.2f dB, v : %.2f dB, in frame %d\n",
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1200 SSE2PSNR(mod->max_sse_y, mod->pixels),
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1201 SSE2PSNR(mod->max_sse_u, mod->pixels/4),
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1202 SSE2PSNR(mod->max_sse_v, mod->pixels/4),
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1203 mod->max_framenum);
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1204 mp_msg(MSGT_MENCODER, MSGL_INFO,
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1205 "xvid: Average PSNR y : %.2f dB, u : %.2f dB, v : %.2f dB, for %d frames\n",
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1206 SSE2PSNR(mod->sse_y, mod->pixels),
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1207 SSE2PSNR(mod->sse_u, mod->pixels/4),
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1208 SSE2PSNR(mod->sse_v, mod->pixels/4),
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1209 mod->frames);
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1210 mp_msg(MSGT_MENCODER, MSGL_INFO,
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1211 "xvid: Max PSNR y : %.2f dB, u : %.2f dB, v : %.2f dB, in frame %d\n",
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1212 SSE2PSNR(mod->min_sse_y, mod->pixels),
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1213 SSE2PSNR(mod->min_sse_u, mod->pixels/4),
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1214 SSE2PSNR(mod->min_sse_v, mod->pixels/4),
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1215 mod->min_framenum);
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1216 }
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1217 }
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1218 #undef SSE2PSNR
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1219
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1220 static void *read_matrix(unsigned char *filename)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1221 {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1222 int i;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1223 unsigned char *matrix;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1224 FILE *input;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1225
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1226 /* Allocate matrix space */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1227 if((matrix = malloc(64*sizeof(unsigned char))) == NULL)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1228 return(NULL);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1229
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1230 /* Open the matrix file */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1231 if((input = fopen(filename, "rb")) == NULL) {
13610
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1232 mp_msg(MSGT_MENCODER, MSGL_ERR,
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1233 "xvid: Error opening the matrix file %s\n",
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1234 filename);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1235 free(matrix);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1236 return(NULL);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1237 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1238
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1239 /* Read the matrix */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1240 for(i=0; i<64; i++) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1241
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1242 int value;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1243
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1244 /* If fscanf fails then get out of the loop */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1245 if(fscanf(input, "%d", &value) != 1) {
13610
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1246 mp_msg(MSGT_MENCODER, MSGL_ERR,
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1247 "xvid: Error reading the matrix file %s\n",
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1248 filename);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1249 free(matrix);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1250 fclose(input);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1251 return(NULL);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1252 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1253
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1254 /* Clamp the value to safe range */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1255 value = (value< 1)?1 :value;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1256 value = (value>255)?255:value;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1257 matrix[i] = value;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1258 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1259
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1260 /* Fills the rest with 1 */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1261 while(i<64) matrix[i++] = 1;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1262
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1263 /* We're done */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1264 fclose(input);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1265
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1266 return(matrix);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1267
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1268 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1269
13610
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1270
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1271 static const char *
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1272 par_string(int parcode)
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1273 {
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1274 const char *par_string;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1275 switch (parcode) {
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1276 case XVID_PAR_11_VGA:
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1277 par_string = "vga11";
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1278 break;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1279 case XVID_PAR_43_PAL:
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1280 par_string = "pal43";
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1281 break;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1282 case XVID_PAR_43_NTSC:
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1283 par_string = "ntsc43";
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1284 break;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1285 case XVID_PAR_169_PAL:
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1286 par_string = "pal169";
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1287 break;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1288 case XVID_PAR_169_NTSC:
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1289 par_string = "ntsc69";
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1290 break;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1291 case XVID_PAR_EXT:
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1292 par_string = "ext";
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1293 break;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1294 default:
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1295 par_string = "unknown";
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1296 break;
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1297 }
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1298 return (par_string);
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1299 }
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1300
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1301 static const char *errorstring(int err)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1302 {
13610
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1303 const char *error;
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1304 switch(err) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1305 case XVID_ERR_FAIL:
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1306 error = "General fault";
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1307 break;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1308 case XVID_ERR_MEMORY:
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1309 error = "Memory allocation error";
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1310 break;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1311 case XVID_ERR_FORMAT:
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1312 error = "File format error";
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1313 break;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1314 case XVID_ERR_VERSION:
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1315 error = "Structure version not supported";
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1316 break;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1317 case XVID_ERR_END:
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1318 error = "End of stream reached";
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1319 break;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1320 default:
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1321 error = "Unknown";
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1322 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1323
13610
b79ee5bf2c9e Sync with GomGom's patch-12 version.
iive
parents: 12806
diff changeset
1324 return(error);
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1325 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1326
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1327 /*****************************************************************************
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1328 * Module structure definition
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1329 ****************************************************************************/
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1330
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1331 vf_info_t ve_info_xvid = {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1332 "XviD 1.0 encoder",
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1333 "xvid",
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1334 "Marco Belli <elcabesa@inwind.it>, Edouard Gomez <ed.gomez@free.fr>",
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1335 "No comment",
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1336 vf_open
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1337 };
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1338
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1339
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1340 #endif /* HAVE_XVID4 */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1341
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1342 /* Please do not change that tag comment.
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1343 * arch-tag: 42ccc257-0548-4a3e-9617-2876c4e8ac88 mplayer xvid encoder module */