8 #if !defined(INFINITY) && defined(HUGE_VAL)
9 #define INFINITY HUGE_VAL
17 #include "codec-cfg.h"
24 #include "img_format.h"
34 #ifdef XVID_API_UNSTABLE
35 #warning *******************************************************************
37 #warning ** Y O U '' R E U S I N G U N S T A B L E S O F T W A R E **
39 #warning ** Streams produced by this version aren''t probably compatible **
40 #warning ** with anything else, even the xvid decoder itself. There are **
41 #warning ** bugs, this code could crash, could blow up your PC or the **
42 #warning ** whole building ! **
43 #warning ** If you want stable code and compatible streams, use stable **
44 #warning ** XViD releases (currently 0.9.x). **
46 #warning *******************************************************************
49 /**********************************************************************/
50 /* motion estimation quality presets */
51 static int const motion_presets
[7] = {
52 #ifdef XVID_API_UNSTABLE
57 PMV_HALFPELREFINE16
| PMV_HALFPELDIAMOND8
,
58 PMV_HALFPELREFINE16
| PMV_HALFPELDIAMOND8
| PMV_ADVANCEDDIAMOND16
,
59 PMV_HALFPELREFINE16
| PMV_EXTSEARCH16
| PMV_HALFPELREFINE8
| PMV_HALFPELDIAMOND8
| PMV_USESQUARES16
64 PMV_EARLYSTOP16
| PMV_EARLYSTOP8
,
65 PMV_EARLYSTOP16
| PMV_HALFPELREFINE16
| PMV_EARLYSTOP8
| PMV_HALFPELDIAMOND8
,
66 PMV_EARLYSTOP16
| PMV_HALFPELREFINE16
| PMV_EARLYSTOP8
| PMV_HALFPELDIAMOND8
| PMV_ADVANCEDDIAMOND16
,
67 PMV_EARLYSTOP16
| PMV_HALFPELREFINE16
| PMV_EXTSEARCH16
| PMV_EARLYSTOP8
| PMV_HALFPELREFINE8
|
68 PMV_HALFPELDIAMOND8
| PMV_USESQUARES16
73 extern char* passtmpfile
;
75 static int xvidenc_pass
= 0;
76 static int xvidenc_quality
= 6;
77 static int xvidenc_4mv
= 0;
78 static int xvidenc_bitrate
= -1;
79 static int xvidenc_rc_reaction_delay_factor
= -1;
80 static int xvidenc_rc_averaging_period
= -1;
81 static int xvidenc_rc_buffer
= -1;
82 static char* xvidenc_quant_range
= "2-31/2-31";
83 static int xvidenc_min_key_interval
= -1;
84 static int xvidenc_max_key_interval
= -1;
85 static int xvidenc_mpeg_quant
= 0;
86 static int xvidenc_mod_quant
= 0;
87 static int xvidenc_keyframe_boost
= -1;
88 static int xvidenc_kfthreshold
= -1;
89 static int xvidenc_kfreduction
= -1;
90 static int xvidenc_fixed_quant
= 0;
91 static int xvidenc_debug
= 0;
92 static int xvidenc_interlacing
= 0;
93 static int xvidenc_greyscale
= 0;
94 #ifdef XVID_API_UNSTABLE
95 static int xvidenc_packed
= 0;
96 static int xvidenc_divx5bvop
= 1;
97 static int xvidenc_lumi_mask
= 0;
98 static int xvidenc_qpel
= 0;
99 static int xvidenc_max_bframes
= 0;
100 static int xvidenc_bquant_ratio
= 150;
101 static int xvidenc_bquant_offset
= 100;
102 static int xvidenc_bf_threshold
= 0;
103 static int xvidenc_gmc
= 0;
104 static int xvidenc_chroma_me
= 0;
105 static int xvidenc_chroma_opt
= 0;
106 static int xvidenc_reduced
= 0;
107 static int xvidenc_hqac
= 0;
108 static int xvidenc_vhq
= 0;
109 static int xvidenc_psnr
= 0;
110 static uint64_t xvid_error
[3];
113 m_option_t xvidencopts_conf
[] = {
114 { "pass", &xvidenc_pass
, CONF_TYPE_INT
, CONF_RANGE
, 0, 2, NULL
},
115 { "me_quality", &xvidenc_quality
, CONF_TYPE_INT
, CONF_RANGE
, 0,
116 sizeof(motion_presets
) / sizeof(motion_presets
[0]) - 1, NULL
},
117 { "4mv", &xvidenc_4mv
, CONF_TYPE_FLAG
, 0, 0, 1, NULL
},
118 { "bitrate", &xvidenc_bitrate
, CONF_TYPE_INT
, CONF_RANGE
, 4, 24000000, NULL
},
119 { "rc_reaction_delay_factor", &xvidenc_rc_reaction_delay_factor
, CONF_TYPE_INT
, 0, 0, 0, NULL
},
120 { "rc_averaging_period", &xvidenc_rc_averaging_period
, CONF_TYPE_INT
, 0, 0, 0, NULL
},
121 { "rc_buffer", &xvidenc_rc_buffer
, CONF_TYPE_INT
, 0, 0, 0, NULL
},
122 { "quant_range", &xvidenc_quant_range
, CONF_TYPE_STRING
, 0, 0, 0, NULL
},
123 { "min_key_interval", &xvidenc_min_key_interval
, CONF_TYPE_INT
, 0, 0, 0, NULL
}, /* for XVID_MODE_2PASS_2 */
124 { "max_key_interval", &xvidenc_max_key_interval
, CONF_TYPE_INT
, 0, 0, 0, NULL
},
125 { "mpeg_quant", &xvidenc_mpeg_quant
, CONF_TYPE_FLAG
, 0, 0, 1, NULL
},
126 { "mod_quant", &xvidenc_mod_quant
, CONF_TYPE_FLAG
, 0, 0, 1, NULL
},
127 { "keyframe_boost", &xvidenc_keyframe_boost
, CONF_TYPE_INT
, CONF_RANGE
, 0, 1000, NULL
}, /* for XVID_MODE_2PASS_2 */
128 { "kfthreshold", &xvidenc_kfthreshold
, CONF_TYPE_INT
, 0, 0, 0, NULL
}, /* for XVID_MODE_2PASS_2 */
129 { "kfreduction", &xvidenc_kfreduction
, CONF_TYPE_INT
, CONF_RANGE
, 0, 100, NULL
}, /* for XVID_MODE_2PASS_2 */
130 { "fixed_quant", &xvidenc_fixed_quant
, CONF_TYPE_INT
, CONF_RANGE
, 1, 31, NULL
}, /* for XVID_MODE_FIXED_QUANT */
131 { "debug", &xvidenc_debug
, CONF_TYPE_FLAG
, 0, 0, 1, NULL
},
132 { "interlacing", &xvidenc_interlacing
, CONF_TYPE_FLAG
, 0, 0, 1, NULL
},
133 { "greyscale", &xvidenc_greyscale
, CONF_TYPE_FLAG
, 0, 0, 1, NULL
},
134 #ifdef XVID_API_UNSTABLE
135 { "packed", &xvidenc_packed
, CONF_TYPE_FLAG
, 0, 0, 1, NULL
},
136 { "divx5bvop", &xvidenc_divx5bvop
, CONF_TYPE_FLAG
, 0, 0, 1, NULL
},
137 //{ "lumi_mask", &xvidenc_lumi_mask, CONF_TYPE_FLAG, 0, 0, 1, NULL},
138 { "psnr", &xvidenc_psnr
, CONF_TYPE_FLAG
, 0, 0, 1, NULL
},
139 { "qpel", &xvidenc_qpel
, CONF_TYPE_FLAG
, 0, 0, 1, NULL
},
140 { "max_bframes", &xvidenc_max_bframes
, CONF_TYPE_INT
, CONF_RANGE
, 0, 4, NULL
},
141 { "bquant_ratio", &xvidenc_bquant_ratio
, CONF_TYPE_INT
, CONF_RANGE
, 0, 1000, NULL
},
142 { "bquant_offset", &xvidenc_bquant_offset
, CONF_TYPE_INT
, CONF_RANGE
, -1000, 1000, NULL
},
143 { "bf_threshold", &xvidenc_bf_threshold
, CONF_TYPE_INT
, CONF_RANGE
, -255, 255, NULL
},
144 { "reduced", &xvidenc_reduced
, CONF_TYPE_FLAG
, 0, 0, 1, NULL
},
145 { "gmc", &xvidenc_gmc
, CONF_TYPE_FLAG
, 0, 0, 1, NULL
},
146 { "chroma_me", &xvidenc_chroma_me
, CONF_TYPE_FLAG
, 0, 0, 1, NULL
},
147 { "hq_ac", &xvidenc_hqac
, CONF_TYPE_FLAG
, 0, 0, 1, NULL
},
148 { "vhq", &xvidenc_vhq
, CONF_TYPE_INT
, CONF_RANGE
, 0, 4, NULL
},
149 { "chroma_opt", &xvidenc_chroma_opt
, CONF_TYPE_FLAG
, 0, 0, 1, NULL
},
151 { NULL
, NULL
, 0, 0, 0, 0, NULL
}
156 XVID_ENC_FRAME enc_frame
;
158 vbr_control_t vbr_state
;
164 config(struct vf_instance_s
* vf
,
165 int width
, int height
, int d_width
, int d_height
,
166 unsigned int flags
, unsigned int outfmt
)
168 XVID_ENC_PARAM enc_param
;
169 struct vf_priv_s
*fp
= vf
->priv
;
170 unsigned int min_iq
, max_iq
, min_pq
, max_pq
;
172 fp
->mux
->bih
->biWidth
= width
;
173 fp
->mux
->bih
->biHeight
= height
;
174 fp
->mux
->bih
->biSizeImage
= fp
->mux
->bih
->biWidth
* fp
->mux
->bih
->biHeight
* 3;
175 fp
->mux
->aspect
= (float)d_width
/d_height
;
176 mp_msg(MSGT_MENCODER
,MSGL_INFO
,"videocodec: XViD (%dx%d fourcc=%x [%.4s])\n",
177 width
, height
, fp
->mux
->bih
->biCompression
, (char *)&fp
->mux
->bih
->biCompression
);
179 // {min,max}_{i,p}quantizer parsing & validation
180 if (sscanf (xvidenc_quant_range
, "%u-%u/%u-%u", &min_iq
, &max_iq
, &min_pq
, &max_pq
) < 4) {
181 mp_msg (MSGT_MENCODER
, MSGL_ERR
,
182 "xvid: ERROR: cannot parse \"quant_range=%s\"\n", xvidenc_quant_range
);
185 if (min_iq
< 1 || min_iq
> 31 || max_iq
< 1 || max_iq
> 31 || min_iq
> max_iq
||
186 min_pq
< 1 || min_pq
> 31 || max_pq
< 1 || max_pq
> 31 || min_pq
> max_pq
) {
187 mp_msg (MSGT_MENCODER
, MSGL_ERR
,
188 "xvid: ERROR: {min,max} {I,P} quantizer must be in [1,31] and min must be <= max.\n");
189 mp_msg (MSGT_MENCODER
, MSGL_ERR
,
190 "xvid: ERROR: cannot use \"quant_range=%s\"\n", xvidenc_quant_range
);
194 #ifdef XVID_API_UNSTABLE
195 mp_msg (MSGT_MENCODER
, MSGL_WARN
,
197 "*******************************************************************\n"
199 "** Y O U ' R E U S I N G U N S T A B L E S O F T W A R E **\n"
201 "** Streams produced by this version aren't probably compatible **\n"
202 "** with anything else, even the xvid decoder itself. There are **\n"
203 "** bugs, this code could crash, could blow up your PC or the **\n"
204 "** whole building ! **\n"
205 "** If you want stable code and compatible streams, use stable **\n"
206 "** XViD releases (currently 0.9.x). **\n"
208 "*******************************************************************\n"
212 // initialize XViD core parameters
213 // ===============================
214 memset(&enc_param
, 0, sizeof(enc_param
));
215 enc_param
.width
= width
;
216 enc_param
.height
= height
;
217 enc_param
.fincr
= fp
->mux
->h
.dwScale
;
218 enc_param
.fbase
= fp
->mux
->h
.dwRate
;
219 if (xvidenc_bitrate
> 16000)
220 enc_param
.rc_bitrate
= xvidenc_bitrate
;
221 else if (xvidenc_bitrate
> 0)
222 enc_param
.rc_bitrate
= xvidenc_bitrate
* 1000;
224 enc_param
.rc_bitrate
= -1;
225 #ifdef XVID_API_UNSTABLE
226 if (xvidenc_max_bframes
>= 1 && xvidenc_pass
>= 1) {
227 mp_msg(MSGT_MENCODER
,MSGL_WARN
, "xvid: cannot use bframes with 2-pass, disabling bframes\n");
228 xvidenc_max_bframes
= 0;
230 enc_param
.max_bframes
= xvidenc_max_bframes
;
231 enc_param
.bquant_ratio
= xvidenc_bquant_ratio
;
232 enc_param
.bquant_offset
= xvidenc_bquant_offset
;
233 if (xvidenc_divx5bvop
)
234 enc_param
.global
|= XVID_GLOBAL_DX50BVOP
;
236 enc_param
.global
|= XVID_GLOBAL_PACKED
;
238 enc_param
.global
|= XVID_GLOBAL_REDUCED
;
240 enc_param
.global
|= XVID_GLOBAL_EXTRASTATS
;
241 fp
->pixels
= width
* height
;
243 xvid_error
[0] = xvid_error
[1] = xvid_error
[2] = 0;
245 if (xvidenc_greyscale
)
246 enc_param
.global
|= XVID_GREYSCALE
;
248 enc_param
.rc_reaction_delay_factor
= xvidenc_rc_reaction_delay_factor
;
249 enc_param
.rc_averaging_period
= xvidenc_rc_averaging_period
;
250 enc_param
.rc_buffer
= xvidenc_rc_buffer
;
251 enc_param
.min_quantizer
= min_iq
;
252 enc_param
.max_quantizer
= max_iq
;
253 if( xvidenc_max_key_interval
<= 0 )
254 xvidenc_max_key_interval
= 10 * enc_param
.fbase
/ enc_param
.fincr
;
255 enc_param
.max_key_interval
= xvidenc_max_key_interval
;
256 switch (xvid_encore(NULL
, XVID_ENC_CREATE
, &enc_param
, NULL
)) {
258 mp_msg(MSGT_MENCODER
,MSGL_ERR
, "xvid: encoder creation failed\n");
260 case XVID_ERR_MEMORY
:
261 mp_msg(MSGT_MENCODER
,MSGL_ERR
, "xvid: encoder creation failed, out of memory\n");
263 case XVID_ERR_FORMAT
:
264 mp_msg(MSGT_MENCODER
,MSGL_ERR
, "xvid: encoder creation failed, bad format\n");
267 fp
->enc_handle
= enc_param
.handle
;
269 // initialize XViD per-frame static parameters
270 // ===========================================
271 fp
->enc_frame
.motion
= motion_presets
[xvidenc_quality
];
272 fp
->enc_frame
.general
= XVID_HALFPEL
| (xvidenc_mpeg_quant
? XVID_MPEGQUANT
: XVID_H263QUANT
);
274 fp
->enc_frame
.general
|= XVID_INTER4V
;
275 if (xvidenc_interlacing
)
276 fp
->enc_frame
.general
|= XVID_INTERLACING
;
277 #ifdef XVID_API_UNSTABLE
278 fp
->enc_frame
.bframe_threshold
= xvidenc_bf_threshold
;
279 if (xvidenc_lumi_mask
)
280 fp
->enc_frame
.general
|= XVID_LUMIMASKING
;
282 fp
->enc_frame
.general
|= XVID_QUARTERPEL
;
283 fp
->enc_frame
.motion
|= PMV_QUARTERPELREFINE16
| PMV_QUARTERPELREFINE8
;
285 switch (xvidenc_vhq
) {
286 case 4: // wide search
287 fp
->enc_frame
.motion
|= EXTSEARCH_BITS
| PMV_EXTSEARCH8
;
288 case 3: // medium search
289 fp
->enc_frame
.motion
|= HALFPELREFINE8_BITS
| QUARTERPELREFINE8_BITS
| CHECKPREDICTION_BITS
;
290 case 2: // limited search
291 fp
->enc_frame
.motion
|= HALFPELREFINE16_BITS
| QUARTERPELREFINE16_BITS
;
292 case 1: // mode decision
293 fp
->enc_frame
.general
|= XVID_MODEDECISION_BITS
;
299 fp
->enc_frame
.general
|= XVID_GMC
;
301 fp
->enc_frame
.general
|= XVID_EXTRASTATS
;
302 if (xvidenc_chroma_me
)
303 fp
->enc_frame
.motion
|= PMV_CHROMA16
| PMV_CHROMA8
;
305 fp
->enc_frame
.general
|= XVID_REDUCED
;
307 fp
->enc_frame
.general
|= XVID_HQACPRED
;
308 if (xvidenc_chroma_opt
)
309 fp
->enc_frame
.general
|= XVID_CHROMAOPT
;
311 if (xvidenc_greyscale
)
312 fp
->enc_frame
.general
|= XVID_GREYSCALE
;
317 fp
->enc_frame
.colorspace
= XVID_CSP_YV12
;
319 case IMGFMT_IYUV
: case IMGFMT_I420
:
320 fp
->enc_frame
.colorspace
= XVID_CSP_I420
;
323 fp
->enc_frame
.colorspace
= XVID_CSP_YUY2
;
326 fp
->enc_frame
.colorspace
= XVID_CSP_UYVY
;
328 case IMGFMT_RGB24
: case IMGFMT_BGR24
:
329 fp
->enc_frame
.colorspace
= XVID_CSP_RGB24
;
332 mp_msg(MSGT_MENCODER
,MSGL_ERR
,"xvid: unsupported picture format (%s)!\n",
333 vo_format_name(outfmt
));
336 fp
->enc_frame
.quant_intra_matrix
= 0;
337 fp
->enc_frame
.quant_inter_matrix
= 0;
339 // initialize VBR engine
340 // =====================
341 vbrSetDefaults(&fp
->vbr_state
);
342 if (xvidenc_min_key_interval
< 0)
343 xvidenc_min_key_interval
= fp
->vbr_state
.min_key_interval
;
346 if (xvidenc_pass
== 0) {
347 if (xvidenc_fixed_quant
>= 1) {
348 fp
->vbr_state
.mode
= VBR_MODE_FIXED_QUANT
;
349 fp
->vbr_state
.fixed_quant
= xvidenc_fixed_quant
;
351 fp
->vbr_state
.mode
= VBR_MODE_1PASS
;
353 else if (xvidenc_pass
== 1)
354 fp
->vbr_state
.mode
= VBR_MODE_2PASS_1
;
355 else if (xvidenc_pass
== 2)
356 fp
->vbr_state
.mode
= VBR_MODE_2PASS_2
;
361 fp
->vbr_state
.fps
= (double)enc_param
.fbase
/ enc_param
.fincr
;
362 fp
->vbr_state
.filename
= passtmpfile
;
363 fp
->vbr_state
.desired_bitrate
= enc_param
.rc_bitrate
;
364 fp
->vbr_state
.min_iquant
= min_iq
;
365 fp
->vbr_state
.max_iquant
= max_iq
;
366 fp
->vbr_state
.min_pquant
= min_pq
;
367 fp
->vbr_state
.max_pquant
= max_pq
;
368 if (xvidenc_keyframe_boost
>= 0)
369 fp
->vbr_state
.keyframe_boost
= xvidenc_keyframe_boost
;
370 if (xvidenc_kfthreshold
>= 0)
371 fp
->vbr_state
.kftreshold
= xvidenc_kfthreshold
;
372 if (xvidenc_kfreduction
>= 0)
373 fp
->vbr_state
.kfreduction
= xvidenc_kfreduction
;
374 if (xvidenc_min_key_interval
>= 0)
375 fp
->vbr_state
.min_key_interval
= xvidenc_min_key_interval
;
376 fp
->vbr_state
.max_key_interval
= enc_param
.max_key_interval
;
377 fp
->vbr_state
.debug
= xvidenc_debug
;
379 vbrInit(&fp
->vbr_state
);
381 #ifdef XVID_API_UNSTABLE
382 fp
->mux
->decoder_delay
= enc_param
.max_bframes
? 1 : 0;
388 #ifdef XVID_API_UNSTABLE
390 sse_to_PSNR(double sse
, double pixels
)
392 return sse
== 0 ? INFINITY
: 4.34294481903251827652 * (11.08252709031685229249 - log(sse
/pixels
));
393 // 4.34294481903251827652 = 10/log(10)
394 // 11.08252709031685229249 = log(255*255)
399 uninit(struct vf_instance_s
* vf
)
401 struct vf_priv_s
*fp
= vf
->priv
;
403 #ifdef XVID_API_UNSTABLE
405 double p
= (double)fp
->pixels
* (double)fp
->nb_frames
;
406 printf ("PSNR: Y:%2.2f, Cb:%2.2f, Cr:%2.2f, All:%2.2f\n",
407 sse_to_PSNR(xvid_error
[0], p
),
408 sse_to_PSNR(xvid_error
[1], p
/4),
409 sse_to_PSNR(xvid_error
[2], p
/4),
410 sse_to_PSNR(xvid_error
[0] + xvid_error
[1] + xvid_error
[2], p
*1.5));
413 vbrFinish(&fp
->vbr_state
);
417 control(struct vf_instance_s
* vf
, int request
, void* data
)
419 return CONTROL_UNKNOWN
;
423 query_format(struct vf_instance_s
* vf
, unsigned int fmt
)
426 case IMGFMT_YV12
: case IMGFMT_IYUV
: case IMGFMT_I420
:
427 return VFCAP_CSP_SUPPORTED
| VFCAP_CSP_SUPPORTED_BY_HW
;
428 case IMGFMT_YUY2
: case IMGFMT_UYVY
:
429 return VFCAP_CSP_SUPPORTED
;
430 case IMGFMT_RGB24
: case IMGFMT_BGR24
:
431 return VFCAP_CSP_SUPPORTED
| VFCAP_FLIPPED
;
437 put_image(struct vf_instance_s
* vf
, mp_image_t
*mpi
, double pts
)
439 XVID_ENC_STATS enc_stats
;
440 struct vf_priv_s
*fp
= vf
->priv
;
442 fp
->enc_frame
.bitstream
= fp
->mux
->buffer
;
443 fp
->enc_frame
.length
= -1 /* fp->mux->buffer_size */;
444 fp
->enc_frame
.image
= mpi
->planes
[0];
445 #ifdef XVID_API_UNSTABLE
446 fp
->enc_frame
.stride
= mpi
->stride
[0];
449 // get quantizers & I/P decision from the VBR engine
450 #ifdef XVID_API_UNSTABLE
451 if (xvidenc_max_bframes
>= 1) {
452 if (xvidenc_fixed_quant
!=0) {
453 // hack, the internal VBR engine isn't fixed-quant aware
454 fp
->enc_frame
.quant
= xvidenc_fixed_quant
;
455 fp
->enc_frame
.intra
= -1;
456 fp
->enc_frame
.bquant
= (xvidenc_fixed_quant
* xvidenc_bquant_ratio
+ xvidenc_bquant_offset
) / 100;
458 // use the internal VBR engine since the external one isn't bframe aware
459 fp
->enc_frame
.quant
=0;
460 fp
->enc_frame
.intra
=-1;
461 fp
->enc_frame
.bquant
= 0;
463 fp
->enc_frame
.quant
= vbrGetQuant(&fp
->vbr_state
);
464 fp
->enc_frame
.intra
= vbrGetIntra(&fp
->vbr_state
);
467 fp
->enc_frame
.quant
= vbrGetQuant(&fp
->vbr_state
);
468 fp
->enc_frame
.intra
= vbrGetIntra(&fp
->vbr_state
);
471 // modulated quantizer type
472 if (xvidenc_mod_quant
&& xvidenc_pass
== 2) {
473 fp
->enc_frame
.general
|= (fp
->enc_frame
.quant
< 4) ? XVID_MPEGQUANT
: XVID_H263QUANT
;
474 fp
->enc_frame
.general
&= (fp
->enc_frame
.quant
< 4) ? ~XVID_H263QUANT
: ~XVID_MPEGQUANT
;
478 switch (xvid_encore(fp
->enc_handle
, XVID_ENC_ENCODE
, &fp
->enc_frame
, &enc_stats
)) {
481 case XVID_ERR_MEMORY
:
482 mp_msg(MSGT_MENCODER
, MSGL_ERR
, "xvid: out of memory\n");
484 case XVID_ERR_FORMAT
:
485 mp_msg(MSGT_MENCODER
, MSGL_ERR
, "xvid: bad format\n");
488 mp_msg(MSGT_MENCODER
, MSGL_ERR
, "xvid: failure\n");
492 #ifdef XVID_API_UNSTABLE
494 static FILE *fvstats
= NULL
;
500 today2
= time (NULL
);
501 today
= localtime (&today2
);
502 sprintf (filename
, "psnr_%02d%02d%02d.log", today
->tm_hour
, today
->tm_min
, today
->tm_sec
);
503 fvstats
= fopen (filename
,"w");
506 xvidenc_psnr
= 0; // disable block
510 xvid_error
[0] += enc_stats
.sse_y
;
511 xvid_error
[1] += enc_stats
.sse_u
;
512 xvid_error
[2] += enc_stats
.sse_v
;
514 fprintf (fvstats
, "%6d, %2d, %6d, %2.2f, %2.2f, %2.2f, %2.2f %c\n",
517 fp
->enc_frame
.length
,
518 sse_to_PSNR (enc_stats
.sse_y
, fp
->pixels
),
519 sse_to_PSNR (enc_stats
.sse_u
, fp
->pixels
/ 4),
520 sse_to_PSNR (enc_stats
.sse_v
, fp
->pixels
/ 4),
521 sse_to_PSNR (enc_stats
.sse_y
+ enc_stats
.sse_u
+ enc_stats
.sse_v
, (double)fp
->pixels
* 1.5),
522 fp
->enc_frame
.intra
== 0 ? 'P' : fp
->enc_frame
.intra
== 1 ? 'I' : 'B'
530 if (fp
->enc_frame
.length
> 0)
531 muxer_write_chunk(fp
->mux
, fp
->enc_frame
.length
, fp
->enc_frame
.intra
==1 ? 0x10 : 0, MP_NOPTS_VALUE
, MP_NOPTS_VALUE
);
533 ++fp
->mux
->encoder_delay
;
535 // update the VBR engine
536 vbrUpdate(&fp
->vbr_state
, enc_stats
.quant
, fp
->enc_frame
.intra
,
537 enc_stats
.hlength
, fp
->enc_frame
.length
, enc_stats
.kblks
, enc_stats
.mblks
, enc_stats
.ublks
);
542 //===========================================================================//
545 vf_open(vf_instance_t
*vf
, char* args
)
547 XVID_INIT_PARAM params
= { 0, 0, 0};
549 vf
->default_caps
= VFCAP_CONSTANT
;
550 vf
->control
= control
;
552 vf
->query_format
= query_format
;
553 vf
->put_image
= put_image
;
554 vf
->priv
= malloc(sizeof(struct vf_priv_s
));
555 memset(vf
->priv
, 0, sizeof(struct vf_priv_s
));
556 vf
->priv
->mux
= (muxer_stream_t
*)args
;
558 vf
->priv
->mux
->bih
= calloc(1, sizeof(BITMAPINFOHEADER
));
559 vf
->priv
->mux
->bih
->biSize
= sizeof(BITMAPINFOHEADER
);
560 vf
->priv
->mux
->bih
->biWidth
= 0;
561 vf
->priv
->mux
->bih
->biHeight
= 0;
562 vf
->priv
->mux
->bih
->biPlanes
= 1;
563 vf
->priv
->mux
->bih
->biBitCount
= 24;
564 vf
->priv
->mux
->bih
->biCompression
= mmioFOURCC('X','V','I','D');
566 if (xvid_init(NULL
, 0, ¶ms
, NULL
) != XVID_ERR_OK
) {
567 mp_msg(MSGT_MENCODER
,MSGL_ERR
, "xvid: initialisation failure\n");
570 if (params
.api_version
!= API_VERSION
) {
571 mp_msg(MSGT_MENCODER
,MSGL_ERR
, "xvid: XviD library API version mismatch\n"
572 "\texpected %d.%d, got %d.%d, you should recompile MPlayer.\n",
573 API_VERSION
>> 16, API_VERSION
& 0xff,
574 params
.api_version
>> 16, params
.api_version
& 0xff);
581 vf_info_t ve_info_xvid
= {
584 "Kim Minh Kaplan & RĂ©mi Guyomarch",
585 "for internal use by mencoder",
589 //===========================================================================//