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