annotate libmpcodecs/ve_xvid.c @ 8330:9abfeca26c20

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