Mercurial > mplayer.hg
annotate libmpcodecs/ve_xvid.c @ 20441:634b7aa76477
Improve translation of autogenerated labels
author | torinthiel |
---|---|
date | Thu, 26 Oct 2006 09:14:39 +0000 |
parents | a1807995e2ab |
children |
rev | line source |
---|---|
7456 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <string.h> | |
8078 | 4 #include <errno.h> |
9809
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
5 #include <math.h> |
9817
796e9b8bf2e3
- added <time.h> since we're using time() related functions
rguyom
parents:
9809
diff
changeset
|
6 #include <time.h> |
9809
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
7 |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
8 #if !defined(INFINITY) && defined(HUGE_VAL) |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
9 #define INFINITY HUGE_VAL |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
10 #endif |
7456 | 11 |
17012 | 12 #include "config.h" |
13 #include "mp_msg.h" | |
7456 | 14 |
15 #include "codec-cfg.h" | |
16 #include "stream.h" | |
17 #include "demuxer.h" | |
18 #include "stheader.h" | |
19 | |
8585 | 20 #include "muxer.h" |
7456 | 21 |
22 #include "img_format.h" | |
23 #include "mp_image.h" | |
24 #include "vf.h" | |
25 | |
26 #include <xvid.h> | |
27 #include "xvid_vbr.h" | |
28 | |
10594
57bdcdb061d7
Removed the historic cfgparser and switched full to the new config parser (altought some macros still remain for compatibility). As a side effect 90% of the warning messages are gone from the core. Things should be cleaner now and less confusing for newbies.
alex
parents:
9843
diff
changeset
|
29 #include "m_option.h" |
8491
ce25d80dd6c3
Use the XVID_API_UNSTABLE macro instead of a home-made one.
rguyom
parents:
8462
diff
changeset
|
30 |
ce25d80dd6c3
Use the XVID_API_UNSTABLE macro instead of a home-made one.
rguyom
parents:
8462
diff
changeset
|
31 |
ce25d80dd6c3
Use the XVID_API_UNSTABLE macro instead of a home-made one.
rguyom
parents:
8462
diff
changeset
|
32 #ifdef XVID_API_UNSTABLE |
ce25d80dd6c3
Use the XVID_API_UNSTABLE macro instead of a home-made one.
rguyom
parents:
8462
diff
changeset
|
33 #warning ******************************************************************* |
ce25d80dd6c3
Use the XVID_API_UNSTABLE macro instead of a home-made one.
rguyom
parents:
8462
diff
changeset
|
34 #warning ** ** |
ce25d80dd6c3
Use the XVID_API_UNSTABLE macro instead of a home-made one.
rguyom
parents:
8462
diff
changeset
|
35 #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 ** |
ce25d80dd6c3
Use the XVID_API_UNSTABLE macro instead of a home-made one.
rguyom
parents:
8462
diff
changeset
|
36 #warning ** ** |
9806 | 37 #warning ** Streams produced by this version aren''t probably compatible ** |
8491
ce25d80dd6c3
Use the XVID_API_UNSTABLE macro instead of a home-made one.
rguyom
parents:
8462
diff
changeset
|
38 #warning ** with anything else, even the xvid decoder itself. There are ** |
ce25d80dd6c3
Use the XVID_API_UNSTABLE macro instead of a home-made one.
rguyom
parents:
8462
diff
changeset
|
39 #warning ** bugs, this code could crash, could blow up your PC or the ** |
ce25d80dd6c3
Use the XVID_API_UNSTABLE macro instead of a home-made one.
rguyom
parents:
8462
diff
changeset
|
40 #warning ** whole building ! ** |
ce25d80dd6c3
Use the XVID_API_UNSTABLE macro instead of a home-made one.
rguyom
parents:
8462
diff
changeset
|
41 #warning ** If you want stable code and compatible streams, use stable ** |
ce25d80dd6c3
Use the XVID_API_UNSTABLE macro instead of a home-made one.
rguyom
parents:
8462
diff
changeset
|
42 #warning ** XViD releases (currently 0.9.x). ** |
ce25d80dd6c3
Use the XVID_API_UNSTABLE macro instead of a home-made one.
rguyom
parents:
8462
diff
changeset
|
43 #warning ** ** |
ce25d80dd6c3
Use the XVID_API_UNSTABLE macro instead of a home-made one.
rguyom
parents:
8462
diff
changeset
|
44 #warning ******************************************************************* |
8462
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
45 #endif |
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
46 |
7456 | 47 /**********************************************************************/ |
8462
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
48 /* motion estimation quality presets */ |
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
49 static int const motion_presets[7] = { |
8491
ce25d80dd6c3
Use the XVID_API_UNSTABLE macro instead of a home-made one.
rguyom
parents:
8462
diff
changeset
|
50 #ifdef XVID_API_UNSTABLE |
8462
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
51 0, |
9803
4563dfa92a5b
xvid fixes and more options by elcabesa & Martin Drab
henry
parents:
9014
diff
changeset
|
52 0, |
8462
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
53 0, |
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
54 0, |
9817
796e9b8bf2e3
- added <time.h> since we're using time() related functions
rguyom
parents:
9809
diff
changeset
|
55 PMV_HALFPELREFINE16 | PMV_HALFPELDIAMOND8, |
796e9b8bf2e3
- added <time.h> since we're using time() related functions
rguyom
parents:
9809
diff
changeset
|
56 PMV_HALFPELREFINE16 | PMV_HALFPELDIAMOND8 | PMV_ADVANCEDDIAMOND16, |
796e9b8bf2e3
- added <time.h> since we're using time() related functions
rguyom
parents:
9809
diff
changeset
|
57 PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 | PMV_HALFPELREFINE8 | PMV_HALFPELDIAMOND8 | PMV_USESQUARES16 |
8462
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
58 #else |
8078 | 59 0, |
60 PMV_QUICKSTOP16, | |
7456 | 61 PMV_EARLYSTOP16, |
8078 | 62 PMV_EARLYSTOP16 | PMV_EARLYSTOP8, |
63 PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 | PMV_HALFPELDIAMOND8, | |
64 PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EARLYSTOP8 | PMV_HALFPELDIAMOND8 | PMV_ADVANCEDDIAMOND16, | |
65 PMV_EARLYSTOP16 | PMV_HALFPELREFINE16 | PMV_EXTSEARCH16 | PMV_EARLYSTOP8 | PMV_HALFPELREFINE8 | | |
66 PMV_HALFPELDIAMOND8 | PMV_USESQUARES16 | |
67 | |
8462
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
68 #endif |
7456 | 69 }; |
70 | |
8078 | 71 extern char* passtmpfile; |
7456 | 72 |
8078 | 73 static int xvidenc_pass = 0; |
9817
796e9b8bf2e3
- added <time.h> since we're using time() related functions
rguyom
parents:
9809
diff
changeset
|
74 static int xvidenc_quality = 6; |
8462
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
75 static int xvidenc_4mv = 0; |
8078 | 76 static int xvidenc_bitrate = -1; |
77 static int xvidenc_rc_reaction_delay_factor = -1; | |
78 static int xvidenc_rc_averaging_period = -1; | |
79 static int xvidenc_rc_buffer = -1; | |
8247
91edcb091dc6
Instead of min_quantizer, max_quantizer, min_iquantizer, etc... use a
rguyom
parents:
8221
diff
changeset
|
80 static char* xvidenc_quant_range = "2-31/2-31"; |
8221 | 81 static int xvidenc_min_key_interval = -1; |
8078 | 82 static int xvidenc_max_key_interval = -1; |
83 static int xvidenc_mpeg_quant = 0; | |
8192 | 84 static int xvidenc_mod_quant = 0; |
8221 | 85 static int xvidenc_keyframe_boost = -1; |
8192 | 86 static int xvidenc_kfthreshold = -1; |
87 static int xvidenc_kfreduction = -1; | |
8078 | 88 static int xvidenc_fixed_quant = 0; |
89 static int xvidenc_debug = 0; | |
9805 | 90 static int xvidenc_interlacing = 0; |
9806 | 91 static int xvidenc_greyscale = 0; |
8491
ce25d80dd6c3
Use the XVID_API_UNSTABLE macro instead of a home-made one.
rguyom
parents:
8462
diff
changeset
|
92 #ifdef XVID_API_UNSTABLE |
9805 | 93 static int xvidenc_packed = 0; |
94 static int xvidenc_divx5bvop = 1; | |
9804 | 95 static int xvidenc_lumi_mask = 0; |
8462
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
96 static int xvidenc_qpel = 0; |
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
97 static int xvidenc_max_bframes = 0; |
9804 | 98 static int xvidenc_bquant_ratio = 150; |
99 static int xvidenc_bquant_offset = 100; | |
9843 | 100 static int xvidenc_bf_threshold = 0; |
8462
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
101 static int xvidenc_gmc = 0; |
9805 | 102 static int xvidenc_chroma_me = 0; |
9817
796e9b8bf2e3
- added <time.h> since we're using time() related functions
rguyom
parents:
9809
diff
changeset
|
103 static int xvidenc_chroma_opt = 0; |
8462
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
104 static int xvidenc_reduced = 0; |
9817
796e9b8bf2e3
- added <time.h> since we're using time() related functions
rguyom
parents:
9809
diff
changeset
|
105 static int xvidenc_hqac = 0; |
796e9b8bf2e3
- added <time.h> since we're using time() related functions
rguyom
parents:
9809
diff
changeset
|
106 static int xvidenc_vhq = 0; |
796e9b8bf2e3
- added <time.h> since we're using time() related functions
rguyom
parents:
9809
diff
changeset
|
107 static int xvidenc_psnr = 0; |
9809
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
108 static uint64_t xvid_error[3]; |
8462
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
109 #endif |
7458 | 110 |
10594
57bdcdb061d7
Removed the historic cfgparser and switched full to the new config parser (altought some macros still remain for compatibility). As a side effect 90% of the warning messages are gone from the core. Things should be cleaner now and less confusing for newbies.
alex
parents:
9843
diff
changeset
|
111 m_option_t xvidencopts_conf[] = { |
8078 | 112 { "pass", &xvidenc_pass, CONF_TYPE_INT, CONF_RANGE, 0, 2, NULL}, |
8462
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
113 { "me_quality", &xvidenc_quality, CONF_TYPE_INT, CONF_RANGE, 0, |
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
114 sizeof(motion_presets) / sizeof(motion_presets[0]) - 1, NULL}, |
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
115 { "4mv", &xvidenc_4mv, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
116 { "bitrate", &xvidenc_bitrate, CONF_TYPE_INT, CONF_RANGE, 4, 24000000, NULL}, |
8078 | 117 { "rc_reaction_delay_factor", &xvidenc_rc_reaction_delay_factor, CONF_TYPE_INT, 0, 0, 0, NULL}, |
118 { "rc_averaging_period", &xvidenc_rc_averaging_period, CONF_TYPE_INT, 0, 0, 0, NULL}, | |
119 { "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
|
120 { "quant_range", &xvidenc_quant_range, CONF_TYPE_STRING, 0, 0, 0, NULL}, |
8078 | 121 { "min_key_interval", &xvidenc_min_key_interval, CONF_TYPE_INT, 0, 0, 0, NULL}, /* for XVID_MODE_2PASS_2 */ |
122 { "max_key_interval", &xvidenc_max_key_interval, CONF_TYPE_INT, 0, 0, 0, NULL}, | |
123 { "mpeg_quant", &xvidenc_mpeg_quant, CONF_TYPE_FLAG, 0, 0, 1, NULL}, | |
8192 | 124 { "mod_quant", &xvidenc_mod_quant, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
8193 | 125 { "keyframe_boost", &xvidenc_keyframe_boost, CONF_TYPE_INT, CONF_RANGE, 0, 1000, NULL}, /* for XVID_MODE_2PASS_2 */ |
8078 | 126 { "kfthreshold", &xvidenc_kfthreshold, CONF_TYPE_INT, 0, 0, 0, NULL}, /* for XVID_MODE_2PASS_2 */ |
8192 | 127 { "kfreduction", &xvidenc_kfreduction, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL}, /* for XVID_MODE_2PASS_2 */ |
8078 | 128 { "fixed_quant", &xvidenc_fixed_quant, CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL}, /* for XVID_MODE_FIXED_QUANT */ |
129 { "debug", &xvidenc_debug, CONF_TYPE_FLAG, 0, 0, 1, NULL}, | |
9805 | 130 { "interlacing", &xvidenc_interlacing, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
9806 | 131 { "greyscale", &xvidenc_greyscale, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
8491
ce25d80dd6c3
Use the XVID_API_UNSTABLE macro instead of a home-made one.
rguyom
parents:
8462
diff
changeset
|
132 #ifdef XVID_API_UNSTABLE |
9805 | 133 { "packed", &xvidenc_packed, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
134 { "divx5bvop", &xvidenc_divx5bvop, CONF_TYPE_FLAG, 0, 0, 1, NULL}, | |
9804 | 135 //{ "lumi_mask", &xvidenc_lumi_mask, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
9809
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
136 { "psnr", &xvidenc_psnr, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
8462
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
137 { "qpel", &xvidenc_qpel, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
138 { "max_bframes", &xvidenc_max_bframes, CONF_TYPE_INT, CONF_RANGE, 0, 4, NULL}, |
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
139 { "bquant_ratio", &xvidenc_bquant_ratio, CONF_TYPE_INT, CONF_RANGE, 0, 1000, NULL}, |
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
140 { "bquant_offset", &xvidenc_bquant_offset, CONF_TYPE_INT, CONF_RANGE, -1000, 1000, NULL}, |
9843 | 141 { "bf_threshold", &xvidenc_bf_threshold, CONF_TYPE_INT, CONF_RANGE, -255, 255, NULL}, |
8462
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
142 { "reduced", &xvidenc_reduced, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
143 { "gmc", &xvidenc_gmc, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
9805 | 144 { "chroma_me", &xvidenc_chroma_me, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
9803
4563dfa92a5b
xvid fixes and more options by elcabesa & Martin Drab
henry
parents:
9014
diff
changeset
|
145 { "hq_ac", &xvidenc_hqac, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
9819 | 146 { "vhq", &xvidenc_vhq, CONF_TYPE_INT, CONF_RANGE, 0, 4, NULL}, |
9817
796e9b8bf2e3
- added <time.h> since we're using time() related functions
rguyom
parents:
9809
diff
changeset
|
147 { "chroma_opt", &xvidenc_chroma_opt, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
8462
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
148 #endif |
7456 | 149 { NULL, NULL, 0, 0, 0, 0, NULL} |
150 }; | |
151 | |
152 struct vf_priv_s { | |
8585 | 153 muxer_stream_t* mux; |
7456 | 154 XVID_ENC_FRAME enc_frame; |
155 void* enc_handle; | |
156 vbr_control_t vbr_state; | |
9809
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
157 int pixels; |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
158 int nb_frames; |
7456 | 159 }; |
160 | |
161 static int | |
162 config(struct vf_instance_s* vf, | |
163 int width, int height, int d_width, int d_height, | |
164 unsigned int flags, unsigned int outfmt) | |
165 { | |
166 XVID_ENC_PARAM enc_param; | |
8078 | 167 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
|
168 unsigned int min_iq, max_iq, min_pq, max_pq; |
7456 | 169 |
8078 | 170 fp->mux->bih->biWidth = width; |
171 fp->mux->bih->biHeight = height; | |
172 fp->mux->bih->biSizeImage = fp->mux->bih->biWidth * fp->mux->bih->biHeight * 3; | |
12061 | 173 fp->mux->aspect = (float)d_width/d_height; |
8078 | 174 mp_msg(MSGT_MENCODER,MSGL_INFO,"videocodec: XViD (%dx%d fourcc=%x [%.4s])\n", |
175 width, height, fp->mux->bih->biCompression, (char *)&fp->mux->bih->biCompression); | |
7456 | 176 |
8247
91edcb091dc6
Instead of min_quantizer, max_quantizer, min_iquantizer, etc... use a
rguyom
parents:
8221
diff
changeset
|
177 // {min,max}_{i,p}quantizer parsing & validation |
91edcb091dc6
Instead of min_quantizer, max_quantizer, min_iquantizer, etc... use a
rguyom
parents:
8221
diff
changeset
|
178 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
|
179 mp_msg (MSGT_MENCODER, MSGL_ERR, |
91edcb091dc6
Instead of min_quantizer, max_quantizer, min_iquantizer, etc... use a
rguyom
parents:
8221
diff
changeset
|
180 "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
|
181 return 0; |
91edcb091dc6
Instead of min_quantizer, max_quantizer, min_iquantizer, etc... use a
rguyom
parents:
8221
diff
changeset
|
182 } |
91edcb091dc6
Instead of min_quantizer, max_quantizer, min_iquantizer, etc... use a
rguyom
parents:
8221
diff
changeset
|
183 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
|
184 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
|
185 mp_msg (MSGT_MENCODER, MSGL_ERR, |
91edcb091dc6
Instead of min_quantizer, max_quantizer, min_iquantizer, etc... use a
rguyom
parents:
8221
diff
changeset
|
186 "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
|
187 mp_msg (MSGT_MENCODER, MSGL_ERR, |
91edcb091dc6
Instead of min_quantizer, max_quantizer, min_iquantizer, etc... use a
rguyom
parents:
8221
diff
changeset
|
188 "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
|
189 return -1; |
91edcb091dc6
Instead of min_quantizer, max_quantizer, min_iquantizer, etc... use a
rguyom
parents:
8221
diff
changeset
|
190 } |
91edcb091dc6
Instead of min_quantizer, max_quantizer, min_iquantizer, etc... use a
rguyom
parents:
8221
diff
changeset
|
191 |
8491
ce25d80dd6c3
Use the XVID_API_UNSTABLE macro instead of a home-made one.
rguyom
parents:
8462
diff
changeset
|
192 #ifdef XVID_API_UNSTABLE |
ce25d80dd6c3
Use the XVID_API_UNSTABLE macro instead of a home-made one.
rguyom
parents:
8462
diff
changeset
|
193 mp_msg (MSGT_MENCODER, MSGL_WARN, |
ce25d80dd6c3
Use the XVID_API_UNSTABLE macro instead of a home-made one.
rguyom
parents:
8462
diff
changeset
|
194 "\n" |
ce25d80dd6c3
Use the XVID_API_UNSTABLE macro instead of a home-made one.
rguyom
parents:
8462
diff
changeset
|
195 "*******************************************************************\n" |
ce25d80dd6c3
Use the XVID_API_UNSTABLE macro instead of a home-made one.
rguyom
parents:
8462
diff
changeset
|
196 "** **\n" |
ce25d80dd6c3
Use the XVID_API_UNSTABLE macro instead of a home-made one.
rguyom
parents:
8462
diff
changeset
|
197 "** 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" |
ce25d80dd6c3
Use the XVID_API_UNSTABLE macro instead of a home-made one.
rguyom
parents:
8462
diff
changeset
|
198 "** **\n" |
9806 | 199 "** Streams produced by this version aren't probably compatible **\n" |
8491
ce25d80dd6c3
Use the XVID_API_UNSTABLE macro instead of a home-made one.
rguyom
parents:
8462
diff
changeset
|
200 "** with anything else, even the xvid decoder itself. There are **\n" |
ce25d80dd6c3
Use the XVID_API_UNSTABLE macro instead of a home-made one.
rguyom
parents:
8462
diff
changeset
|
201 "** bugs, this code could crash, could blow up your PC or the **\n" |
ce25d80dd6c3
Use the XVID_API_UNSTABLE macro instead of a home-made one.
rguyom
parents:
8462
diff
changeset
|
202 "** whole building ! **\n" |
ce25d80dd6c3
Use the XVID_API_UNSTABLE macro instead of a home-made one.
rguyom
parents:
8462
diff
changeset
|
203 "** If you want stable code and compatible streams, use stable **\n" |
ce25d80dd6c3
Use the XVID_API_UNSTABLE macro instead of a home-made one.
rguyom
parents:
8462
diff
changeset
|
204 "** XViD releases (currently 0.9.x). **\n" |
ce25d80dd6c3
Use the XVID_API_UNSTABLE macro instead of a home-made one.
rguyom
parents:
8462
diff
changeset
|
205 "** **\n" |
ce25d80dd6c3
Use the XVID_API_UNSTABLE macro instead of a home-made one.
rguyom
parents:
8462
diff
changeset
|
206 "*******************************************************************\n" |
ce25d80dd6c3
Use the XVID_API_UNSTABLE macro instead of a home-made one.
rguyom
parents:
8462
diff
changeset
|
207 "\n"); |
ce25d80dd6c3
Use the XVID_API_UNSTABLE macro instead of a home-made one.
rguyom
parents:
8462
diff
changeset
|
208 #endif |
ce25d80dd6c3
Use the XVID_API_UNSTABLE macro instead of a home-made one.
rguyom
parents:
8462
diff
changeset
|
209 |
8078 | 210 // initialize XViD core parameters |
211 // =============================== | |
7456 | 212 memset(&enc_param, 0, sizeof(enc_param)); |
213 enc_param.width = width; | |
214 enc_param.height = height; | |
8078 | 215 enc_param.fincr = fp->mux->h.dwScale; |
216 enc_param.fbase = fp->mux->h.dwRate; | |
217 if (xvidenc_bitrate > 16000) | |
218 enc_param.rc_bitrate = xvidenc_bitrate; | |
219 else if (xvidenc_bitrate > 0) | |
220 enc_param.rc_bitrate = xvidenc_bitrate * 1000; | |
221 else | |
222 enc_param.rc_bitrate = -1; | |
8491
ce25d80dd6c3
Use the XVID_API_UNSTABLE macro instead of a home-made one.
rguyom
parents:
8462
diff
changeset
|
223 #ifdef XVID_API_UNSTABLE |
8462
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
224 if (xvidenc_max_bframes >= 1 && xvidenc_pass >= 1) { |
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
225 mp_msg(MSGT_MENCODER,MSGL_WARN, "xvid: cannot use bframes with 2-pass, disabling bframes\n"); |
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
226 xvidenc_max_bframes = 0; |
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
227 } |
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
228 enc_param.max_bframes = xvidenc_max_bframes; |
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
229 enc_param.bquant_ratio = xvidenc_bquant_ratio; |
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
230 enc_param.bquant_offset = xvidenc_bquant_offset; |
9805 | 231 if (xvidenc_divx5bvop) |
232 enc_param.global |= XVID_GLOBAL_DX50BVOP; | |
233 if (xvidenc_packed) | |
234 enc_param.global |= XVID_GLOBAL_PACKED; | |
8462
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
235 if (xvidenc_reduced) |
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
236 enc_param.global |= XVID_GLOBAL_REDUCED; |
9809
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
237 if (xvidenc_psnr) { |
9803
4563dfa92a5b
xvid fixes and more options by elcabesa & Martin Drab
henry
parents:
9014
diff
changeset
|
238 enc_param.global |= XVID_GLOBAL_EXTRASTATS; |
9809
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
239 fp->pixels = width * height; |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
240 fp->nb_frames = 0; |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
241 xvid_error[0] = xvid_error[1] = xvid_error[2] = 0; |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
242 } |
9806 | 243 if (xvidenc_greyscale) |
244 enc_param.global |= XVID_GREYSCALE; | |
9835 | 245 #endif |
8078 | 246 enc_param.rc_reaction_delay_factor = xvidenc_rc_reaction_delay_factor; |
247 enc_param.rc_averaging_period = xvidenc_rc_averaging_period; | |
248 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
|
249 enc_param.min_quantizer = min_iq; |
91edcb091dc6
Instead of min_quantizer, max_quantizer, min_iquantizer, etc... use a
rguyom
parents:
8221
diff
changeset
|
250 enc_param.max_quantizer = max_iq; |
8221 | 251 if( xvidenc_max_key_interval <= 0 ) |
252 xvidenc_max_key_interval = 10 * enc_param.fbase / enc_param.fincr; | |
253 enc_param.max_key_interval = xvidenc_max_key_interval; | |
7456 | 254 switch (xvid_encore(NULL, XVID_ENC_CREATE, &enc_param, NULL)) { |
255 case XVID_ERR_FAIL: | |
8078 | 256 mp_msg(MSGT_MENCODER,MSGL_ERR, "xvid: encoder creation failed\n"); |
7456 | 257 return 0; |
258 case XVID_ERR_MEMORY: | |
8078 | 259 mp_msg(MSGT_MENCODER,MSGL_ERR, "xvid: encoder creation failed, out of memory\n"); |
7456 | 260 return 0; |
261 case XVID_ERR_FORMAT: | |
8078 | 262 mp_msg(MSGT_MENCODER,MSGL_ERR, "xvid: encoder creation failed, bad format\n"); |
7456 | 263 return 0; |
264 } | |
8078 | 265 fp->enc_handle = enc_param.handle; |
7456 | 266 |
8078 | 267 // initialize XViD per-frame static parameters |
268 // =========================================== | |
8462
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
269 fp->enc_frame.motion = motion_presets[xvidenc_quality]; |
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
270 fp->enc_frame.general = XVID_HALFPEL | (xvidenc_mpeg_quant ? XVID_MPEGQUANT : XVID_H263QUANT); |
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
271 if (xvidenc_4mv) |
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
272 fp->enc_frame.general |= XVID_INTER4V; |
9805 | 273 if (xvidenc_interlacing) |
274 fp->enc_frame.general |= XVID_INTERLACING; | |
8491
ce25d80dd6c3
Use the XVID_API_UNSTABLE macro instead of a home-made one.
rguyom
parents:
8462
diff
changeset
|
275 #ifdef XVID_API_UNSTABLE |
9843 | 276 fp->enc_frame.bframe_threshold = xvidenc_bf_threshold; |
9835 | 277 if (xvidenc_lumi_mask) |
278 fp->enc_frame.general |= XVID_LUMIMASKING; | |
8462
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
279 if (xvidenc_qpel) { |
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
280 fp->enc_frame.general |= XVID_QUARTERPEL; |
9817
796e9b8bf2e3
- added <time.h> since we're using time() related functions
rguyom
parents:
9809
diff
changeset
|
281 fp->enc_frame.motion |= PMV_QUARTERPELREFINE16 | PMV_QUARTERPELREFINE8; |
8462
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
282 } |
9817
796e9b8bf2e3
- added <time.h> since we're using time() related functions
rguyom
parents:
9809
diff
changeset
|
283 switch (xvidenc_vhq) { |
9819 | 284 case 4: // wide search |
9817
796e9b8bf2e3
- added <time.h> since we're using time() related functions
rguyom
parents:
9809
diff
changeset
|
285 fp->enc_frame.motion |= EXTSEARCH_BITS | PMV_EXTSEARCH8; |
9819 | 286 case 3: // medium search |
9817
796e9b8bf2e3
- added <time.h> since we're using time() related functions
rguyom
parents:
9809
diff
changeset
|
287 fp->enc_frame.motion |= HALFPELREFINE8_BITS | QUARTERPELREFINE8_BITS | CHECKPREDICTION_BITS; |
9819 | 288 case 2: // limited search |
9817
796e9b8bf2e3
- added <time.h> since we're using time() related functions
rguyom
parents:
9809
diff
changeset
|
289 fp->enc_frame.motion |= HALFPELREFINE16_BITS | QUARTERPELREFINE16_BITS; |
9819 | 290 case 1: // mode decision |
9803
4563dfa92a5b
xvid fixes and more options by elcabesa & Martin Drab
henry
parents:
9014
diff
changeset
|
291 fp->enc_frame.general |= XVID_MODEDECISION_BITS; |
9817
796e9b8bf2e3
- added <time.h> since we're using time() related functions
rguyom
parents:
9809
diff
changeset
|
292 break; |
796e9b8bf2e3
- added <time.h> since we're using time() related functions
rguyom
parents:
9809
diff
changeset
|
293 case 0: // off |
796e9b8bf2e3
- added <time.h> since we're using time() related functions
rguyom
parents:
9809
diff
changeset
|
294 break; |
796e9b8bf2e3
- added <time.h> since we're using time() related functions
rguyom
parents:
9809
diff
changeset
|
295 } |
8462
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
296 if (xvidenc_gmc) |
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
297 fp->enc_frame.general |= XVID_GMC; |
9809
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
298 if (xvidenc_psnr) |
9803
4563dfa92a5b
xvid fixes and more options by elcabesa & Martin Drab
henry
parents:
9014
diff
changeset
|
299 fp->enc_frame.general |= XVID_EXTRASTATS; |
9805 | 300 if (xvidenc_chroma_me) |
9803
4563dfa92a5b
xvid fixes and more options by elcabesa & Martin Drab
henry
parents:
9014
diff
changeset
|
301 fp->enc_frame.motion |= PMV_CHROMA16 | PMV_CHROMA8; |
8462
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
302 if(xvidenc_reduced) |
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
303 fp->enc_frame.general |= XVID_REDUCED; |
9803
4563dfa92a5b
xvid fixes and more options by elcabesa & Martin Drab
henry
parents:
9014
diff
changeset
|
304 if(xvidenc_hqac) |
4563dfa92a5b
xvid fixes and more options by elcabesa & Martin Drab
henry
parents:
9014
diff
changeset
|
305 fp->enc_frame.general |= XVID_HQACPRED; |
9817
796e9b8bf2e3
- added <time.h> since we're using time() related functions
rguyom
parents:
9809
diff
changeset
|
306 if (xvidenc_chroma_opt) |
9803
4563dfa92a5b
xvid fixes and more options by elcabesa & Martin Drab
henry
parents:
9014
diff
changeset
|
307 fp->enc_frame.general |= XVID_CHROMAOPT; |
9835 | 308 #else |
309 if (xvidenc_greyscale) | |
310 fp->enc_frame.general |= XVID_GREYSCALE; | |
8462
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
311 #endif |
8078 | 312 |
7456 | 313 switch (outfmt) { |
314 case IMGFMT_YV12: | |
8078 | 315 fp->enc_frame.colorspace = XVID_CSP_YV12; |
7456 | 316 break; |
317 case IMGFMT_IYUV: case IMGFMT_I420: | |
8078 | 318 fp->enc_frame.colorspace = XVID_CSP_I420; |
7456 | 319 break; |
320 case IMGFMT_YUY2: | |
8078 | 321 fp->enc_frame.colorspace = XVID_CSP_YUY2; |
7456 | 322 break; |
323 case IMGFMT_UYVY: | |
8078 | 324 fp->enc_frame.colorspace = XVID_CSP_UYVY; |
7456 | 325 break; |
326 case IMGFMT_RGB24: case IMGFMT_BGR24: | |
8078 | 327 fp->enc_frame.colorspace = XVID_CSP_RGB24; |
7456 | 328 break; |
329 default: | |
330 mp_msg(MSGT_MENCODER,MSGL_ERR,"xvid: unsupported picture format (%s)!\n", | |
331 vo_format_name(outfmt)); | |
332 return 0; | |
333 } | |
8078 | 334 fp->enc_frame.quant_intra_matrix = 0; |
335 fp->enc_frame.quant_inter_matrix = 0; | |
336 | |
337 // initialize VBR engine | |
338 // ===================== | |
339 vbrSetDefaults(&fp->vbr_state); | |
8221 | 340 if (xvidenc_min_key_interval < 0) |
341 xvidenc_min_key_interval = fp->vbr_state.min_key_interval; | |
342 | |
343 // pass | |
8078 | 344 if (xvidenc_pass == 0) { |
345 if (xvidenc_fixed_quant >= 1) { | |
346 fp->vbr_state.mode = VBR_MODE_FIXED_QUANT; | |
347 fp->vbr_state.fixed_quant = xvidenc_fixed_quant; | |
348 } else | |
349 fp->vbr_state.mode = VBR_MODE_1PASS; | |
7456 | 350 } |
8078 | 351 else if (xvidenc_pass == 1) |
352 fp->vbr_state.mode = VBR_MODE_2PASS_1; | |
353 else if (xvidenc_pass == 2) | |
354 fp->vbr_state.mode = VBR_MODE_2PASS_2; | |
355 else | |
356 return -1; | |
8221 | 357 |
358 // misc | |
8078 | 359 fp->vbr_state.fps = (double)enc_param.fbase / enc_param.fincr; |
360 fp->vbr_state.filename = passtmpfile; | |
361 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
|
362 fp->vbr_state.min_iquant = min_iq; |
91edcb091dc6
Instead of min_quantizer, max_quantizer, min_iquantizer, etc... use a
rguyom
parents:
8221
diff
changeset
|
363 fp->vbr_state.max_iquant = max_iq; |
91edcb091dc6
Instead of min_quantizer, max_quantizer, min_iquantizer, etc... use a
rguyom
parents:
8221
diff
changeset
|
364 fp->vbr_state.min_pquant = min_pq; |
91edcb091dc6
Instead of min_quantizer, max_quantizer, min_iquantizer, etc... use a
rguyom
parents:
8221
diff
changeset
|
365 fp->vbr_state.max_pquant = max_pq; |
8221 | 366 if (xvidenc_keyframe_boost >= 0) |
8078 | 367 fp->vbr_state.keyframe_boost = xvidenc_keyframe_boost; |
8192 | 368 if (xvidenc_kfthreshold >= 0) |
8078 | 369 fp->vbr_state.kftreshold = xvidenc_kfthreshold; |
8192 | 370 if (xvidenc_kfreduction >= 0) |
8078 | 371 fp->vbr_state.kfreduction = xvidenc_kfreduction; |
8221 | 372 if (xvidenc_min_key_interval >= 0) |
8078 | 373 fp->vbr_state.min_key_interval = xvidenc_min_key_interval; |
374 fp->vbr_state.max_key_interval = enc_param.max_key_interval; | |
375 fp->vbr_state.debug = xvidenc_debug; | |
8221 | 376 |
8078 | 377 vbrInit(&fp->vbr_state); |
378 | |
17659 | 379 #ifdef XVID_API_UNSTABLE |
380 fp->mux->decoder_delay = enc_param.max_bframes ? 1 : 0; | |
381 #endif | |
382 | |
7456 | 383 return 1; |
384 } | |
385 | |
9823
da375915f47c
"psnr" & related code is only for the -HEAD (unstable) XviD branch.
rguyom
parents:
9819
diff
changeset
|
386 #ifdef XVID_API_UNSTABLE |
9809
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
387 static double |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
388 sse_to_PSNR(double sse, double pixels) |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
389 { |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
390 return sse == 0 ? INFINITY : 4.34294481903251827652 * (11.08252709031685229249 - log(sse/pixels)); |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
391 // 4.34294481903251827652 = 10/log(10) |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
392 // 11.08252709031685229249 = log(255*255) |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
393 } |
9823
da375915f47c
"psnr" & related code is only for the -HEAD (unstable) XviD branch.
rguyom
parents:
9819
diff
changeset
|
394 #endif |
9809
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
395 |
7456 | 396 static void |
397 uninit(struct vf_instance_s* vf) | |
398 { | |
8078 | 399 struct vf_priv_s *fp = vf->priv; |
400 | |
9823
da375915f47c
"psnr" & related code is only for the -HEAD (unstable) XviD branch.
rguyom
parents:
9819
diff
changeset
|
401 #ifdef XVID_API_UNSTABLE |
9809
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
402 if (xvidenc_psnr) { |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
403 double p = (double)fp->pixels * (double)fp->nb_frames; |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
404 printf ("PSNR: Y:%2.2f, Cb:%2.2f, Cr:%2.2f, All:%2.2f\n", |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
405 sse_to_PSNR(xvid_error[0], p), |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
406 sse_to_PSNR(xvid_error[1], p/4), |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
407 sse_to_PSNR(xvid_error[2], p/4), |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
408 sse_to_PSNR(xvid_error[0] + xvid_error[1] + xvid_error[2], p*1.5)); |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
409 } |
9823
da375915f47c
"psnr" & related code is only for the -HEAD (unstable) XviD branch.
rguyom
parents:
9819
diff
changeset
|
410 #endif |
8078 | 411 vbrFinish(&fp->vbr_state); |
7456 | 412 } |
413 | |
414 static int | |
415 control(struct vf_instance_s* vf, int request, void* data) | |
416 { | |
417 return CONTROL_UNKNOWN; | |
418 } | |
419 | |
420 static int | |
421 query_format(struct vf_instance_s* vf, unsigned int fmt) | |
422 { | |
423 switch(fmt){ | |
424 case IMGFMT_YV12: case IMGFMT_IYUV: case IMGFMT_I420: | |
425 return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW; | |
426 case IMGFMT_YUY2: case IMGFMT_UYVY: | |
427 return VFCAP_CSP_SUPPORTED; | |
428 case IMGFMT_RGB24: case IMGFMT_BGR24: | |
429 return VFCAP_CSP_SUPPORTED | VFCAP_FLIPPED; | |
430 } | |
431 return 0; | |
432 } | |
433 | |
434 static int | |
17906
20aca9baf5d8
passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents:
17659
diff
changeset
|
435 put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts) |
7456 | 436 { |
437 XVID_ENC_STATS enc_stats; | |
8078 | 438 struct vf_priv_s *fp = vf->priv; |
7456 | 439 |
8078 | 440 fp->enc_frame.bitstream = fp->mux->buffer; |
441 fp->enc_frame.length = -1 /* fp->mux->buffer_size */; | |
442 fp->enc_frame.image = mpi->planes[0]; | |
8561 | 443 #ifdef XVID_API_UNSTABLE |
444 fp->enc_frame.stride = mpi->stride[0]; | |
445 #endif | |
8192 | 446 |
447 // get quantizers & I/P decision from the VBR engine | |
8491
ce25d80dd6c3
Use the XVID_API_UNSTABLE macro instead of a home-made one.
rguyom
parents:
8462
diff
changeset
|
448 #ifdef XVID_API_UNSTABLE |
8462
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
449 if (xvidenc_max_bframes >= 1) { |
9803
4563dfa92a5b
xvid fixes and more options by elcabesa & Martin Drab
henry
parents:
9014
diff
changeset
|
450 if (xvidenc_fixed_quant!=0) { |
8462
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
451 // hack, the internal VBR engine isn't fixed-quant aware |
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
452 fp->enc_frame.quant = xvidenc_fixed_quant; |
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
453 fp->enc_frame.intra = -1; |
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
454 fp->enc_frame.bquant = (xvidenc_fixed_quant * xvidenc_bquant_ratio + xvidenc_bquant_offset) / 100; |
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
455 } else |
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
456 // use the internal VBR engine since the external one isn't bframe aware |
9803
4563dfa92a5b
xvid fixes and more options by elcabesa & Martin Drab
henry
parents:
9014
diff
changeset
|
457 fp->enc_frame.quant =0; |
4563dfa92a5b
xvid fixes and more options by elcabesa & Martin Drab
henry
parents:
9014
diff
changeset
|
458 fp->enc_frame.intra =-1; |
4563dfa92a5b
xvid fixes and more options by elcabesa & Martin Drab
henry
parents:
9014
diff
changeset
|
459 fp->enc_frame.bquant = 0; |
8462
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
460 } else { |
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
461 fp->enc_frame.quant = vbrGetQuant(&fp->vbr_state); |
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
462 fp->enc_frame.intra = vbrGetIntra(&fp->vbr_state); |
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
463 } |
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
464 #else |
8078 | 465 fp->enc_frame.quant = vbrGetQuant(&fp->vbr_state); |
466 fp->enc_frame.intra = vbrGetIntra(&fp->vbr_state); | |
8462
800d77666843
Support the latest development code from XViD dev-api-3 CVS
rguyom
parents:
8247
diff
changeset
|
467 #endif |
8192 | 468 |
469 // modulated quantizer type | |
470 if (xvidenc_mod_quant && xvidenc_pass == 2) { | |
471 fp->enc_frame.general |= (fp->enc_frame.quant < 4) ? XVID_MPEGQUANT : XVID_H263QUANT; | |
472 fp->enc_frame.general &= (fp->enc_frame.quant < 4) ? ~XVID_H263QUANT : ~XVID_MPEGQUANT; | |
473 } | |
474 | |
475 // encode frame | |
8078 | 476 switch (xvid_encore(fp->enc_handle, XVID_ENC_ENCODE, &fp->enc_frame, &enc_stats)) { |
7456 | 477 case XVID_ERR_OK: |
478 break; | |
479 case XVID_ERR_MEMORY: | |
480 mp_msg(MSGT_MENCODER, MSGL_ERR, "xvid: out of memory\n"); | |
481 break; | |
482 case XVID_ERR_FORMAT: | |
483 mp_msg(MSGT_MENCODER, MSGL_ERR, "xvid: bad format\n"); | |
484 break; | |
485 default: | |
486 mp_msg(MSGT_MENCODER, MSGL_ERR, "xvid: failure\n"); | |
487 break; | |
488 } | |
9809
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
489 |
9823
da375915f47c
"psnr" & related code is only for the -HEAD (unstable) XviD branch.
rguyom
parents:
9819
diff
changeset
|
490 #ifdef XVID_API_UNSTABLE |
9809
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
491 if (xvidenc_psnr) { |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
492 static FILE *fvstats = NULL; |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
493 char filename[20]; |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
494 |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
495 if (!fvstats) { |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
496 time_t today2; |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
497 struct tm *today; |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
498 today2 = time (NULL); |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
499 today = localtime (&today2); |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
500 sprintf (filename, "psnr_%02d%02d%02d.log", today->tm_hour, today->tm_min, today->tm_sec); |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
501 fvstats = fopen (filename,"w"); |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
502 if (!fvstats) { |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
503 perror ("fopen"); |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
504 xvidenc_psnr = 0; // disable block |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
505 } |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
506 } |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
507 |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
508 xvid_error[0] += enc_stats.sse_y; |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
509 xvid_error[1] += enc_stats.sse_u; |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
510 xvid_error[2] += enc_stats.sse_v; |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
511 |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
512 fprintf (fvstats, "%6d, %2d, %6d, %2.2f, %2.2f, %2.2f, %2.2f %c\n", |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
513 fp->nb_frames, |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
514 enc_stats.quant, |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
515 fp->enc_frame.length, |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
516 sse_to_PSNR (enc_stats.sse_y, fp->pixels), |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
517 sse_to_PSNR (enc_stats.sse_u, fp->pixels / 4), |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
518 sse_to_PSNR (enc_stats.sse_v, fp->pixels / 4), |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
519 sse_to_PSNR (enc_stats.sse_y + enc_stats.sse_u + enc_stats.sse_v, (double)fp->pixels * 1.5), |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
520 fp->enc_frame.intra == 0 ? 'P' : fp->enc_frame.intra == 1 ? 'I' : 'B' |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
521 ); |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
522 |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
523 fp->nb_frames++; |
508dc4231269
Actually do something useful with XVID_GLOBAL_EXTRASTATS / XVID_EXTRASTATS.
rguyom
parents:
9806
diff
changeset
|
524 } |
9823
da375915f47c
"psnr" & related code is only for the -HEAD (unstable) XviD branch.
rguyom
parents:
9819
diff
changeset
|
525 #endif |
8192 | 526 |
527 // write output | |
17659 | 528 if (fp->enc_frame.length > 0) |
17487
fa17424b4c7b
change muxer_write_chunk() so that pts/dts _could_ be passed from encoder to muxer
michael
parents:
17012
diff
changeset
|
529 muxer_write_chunk(fp->mux, fp->enc_frame.length, fp->enc_frame.intra==1 ? 0x10 : 0, MP_NOPTS_VALUE, MP_NOPTS_VALUE); |
17659 | 530 else |
531 ++fp->mux->encoder_delay; | |
8192 | 532 |
533 // update the VBR engine | |
8078 | 534 vbrUpdate(&fp->vbr_state, enc_stats.quant, fp->enc_frame.intra, |
535 enc_stats.hlength, fp->enc_frame.length, enc_stats.kblks, enc_stats.mblks, enc_stats.ublks); | |
8192 | 536 |
7456 | 537 return 1; |
538 } | |
539 | |
540 //===========================================================================// | |
541 | |
542 static int | |
543 vf_open(vf_instance_t *vf, char* args) | |
544 { | |
545 XVID_INIT_PARAM params = { 0, 0, 0}; | |
546 vf->config = config; | |
14878 | 547 vf->default_caps = VFCAP_CONSTANT; |
7456 | 548 vf->control = control; |
549 vf->uninit = uninit; | |
550 vf->query_format = query_format; | |
551 vf->put_image = put_image; | |
552 vf->priv = malloc(sizeof(struct vf_priv_s)); | |
553 memset(vf->priv, 0, sizeof(struct vf_priv_s)); | |
8585 | 554 vf->priv->mux = (muxer_stream_t*)args; |
7456 | 555 |
14549
acf3241be19b
Initialized BITMAPINFOHEADER to 0 to avoid problems, esp. windows has problems
reimar
parents:
12061
diff
changeset
|
556 vf->priv->mux->bih = calloc(1, sizeof(BITMAPINFOHEADER)); |
7456 | 557 vf->priv->mux->bih->biSize = sizeof(BITMAPINFOHEADER); |
558 vf->priv->mux->bih->biWidth = 0; | |
559 vf->priv->mux->bih->biHeight = 0; | |
560 vf->priv->mux->bih->biPlanes = 1; | |
561 vf->priv->mux->bih->biBitCount = 24; | |
562 vf->priv->mux->bih->biCompression = mmioFOURCC('X','V','I','D'); | |
563 | |
564 if (xvid_init(NULL, 0, ¶ms, NULL) != XVID_ERR_OK) { | |
8078 | 565 mp_msg(MSGT_MENCODER,MSGL_ERR, "xvid: initialisation failure\n"); |
7456 | 566 abort(); |
567 } | |
568 if (params.api_version != API_VERSION) { | |
8078 | 569 mp_msg(MSGT_MENCODER,MSGL_ERR, "xvid: XviD library API version mismatch\n" |
7456 | 570 "\texpected %d.%d, got %d.%d, you should recompile MPlayer.\n", |
571 API_VERSION >> 16, API_VERSION & 0xff, | |
572 params.api_version >> 16, params.api_version & 0xff); | |
573 abort(); | |
574 } | |
575 | |
576 return 1; | |
577 } | |
578 | |
579 vf_info_t ve_info_xvid = { | |
580 "XviD encoder", | |
581 "xvid", | |
8078 | 582 "Kim Minh Kaplan & Rémi Guyomarch", |
7456 | 583 "for internal use by mencoder", |
584 vf_open | |
585 }; | |
586 | |
587 //===========================================================================// |