Mercurial > mplayer.hg
annotate libmpcodecs/ve_xvid.c @ 8330:9abfeca26c20
HTML fixes
author | diego |
---|---|
date | Mon, 02 Dec 2002 17:28:03 +0000 |
parents | 91edcb091dc6 |
children | 800d77666843 |
rev | line source |
---|---|
7456 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <string.h> | |
8078 | 4 #include <errno.h> |
7456 | 5 |
6 #include "../config.h" | |
7 #include "../mp_msg.h" | |
8 | |
9 #ifdef HAVE_XVID | |
10 | |
11 #include "codec-cfg.h" | |
12 #include "stream.h" | |
13 #include "demuxer.h" | |
14 #include "stheader.h" | |
15 | |
16 #include "aviwrite.h" | |
17 | |
18 #include "img_format.h" | |
19 #include "mp_image.h" | |
20 #include "vf.h" | |
21 | |
22 #include <xvid.h> | |
23 #include "xvid_vbr.h" | |
24 | |
25 #include "cfgparser.h" | |
26 | |
27 /**********************************************************************/ | |
28 /* Divx4 quality to XviD encoder motion flag presets */ | |
29 static int const divx4_motion_presets[7] = { | |
8078 | 30 0, |
31 PMV_QUICKSTOP16, | |
7456 | 32 PMV_EARLYSTOP16, |
8078 | 33 PMV_EARLYSTOP16 | PMV_EARLYSTOP8, |
34 PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 | PMV_HALFPELDIAMOND8, | |
35 PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 | PMV_HALFPELDIAMOND8 | PMV_ADVANCEDDIAMOND16, | |
36 PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 | PMV_EARLYSTOP8 | PMV_HALFPELREFINE8 | | |
37 PMV_HALFPELDIAMOND8 | PMV_USESQUARES16 | |
38 | |
7456 | 39 }; |
40 | |
41 /* Divx4 quality to general encoder flag presets */ | |
42 static int const divx4_general_presets[7] = { | |
43 0, | |
44 XVID_H263QUANT, | |
45 XVID_H263QUANT, | |
46 XVID_H263QUANT | XVID_HALFPEL, | |
47 XVID_H263QUANT | XVID_INTER4V | XVID_HALFPEL, | |
48 XVID_H263QUANT | XVID_INTER4V | XVID_HALFPEL, | |
49 XVID_H263QUANT | XVID_INTER4V | XVID_HALFPEL | |
50 }; | |
51 | |
8078 | 52 extern char* passtmpfile; |
8123
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
8078
diff
changeset
|
53 extern void mencoder_write_chunk(aviwrite_stream_t *s,int len,unsigned int flags); |
7456 | 54 |
8078 | 55 static int xvidenc_pass = 0; |
56 static int xvidenc_quality = sizeof(divx4_motion_presets) / sizeof(divx4_motion_presets[0]) - 1; /* best quality */ | |
57 static int xvidenc_bitrate = -1; | |
58 static int xvidenc_rc_reaction_delay_factor = -1; | |
59 static int xvidenc_rc_averaging_period = -1; | |
60 static int xvidenc_rc_buffer = -1; | |
8247
91edcb091dc6
Instead of min_quantizer, max_quantizer, min_iquantizer, etc... use a
rguyom
parents:
8221
diff
changeset
|
61 static char* xvidenc_quant_range = "2-31/2-31"; |
8221 | 62 static int xvidenc_min_key_interval = -1; |
8078 | 63 static int xvidenc_max_key_interval = -1; |
64 static int xvidenc_mpeg_quant = 0; | |
8192 | 65 static int xvidenc_mod_quant = 0; |
8078 | 66 static int xvidenc_lumi_mask = 0; |
8221 | 67 static int xvidenc_keyframe_boost = -1; |
8192 | 68 static int xvidenc_kfthreshold = -1; |
69 static int xvidenc_kfreduction = -1; | |
8078 | 70 static int xvidenc_fixed_quant = 0; |
71 static int xvidenc_debug = 0; | |
72 static int xvidenc_hintedme = 0; | |
73 static char* xvidenc_hintfile = "xvid_hint_me.dat"; | |
7458 | 74 |
7456 | 75 struct config xvidencopts_conf[] = { |
8078 | 76 { "pass", &xvidenc_pass, CONF_TYPE_INT, CONF_RANGE, 0, 2, NULL}, |
77 { "quality", &xvidenc_quality, CONF_TYPE_INT, CONF_RANGE, 0, | |
7456 | 78 sizeof(divx4_motion_presets) / sizeof(divx4_motion_presets[0]) - 1, NULL}, |
8078 | 79 { "br", &xvidenc_bitrate, CONF_TYPE_INT, CONF_RANGE, 4, 24000000, NULL}, |
80 { "rc_reaction_delay_factor", &xvidenc_rc_reaction_delay_factor, CONF_TYPE_INT, 0, 0, 0, NULL}, | |
81 { "rc_averaging_period", &xvidenc_rc_averaging_period, CONF_TYPE_INT, 0, 0, 0, NULL}, | |
82 { "rc_buffer", &xvidenc_rc_buffer, CONF_TYPE_INT, 0, 0, 0, NULL}, | |
8247
91edcb091dc6
Instead of min_quantizer, max_quantizer, min_iquantizer, etc... use a
rguyom
parents:
8221
diff
changeset
|
83 { "quant_range", &xvidenc_quant_range, CONF_TYPE_STRING, 0, 0, 0, NULL}, |
8078 | 84 { "min_key_interval", &xvidenc_min_key_interval, CONF_TYPE_INT, 0, 0, 0, NULL}, /* for XVID_MODE_2PASS_2 */ |
85 { "max_key_interval", &xvidenc_max_key_interval, CONF_TYPE_INT, 0, 0, 0, NULL}, | |
86 { "mpeg_quant", &xvidenc_mpeg_quant, CONF_TYPE_FLAG, 0, 0, 1, NULL}, | |
8192 | 87 { "mod_quant", &xvidenc_mod_quant, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
8078 | 88 { "lumi_mask", &xvidenc_lumi_mask, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
8193 | 89 { "keyframe_boost", &xvidenc_keyframe_boost, CONF_TYPE_INT, CONF_RANGE, 0, 1000, NULL}, /* for XVID_MODE_2PASS_2 */ |
8078 | 90 { "kfthreshold", &xvidenc_kfthreshold, CONF_TYPE_INT, 0, 0, 0, NULL}, /* for XVID_MODE_2PASS_2 */ |
8192 | 91 { "kfreduction", &xvidenc_kfreduction, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL}, /* for XVID_MODE_2PASS_2 */ |
8078 | 92 { "fixed_quant", &xvidenc_fixed_quant, CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL}, /* for XVID_MODE_FIXED_QUANT */ |
93 { "debug", &xvidenc_debug, CONF_TYPE_FLAG, 0, 0, 1, NULL}, | |
94 { "hintedme", &xvidenc_hintedme, CONF_TYPE_FLAG, 0, 0, 1, NULL}, | |
95 { "hintfile", &xvidenc_hintfile, CONF_TYPE_STRING, 0, 0, 0, NULL}, | |
7456 | 96 { NULL, NULL, 0, 0, 0, 0, NULL} |
97 }; | |
98 | |
99 struct vf_priv_s { | |
100 aviwrite_stream_t* mux; | |
101 XVID_ENC_FRAME enc_frame; | |
102 void* enc_handle; | |
103 vbr_control_t vbr_state; | |
104 FILE *hintfile; | |
8078 | 105 void *hintstream; |
7456 | 106 }; |
107 | |
108 static int | |
109 config(struct vf_instance_s* vf, | |
110 int width, int height, int d_width, int d_height, | |
111 unsigned int flags, unsigned int outfmt) | |
112 { | |
113 XVID_ENC_PARAM enc_param; | |
8078 | 114 struct vf_priv_s *fp = vf->priv; |
8247
91edcb091dc6
Instead of min_quantizer, max_quantizer, min_iquantizer, etc... use a
rguyom
parents:
8221
diff
changeset
|
115 unsigned int min_iq, max_iq, min_pq, max_pq; |
7456 | 116 |
8078 | 117 fp->mux->bih->biWidth = width; |
118 fp->mux->bih->biHeight = height; | |
119 fp->mux->bih->biSizeImage = fp->mux->bih->biWidth * fp->mux->bih->biHeight * 3; | |
120 mp_msg(MSGT_MENCODER,MSGL_INFO,"videocodec: XViD (%dx%d fourcc=%x [%.4s])\n", | |
121 width, height, fp->mux->bih->biCompression, (char *)&fp->mux->bih->biCompression); | |
7456 | 122 |
8247
91edcb091dc6
Instead of min_quantizer, max_quantizer, min_iquantizer, etc... use a
rguyom
parents:
8221
diff
changeset
|
123 // {min,max}_{i,p}quantizer parsing & validation |
91edcb091dc6
Instead of min_quantizer, max_quantizer, min_iquantizer, etc... use a
rguyom
parents:
8221
diff
changeset
|
124 if (sscanf (xvidenc_quant_range, "%u-%u/%u-%u", &min_iq, &max_iq, &min_pq, &max_pq) < 4) { |
91edcb091dc6
Instead of min_quantizer, max_quantizer, min_iquantizer, etc... use a
rguyom
parents:
8221
diff
changeset
|
125 mp_msg (MSGT_MENCODER, MSGL_ERR, |
91edcb091dc6
Instead of min_quantizer, max_quantizer, min_iquantizer, etc... use a
rguyom
parents:
8221
diff
changeset
|
126 "xvid: ERROR: cannot parse \"quant_range=%s\"\n", xvidenc_quant_range); |
91edcb091dc6
Instead of min_quantizer, max_quantizer, min_iquantizer, etc... use a
rguyom
parents:
8221
diff
changeset
|
127 return 0; |
91edcb091dc6
Instead of min_quantizer, max_quantizer, min_iquantizer, etc... use a
rguyom
parents:
8221
diff
changeset
|
128 } |
91edcb091dc6
Instead of min_quantizer, max_quantizer, min_iquantizer, etc... use a
rguyom
parents:
8221
diff
changeset
|
129 if (min_iq < 1 || min_iq > 31 || max_iq < 1 || max_iq > 31 || min_iq > max_iq || |
91edcb091dc6
Instead of min_quantizer, max_quantizer, min_iquantizer, etc... use a
rguyom
parents:
8221
diff
changeset
|
130 min_pq < 1 || min_pq > 31 || max_pq < 1 || max_pq > 31 || min_pq > max_pq) { |
91edcb091dc6
Instead of min_quantizer, max_quantizer, min_iquantizer, etc... use a
rguyom
parents:
8221
diff
changeset
|
131 mp_msg (MSGT_MENCODER, MSGL_ERR, |
91edcb091dc6
Instead of min_quantizer, max_quantizer, min_iquantizer, etc... use a
rguyom
parents:
8221
diff
changeset
|
132 "xvid: ERROR: {min,max} {I,P} quantizer must be in [1,31] and min must be <= max.\n"); |
91edcb091dc6
Instead of min_quantizer, max_quantizer, min_iquantizer, etc... use a
rguyom
parents:
8221
diff
changeset
|
133 mp_msg (MSGT_MENCODER, MSGL_ERR, |
91edcb091dc6
Instead of min_quantizer, max_quantizer, min_iquantizer, etc... use a
rguyom
parents:
8221
diff
changeset
|
134 "xvid: ERROR: cannot use \"quant_range=%s\"\n", xvidenc_quant_range); |
91edcb091dc6
Instead of min_quantizer, max_quantizer, min_iquantizer, etc... use a
rguyom
parents:
8221
diff
changeset
|
135 return -1; |
91edcb091dc6
Instead of min_quantizer, max_quantizer, min_iquantizer, etc... use a
rguyom
parents:
8221
diff
changeset
|
136 } |
91edcb091dc6
Instead of min_quantizer, max_quantizer, min_iquantizer, etc... use a
rguyom
parents:
8221
diff
changeset
|
137 |
8078 | 138 // initialize XViD core parameters |
139 // =============================== | |
7456 | 140 memset(&enc_param, 0, sizeof(enc_param)); |
141 enc_param.width = width; | |
142 enc_param.height = height; | |
8078 | 143 enc_param.fincr = fp->mux->h.dwScale; |
144 enc_param.fbase = fp->mux->h.dwRate; | |
145 if (xvidenc_bitrate > 16000) | |
146 enc_param.rc_bitrate = xvidenc_bitrate; | |
147 else if (xvidenc_bitrate > 0) | |
148 enc_param.rc_bitrate = xvidenc_bitrate * 1000; | |
149 else | |
150 enc_param.rc_bitrate = -1; | |
151 enc_param.rc_reaction_delay_factor = xvidenc_rc_reaction_delay_factor; | |
152 enc_param.rc_averaging_period = xvidenc_rc_averaging_period; | |
153 enc_param.rc_buffer = xvidenc_rc_buffer; | |
8247
91edcb091dc6
Instead of min_quantizer, max_quantizer, min_iquantizer, etc... use a
rguyom
parents:
8221
diff
changeset
|
154 enc_param.min_quantizer = min_iq; |
91edcb091dc6
Instead of min_quantizer, max_quantizer, min_iquantizer, etc... use a
rguyom
parents:
8221
diff
changeset
|
155 enc_param.max_quantizer = max_iq; |
8221 | 156 if( xvidenc_max_key_interval <= 0 ) |
157 xvidenc_max_key_interval = 10 * enc_param.fbase / enc_param.fincr; | |
158 enc_param.max_key_interval = xvidenc_max_key_interval; | |
7456 | 159 switch (xvid_encore(NULL, XVID_ENC_CREATE, &enc_param, NULL)) { |
160 case XVID_ERR_FAIL: | |
8078 | 161 mp_msg(MSGT_MENCODER,MSGL_ERR, "xvid: encoder creation failed\n"); |
7456 | 162 return 0; |
163 case XVID_ERR_MEMORY: | |
8078 | 164 mp_msg(MSGT_MENCODER,MSGL_ERR, "xvid: encoder creation failed, out of memory\n"); |
7456 | 165 return 0; |
166 case XVID_ERR_FORMAT: | |
8078 | 167 mp_msg(MSGT_MENCODER,MSGL_ERR, "xvid: encoder creation failed, bad format\n"); |
7456 | 168 return 0; |
169 } | |
8078 | 170 fp->enc_handle = enc_param.handle; |
7456 | 171 |
8078 | 172 // initialize XViD per-frame static parameters |
173 // =========================================== | |
174 fp->enc_frame.general = divx4_general_presets[xvidenc_quality]; | |
175 fp->enc_frame.motion = divx4_motion_presets[xvidenc_quality]; | |
176 if (xvidenc_mpeg_quant) { | |
177 fp->enc_frame.general &= ~XVID_H263QUANT; | |
178 fp->enc_frame.general |= XVID_MPEGQUANT; | |
179 } | |
180 if (xvidenc_lumi_mask) | |
181 fp->enc_frame.general |= XVID_LUMIMASKING; | |
182 | |
7456 | 183 switch (outfmt) { |
184 case IMGFMT_YV12: | |
8078 | 185 fp->enc_frame.colorspace = XVID_CSP_YV12; |
7456 | 186 break; |
187 case IMGFMT_IYUV: case IMGFMT_I420: | |
8078 | 188 fp->enc_frame.colorspace = XVID_CSP_I420; |
7456 | 189 break; |
190 case IMGFMT_YUY2: | |
8078 | 191 fp->enc_frame.colorspace = XVID_CSP_YUY2; |
7456 | 192 break; |
193 case IMGFMT_UYVY: | |
8078 | 194 fp->enc_frame.colorspace = XVID_CSP_UYVY; |
7456 | 195 break; |
196 case IMGFMT_RGB24: case IMGFMT_BGR24: | |
8078 | 197 fp->enc_frame.colorspace = XVID_CSP_RGB24; |
7456 | 198 break; |
199 default: | |
200 mp_msg(MSGT_MENCODER,MSGL_ERR,"xvid: unsupported picture format (%s)!\n", | |
201 vo_format_name(outfmt)); | |
202 return 0; | |
203 } | |
8078 | 204 fp->enc_frame.quant_intra_matrix = 0; |
205 fp->enc_frame.quant_inter_matrix = 0; | |
206 | |
207 // hinted ME | |
208 fp->hintstream = NULL; | |
209 fp->hintfile = NULL; | |
210 if (xvidenc_hintedme && (xvidenc_pass == 1 || xvidenc_pass == 2)) { | |
211 fp->hintstream = malloc( 100000 ); // this is what the vfw code in XViD CVS allocates | |
212 if (fp->hintstream == NULL) | |
213 mp_msg(MSGT_MENCODER,MSGL_ERR, "xvid: cannot allocate memory for hinted ME\n"); | |
214 else { | |
215 fp->hintfile = fopen(xvidenc_hintfile, xvidenc_pass == 1 ? "w" : "r"); | |
216 if (fp->hintfile == NULL) { | |
217 mp_msg(MSGT_MENCODER,MSGL_ERR, "xvid: %s: %s\n", strerror(errno), xvidenc_hintfile); | |
218 free(fp->hintstream); | |
219 } | |
220 } | |
221 if (fp->hintstream == NULL || fp->hintfile == NULL) | |
222 xvidenc_hintedme = 0; | |
223 } | |
7456 | 224 |
8078 | 225 // initialize VBR engine |
226 // ===================== | |
227 vbrSetDefaults(&fp->vbr_state); | |
8221 | 228 if (xvidenc_min_key_interval < 0) |
229 xvidenc_min_key_interval = fp->vbr_state.min_key_interval; | |
230 | |
231 // pass | |
8078 | 232 if (xvidenc_pass == 0) { |
233 if (xvidenc_fixed_quant >= 1) { | |
234 fp->vbr_state.mode = VBR_MODE_FIXED_QUANT; | |
235 fp->vbr_state.fixed_quant = xvidenc_fixed_quant; | |
236 } else | |
237 fp->vbr_state.mode = VBR_MODE_1PASS; | |
7456 | 238 } |
8078 | 239 else if (xvidenc_pass == 1) |
240 fp->vbr_state.mode = VBR_MODE_2PASS_1; | |
241 else if (xvidenc_pass == 2) | |
242 fp->vbr_state.mode = VBR_MODE_2PASS_2; | |
243 else | |
244 return -1; | |
8221 | 245 |
246 // misc | |
8078 | 247 fp->vbr_state.fps = (double)enc_param.fbase / enc_param.fincr; |
248 fp->vbr_state.filename = passtmpfile; | |
249 fp->vbr_state.desired_bitrate = enc_param.rc_bitrate; | |
8247
91edcb091dc6
Instead of min_quantizer, max_quantizer, min_iquantizer, etc... use a
rguyom
parents:
8221
diff
changeset
|
250 fp->vbr_state.min_iquant = min_iq; |
91edcb091dc6
Instead of min_quantizer, max_quantizer, min_iquantizer, etc... use a
rguyom
parents:
8221
diff
changeset
|
251 fp->vbr_state.max_iquant = max_iq; |
91edcb091dc6
Instead of min_quantizer, max_quantizer, min_iquantizer, etc... use a
rguyom
parents:
8221
diff
changeset
|
252 fp->vbr_state.min_pquant = min_pq; |
91edcb091dc6
Instead of min_quantizer, max_quantizer, min_iquantizer, etc... use a
rguyom
parents:
8221
diff
changeset
|
253 fp->vbr_state.max_pquant = max_pq; |
8221 | 254 if (xvidenc_keyframe_boost >= 0) |
8078 | 255 fp->vbr_state.keyframe_boost = xvidenc_keyframe_boost; |
8192 | 256 if (xvidenc_kfthreshold >= 0) |
8078 | 257 fp->vbr_state.kftreshold = xvidenc_kfthreshold; |
8192 | 258 if (xvidenc_kfreduction >= 0) |
8078 | 259 fp->vbr_state.kfreduction = xvidenc_kfreduction; |
8221 | 260 if (xvidenc_min_key_interval >= 0) |
8078 | 261 fp->vbr_state.min_key_interval = xvidenc_min_key_interval; |
262 fp->vbr_state.max_key_interval = enc_param.max_key_interval; | |
263 fp->vbr_state.debug = xvidenc_debug; | |
8221 | 264 |
8078 | 265 vbrInit(&fp->vbr_state); |
266 | |
7456 | 267 return 1; |
268 } | |
269 | |
270 static void | |
271 uninit(struct vf_instance_s* vf) | |
272 { | |
8078 | 273 struct vf_priv_s *fp = vf->priv; |
274 | |
275 if (fp->hintfile) | |
276 fclose(fp->hintfile); | |
277 if (fp->hintstream) | |
278 free(fp->hintstream); | |
279 vbrFinish(&fp->vbr_state); | |
7456 | 280 } |
281 | |
282 static int | |
283 control(struct vf_instance_s* vf, int request, void* data) | |
284 { | |
285 return CONTROL_UNKNOWN; | |
286 } | |
287 | |
288 static int | |
289 query_format(struct vf_instance_s* vf, unsigned int fmt) | |
290 { | |
291 switch(fmt){ | |
292 case IMGFMT_YV12: case IMGFMT_IYUV: case IMGFMT_I420: | |
293 return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW; | |
294 case IMGFMT_YUY2: case IMGFMT_UYVY: | |
295 return VFCAP_CSP_SUPPORTED; | |
296 case IMGFMT_RGB24: case IMGFMT_BGR24: | |
297 return VFCAP_CSP_SUPPORTED | VFCAP_FLIPPED; | |
298 } | |
299 return 0; | |
300 } | |
301 | |
302 static int | |
303 put_image(struct vf_instance_s* vf, mp_image_t *mpi) | |
304 { | |
305 XVID_ENC_STATS enc_stats; | |
8078 | 306 struct vf_priv_s *fp = vf->priv; |
7456 | 307 |
8078 | 308 fp->enc_frame.bitstream = fp->mux->buffer; |
309 fp->enc_frame.length = -1 /* fp->mux->buffer_size */; | |
310 fp->enc_frame.image = mpi->planes[0]; | |
8192 | 311 |
312 // get quantizers & I/P decision from the VBR engine | |
8078 | 313 fp->enc_frame.quant = vbrGetQuant(&fp->vbr_state); |
314 fp->enc_frame.intra = vbrGetIntra(&fp->vbr_state); | |
8192 | 315 |
316 // modulated quantizer type | |
317 if (xvidenc_mod_quant && xvidenc_pass == 2) { | |
318 fp->enc_frame.general |= (fp->enc_frame.quant < 4) ? XVID_MPEGQUANT : XVID_H263QUANT; | |
319 fp->enc_frame.general &= (fp->enc_frame.quant < 4) ? ~XVID_H263QUANT : ~XVID_MPEGQUANT; | |
320 } | |
321 | |
322 // hinted ME, 1st part | |
8078 | 323 if (xvidenc_hintedme && xvidenc_pass == 1) { |
324 fp->enc_frame.hint.hintstream = fp->hintstream; | |
325 fp->enc_frame.hint.rawhints = 0; | |
326 fp->enc_frame.general |= XVID_HINTEDME_GET; | |
7456 | 327 } |
8078 | 328 else if (xvidenc_hintedme && xvidenc_pass == 2) { |
329 size_t read; | |
330 int blocksize; | |
331 fp->enc_frame.general &= ~XVID_HINTEDME_SET; | |
332 read = fread(&blocksize, sizeof(blocksize), 1, fp->hintfile); | |
333 if (read == 1) { | |
334 read = fread(fp->hintstream, (size_t)blocksize, 1, fp->hintfile); | |
7456 | 335 if (read == 1) { |
8078 | 336 fp->enc_frame.hint.hintstream = fp->hintstream; |
337 fp->enc_frame.hint.hintlength = 0; | |
338 fp->enc_frame.hint.rawhints = 0; | |
339 fp->enc_frame.general |= XVID_HINTEDME_SET; | |
340 } | |
7456 | 341 else |
8078 | 342 perror("xvid: hint file read block failure"); |
343 } | |
344 else | |
345 perror("xvid: hint file read failure"); | |
7456 | 346 } |
8192 | 347 |
348 // encode frame | |
8078 | 349 switch (xvid_encore(fp->enc_handle, XVID_ENC_ENCODE, &fp->enc_frame, &enc_stats)) { |
7456 | 350 case XVID_ERR_OK: |
351 break; | |
352 case XVID_ERR_MEMORY: | |
353 mp_msg(MSGT_MENCODER, MSGL_ERR, "xvid: out of memory\n"); | |
354 break; | |
355 case XVID_ERR_FORMAT: | |
356 mp_msg(MSGT_MENCODER, MSGL_ERR, "xvid: bad format\n"); | |
357 break; | |
358 default: | |
359 mp_msg(MSGT_MENCODER, MSGL_ERR, "xvid: failure\n"); | |
360 break; | |
361 } | |
8192 | 362 |
363 // write output | |
8078 | 364 mencoder_write_chunk(fp->mux, fp->enc_frame.length, fp->enc_frame.intra ? 0x10 : 0); |
8192 | 365 |
366 // update the VBR engine | |
8078 | 367 vbrUpdate(&fp->vbr_state, enc_stats.quant, fp->enc_frame.intra, |
368 enc_stats.hlength, fp->enc_frame.length, enc_stats.kblks, enc_stats.mblks, enc_stats.ublks); | |
8192 | 369 |
370 // hinted ME, 2nd part | |
8078 | 371 if (fp->enc_frame.general & XVID_HINTEDME_GET) { |
372 size_t wrote = fwrite(&fp->enc_frame.hint.hintlength, sizeof(fp->enc_frame.hint.hintlength), 1, fp->hintfile); | |
373 if (wrote == 1) { | |
374 wrote = fwrite(fp->enc_frame.hint.hintstream, fp->enc_frame.hint.hintlength, 1, fp->hintfile); | |
375 if (wrote != 1) | |
376 perror("xvid: hint write block failure"); | |
7456 | 377 } |
8078 | 378 else |
379 perror("xvid: hint write failure"); | |
7456 | 380 } |
381 return 1; | |
382 } | |
383 | |
384 //===========================================================================// | |
385 | |
386 static int | |
387 vf_open(vf_instance_t *vf, char* args) | |
388 { | |
389 XVID_INIT_PARAM params = { 0, 0, 0}; | |
390 vf->config = config; | |
391 vf->control = control; | |
392 vf->uninit = uninit; | |
393 vf->query_format = query_format; | |
394 vf->put_image = put_image; | |
395 vf->priv = malloc(sizeof(struct vf_priv_s)); | |
396 memset(vf->priv, 0, sizeof(struct vf_priv_s)); | |
397 vf->priv->mux = (aviwrite_stream_t*)args; | |
398 | |
399 vf->priv->mux->bih = malloc(sizeof(BITMAPINFOHEADER)); | |
400 vf->priv->mux->bih->biSize = sizeof(BITMAPINFOHEADER); | |
401 vf->priv->mux->bih->biWidth = 0; | |
402 vf->priv->mux->bih->biHeight = 0; | |
403 vf->priv->mux->bih->biPlanes = 1; | |
404 vf->priv->mux->bih->biBitCount = 24; | |
405 vf->priv->mux->bih->biCompression = mmioFOURCC('X','V','I','D'); | |
406 | |
407 if (xvid_init(NULL, 0, ¶ms, NULL) != XVID_ERR_OK) { | |
8078 | 408 mp_msg(MSGT_MENCODER,MSGL_ERR, "xvid: initialisation failure\n"); |
7456 | 409 abort(); |
410 } | |
411 if (params.api_version != API_VERSION) { | |
8078 | 412 mp_msg(MSGT_MENCODER,MSGL_ERR, "xvid: XviD library API version mismatch\n" |
7456 | 413 "\texpected %d.%d, got %d.%d, you should recompile MPlayer.\n", |
414 API_VERSION >> 16, API_VERSION & 0xff, | |
415 params.api_version >> 16, params.api_version & 0xff); | |
416 abort(); | |
417 } | |
418 | |
419 return 1; | |
420 } | |
421 | |
422 vf_info_t ve_info_xvid = { | |
423 "XviD encoder", | |
424 "xvid", | |
8078 | 425 "Kim Minh Kaplan & Rémi Guyomarch", |
7456 | 426 "for internal use by mencoder", |
427 vf_open | |
428 }; | |
429 | |
430 //===========================================================================// | |
431 #endif |