annotate libmpcodecs/ve_xvid4.c @ 11579:2f96ed23c71b

prevent possible segfault when vidmodes is freed and config() calls vo_vm_switch again. Found by Peter Kosinar <goober@ksp.sk>
author attila
date Mon, 08 Dec 2003 12:03:03 +0000
parents 5af505348795
children efe910b068fc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1 /*****************************************************************************
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
2 *
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
3 * - XviD 1.0 export module for mplayer/mencoder -
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
4 *
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
5 * Copyright(C) 2003 Marco Belli <elcabesa@inwind.it>
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
6 * 2003 Edouard Gomez <ed.gomez@free.fr>
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
7 *
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
11 * (at your option) any later version.
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
12 *
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
16 * GNU General Public License for more details.
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
17 *
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
21 *
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
22 ****************************************************************************/
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
23
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
24 /*****************************************************************************
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
25 * Includes
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
26 ****************************************************************************/
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
27
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
28 #include <stdio.h>
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
29 #include <stdlib.h>
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
30 #include <string.h>
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
31 #include <errno.h>
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
32 #include <math.h>
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
33 #include <limits.h>
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
34
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
35 #include "../config.h"
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
36 #include "../mp_msg.h"
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
37
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
38 #ifdef HAVE_XVID4
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
39
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
40 #include "codec-cfg.h"
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
41 #include "stream.h"
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
42 #include "demuxer.h"
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
43 #include "stheader.h"
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
44
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
45 #include "muxer.h"
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
46
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
47 #include "img_format.h"
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
48 #include "mp_image.h"
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
49 #include "vf.h"
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
50
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
51 #include <xvid.h>
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
52 #include <stdio.h>
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
53 #include <stdarg.h>
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
54 #include <limits.h>
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
55
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
56 #include "m_option.h"
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
57
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
58 #define XVID_FIRST_PASS_FILENAME "xvid-twopass.stats"
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
59 #define FINE (!0)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
60 #define BAD (!FINE)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
61
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
62 /*****************************************************************************
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
63 * Configuration options
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
64 ****************************************************************************/
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
65
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
66 static int xvidenc_bitrate = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
67 static int xvidenc_pass = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
68 static float xvidenc_quantizer = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
69
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
70 static int xvidenc_packed = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
71 static int xvidenc_closed_gop = 1;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
72 static int xvidenc_interlaced = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
73 static int xvidenc_quarterpel = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
74 static int xvidenc_gmc = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
75 static int xvidenc_trellis = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
76 static int xvidenc_cartoon = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
77 static int xvidenc_hqacpred = 1;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
78 static int xvidenc_chromame = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
79 static int xvidenc_vhq = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
80 static int xvidenc_motion = 6;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
81 static int xvidenc_stats = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
82 static int xvidenc_max_key_interval = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
83 static int xvidenc_frame_drop_ratio = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
84 static int xvidenc_greyscale = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
85
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
86 static int xvidenc_max_bframes = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
87 static int xvidenc_bquant_ratio = 150;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
88 static int xvidenc_bquant_offset = 100;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
89 static int xvidenc_bframe_threshold = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
90
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
91 static int xvidenc_min_quant[3] = {2, 2, 2};
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
92 static int xvidenc_max_quant[3] = {31, 31, 31};
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
93 static char *xvidenc_intra_matrix_file = NULL;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
94 static char *xvidenc_inter_matrix_file = NULL;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
95 static char *xvidenc_quant_method = NULL;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
96
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
97 static int xvidenc_cbr_reaction_delay_factor = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
98 static int xvidenc_cbr_averaging_period = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
99 static int xvidenc_cbr_buffer = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
100
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
101 static int xvidenc_vbr_keyframe_boost = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
102 static int xvidenc_vbr_overflow_control_strength = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
103 static int xvidenc_vbr_curve_compression_high = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
104 static int xvidenc_vbr_curve_compression_low = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
105 static int xvidenc_vbr_max_overflow_improvement = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
106 static int xvidenc_vbr_max_overflow_degradation = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
107 static int xvidenc_vbr_kfreduction = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
108 static int xvidenc_vbr_min_key_interval = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
109 static int xvidenc_vbr_container_frame_overhead = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
110
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
111 static char *xvidenc_par = NULL;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
112 static int xvidenc_par_width = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
113 static int xvidenc_par_height = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
114
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
115 m_option_t xvidencopts_conf[] =
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
116 {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
117 /* Standard things mencoder should be able to treat directly */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
118 {"bitrate", &xvidenc_bitrate, CONF_TYPE_INT, 0, 0, 0, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
119 {"pass", &xvidenc_pass, CONF_TYPE_INT, CONF_RANGE, 1, 2, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
120 {"fixed_quant", &xvidenc_quantizer, CONF_TYPE_FLOAT, CONF_RANGE, 1, 31, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
121
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
122 /* Features */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
123 {"quant_type", &xvidenc_quant_method, CONF_TYPE_STRING, 0, 0, 0, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
124 {"me_quality", &xvidenc_motion, CONF_TYPE_INT, CONF_RANGE, 0, 6, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
125 {"chroma_me", &xvidenc_chromame, CONF_TYPE_FLAG, 0, 0, 1, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
126 {"vhq", &xvidenc_vhq, CONF_TYPE_INT, CONF_RANGE, 0, 4, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
127 {"max_bframes", &xvidenc_max_bframes, CONF_TYPE_INT, CONF_RANGE, 0, 20, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
128 {"bquant_ratio", &xvidenc_bquant_ratio, CONF_TYPE_INT, CONF_RANGE, 0, 200, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
129 {"bquant_offset", &xvidenc_bquant_offset, CONF_TYPE_INT, CONF_RANGE, 0, 200, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
130 {"bf_threshold", &xvidenc_bframe_threshold, CONF_TYPE_INT, CONF_RANGE, -255, 255, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
131 {"qpel", &xvidenc_quarterpel, CONF_TYPE_FLAG, 0, 0, 1, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
132 {"gmc", &xvidenc_gmc, CONF_TYPE_FLAG, 0, 0, 1, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
133 {"trellis", &xvidenc_trellis, CONF_TYPE_FLAG, 0, 0, 1, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
134 {"packed", &xvidenc_packed, CONF_TYPE_FLAG, 0, 0, 1, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
135 {"closed_gop", &xvidenc_closed_gop, CONF_TYPE_FLAG, 0, 0, 1, NULL},
11491
5af505348795 use the old names for 4 options
iive
parents: 11437
diff changeset
136 {"interlacing", &xvidenc_interlaced, CONF_TYPE_FLAG, 0, 0, 1, NULL},
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
137 {"cartoon", &xvidenc_cartoon, CONF_TYPE_FLAG, 0, 0, 1, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
138 {"hq_ac", &xvidenc_hqacpred, CONF_TYPE_FLAG, 0, 0, 1, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
139 {"frame_drop_ratio", &xvidenc_frame_drop_ratio, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
140 {"max_key_interval", &xvidenc_max_key_interval, CONF_TYPE_INT, CONF_MIN, 0, 0, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
141 {"greyscale", &xvidenc_greyscale, CONF_TYPE_FLAG, 0, 0, 1, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
142 {"stats", &xvidenc_stats, CONF_TYPE_FLAG, 0, 0, 1, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
143
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
144
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
145 /* section [quantizer] */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
146 {"min_iquant", &xvidenc_min_quant[0], CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
147 {"max_iquant", &xvidenc_max_quant[0], CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
148 {"min_pquant", &xvidenc_min_quant[1], CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
149 {"max_pquant", &xvidenc_max_quant[1], CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
150 {"min_bquant", &xvidenc_min_quant[2], CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
151 {"max_bquant", &xvidenc_max_quant[2], CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
152 {"quant_intra_matrix", &xvidenc_intra_matrix_file, CONF_TYPE_STRING, 0, 0, 100, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
153 {"quant_inter_matrix", &xvidenc_inter_matrix_file, CONF_TYPE_STRING, 0, 0, 100, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
154
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
155 /* section [cbr] */
11491
5af505348795 use the old names for 4 options
iive
parents: 11437
diff changeset
156 {"rc_reaction_delay_factor", &xvidenc_cbr_reaction_delay_factor, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL},
5af505348795 use the old names for 4 options
iive
parents: 11437
diff changeset
157 {"rc_averaging_period", &xvidenc_cbr_averaging_period, CONF_TYPE_INT, CONF_MIN, 0, 0, NULL},
5af505348795 use the old names for 4 options
iive
parents: 11437
diff changeset
158 {"rc_buffer", &xvidenc_cbr_buffer, CONF_TYPE_INT, CONF_MIN, 0, 0, NULL},
11437
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
159
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
160 /* section [vbr] */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
161 {"keyframe_boost", &xvidenc_vbr_keyframe_boost, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
162 {"curve_compression_high", &xvidenc_vbr_curve_compression_high, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
163 {"curve_compression_low", &xvidenc_vbr_curve_compression_low, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
164 {"overflow_control_strength", &xvidenc_vbr_overflow_control_strength, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
165 {"max_overflow_improvement", &xvidenc_vbr_max_overflow_improvement, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
166 {"max_overflow_degradation", &xvidenc_vbr_max_overflow_degradation, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
167 {"kfreduction", &xvidenc_vbr_kfreduction, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
168 {"min_key_interval", &xvidenc_vbr_min_key_interval, CONF_TYPE_INT, CONF_MIN, 0, 0, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
169 {"container_frame_overhead", &xvidenc_vbr_container_frame_overhead, CONF_TYPE_INT, CONF_MIN, 0, 0, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
170
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
171 /* Section Aspect Ratio */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
172 {"par", &xvidenc_par, CONF_TYPE_STRING, 0, 0, 0, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
173 {"par_width", &xvidenc_par_width, CONF_TYPE_INT, CONF_RANGE, 0, 255, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
174 {"par_height", &xvidenc_par_height, CONF_TYPE_INT, CONF_RANGE, 0, 255, NULL},
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
175
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
176 /* End of the config array */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
177 {NULL, 0, 0, 0, 0, 0, NULL}
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
178 };
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
179
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
180 /*****************************************************************************
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
181 * Module private data
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
182 ****************************************************************************/
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
183
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
184 typedef struct _xvid_mplayer_module_t
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
185 {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
186 /* Instance related global vars */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
187 void *instance;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
188 xvid_gbl_init_t init;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
189 xvid_enc_create_t create;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
190 xvid_enc_frame_t frame;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
191 xvid_plugin_single_t onepass;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
192 xvid_plugin_2pass1_t pass1;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
193 xvid_plugin_2pass2_t pass2;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
194
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
195 /* This data must survive local block scope, so here it is */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
196 xvid_enc_plugin_t plugins[7];
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
197 xvid_enc_zone_t zones[1];
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
198
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
199 /* MPEG4 stream buffer */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
200 muxer_stream_t *mux;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
201
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
202 /* Stats accumulators */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
203 int frames;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
204 long long sse_y;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
205 long long sse_u;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
206 long long sse_v;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
207
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
208 /* Min & Max PSNR */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
209 int min_sse_y;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
210 int min_sse_u;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
211 int min_sse_v;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
212 int max_sse_y;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
213 int max_sse_u;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
214 int max_sse_v;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
215 } xvid_mplayer_module_t;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
216
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
217 static void dispatch_settings(xvid_mplayer_module_t *mod);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
218 static int set_create_struct(xvid_mplayer_module_t *mod);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
219 static int set_frame_struct(xvid_mplayer_module_t *mod, mp_image_t *mpi);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
220 static const char *errorstring(int err);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
221
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
222 /*****************************************************************************
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
223 * Video Filter API function definitions
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
224 ****************************************************************************/
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
225
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
226 /*============================================================================
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
227 * config
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
228 *==========================================================================*/
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
229
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
230 static int
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
231 config(struct vf_instance_s* vf,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
232 int width, int height, int d_width, int d_height,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
233 unsigned int flags, unsigned int outfmt)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
234 {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
235 int err;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
236 xvid_mplayer_module_t *mod = (xvid_mplayer_module_t *)vf->priv;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
237
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
238 /* Complete the muxer initialization */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
239 mod->mux->bih->biWidth = width;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
240 mod->mux->bih->biHeight = height;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
241 mod->mux->bih->biSizeImage =
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
242 mod->mux->bih->biWidth * mod->mux->bih->biHeight * 3;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
243
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
244 /* Message the FourCC type */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
245 mp_msg(MSGT_MENCODER, MSGL_INFO,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
246 "videocodec: XviD (%dx%d fourcc=%x [%.4s])\n",
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
247 width, height, mod->mux->bih->biCompression,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
248 (char *)&mod->mux->bih->biCompression);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
249
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
250 /*--------------------------------------------------------------------
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
251 * Dispatch all module settings to XviD structures
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
252 *------------------------------------------------------------------*/
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
253
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
254 dispatch_settings(mod);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
255
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
256 /*--------------------------------------------------------------------
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
257 * Set remaining information in the xvid_enc_create_t structure
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
258 *------------------------------------------------------------------*/
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
259
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
260 if(set_create_struct(mod) == BAD)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
261 return(BAD);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
262
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
263 /*--------------------------------------------------------------------
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
264 * Encoder instance creation
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
265 *------------------------------------------------------------------*/
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
266
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
267 err = xvid_encore(NULL, XVID_ENC_CREATE, &mod->create, NULL);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
268
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
269 if(err<0) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
270 mp_msg(MSGT_MENCODER, MSGL_ERR,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
271 "xvid: xvidcore returned a '%s' error\n", errorstring(err));
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
272 return(BAD);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
273 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
274
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
275 /* Store the encoder instance into the private data */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
276 mod->instance = mod->create.handle;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
277
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
278 return(FINE);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
279 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
280
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
281 /*============================================================================
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
282 * uninit
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
283 *==========================================================================*/
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
284
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
285 static void
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
286 uninit(struct vf_instance_s* vf)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
287 {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
288
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
289 xvid_mplayer_module_t *mod = (xvid_mplayer_module_t *)vf->priv;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
290
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
291 /* Destroy xvid instance */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
292 xvid_encore(mod->instance, XVID_ENC_DESTROY, NULL, NULL);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
293
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
294 /* Display stats */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
295 if(mod->frames) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
296 int pixels;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
297
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
298 mod->sse_y /= mod->frames;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
299 mod->sse_u /= mod->frames;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
300 mod->sse_v /= mod->frames;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
301
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
302 pixels = mod->create.width*mod->create.height;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
303
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
304 #define SSE2PSNR(sse, nbpixels) \
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
305 ((!(sse)) ? 99.99f : 48.131f - 10*(double)log10((double)(sse)/(double)((nbpixels))))
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
306 mp_msg(MSGT_MENCODER, MSGL_INFO,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
307 "The value 99.99dB is a special value and represents "
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
308 "the upper range limit\n");
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
309 mp_msg(MSGT_MENCODER, MSGL_INFO,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
310 "xvid: Min PSNR y : %.2f dB, u : %.2f dB, v : %.2f dB\n",
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
311 SSE2PSNR(mod->max_sse_y, pixels),
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
312 SSE2PSNR(mod->max_sse_u, pixels/4),
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
313 SSE2PSNR(mod->max_sse_v, pixels/4));
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
314 mp_msg(MSGT_MENCODER, MSGL_INFO,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
315 "xvid: Average PSNR y : %.2f dB, u : %.2f dB, v : %.2f dB\n",
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
316 SSE2PSNR(mod->sse_y, pixels),
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
317 SSE2PSNR(mod->sse_u, pixels/4),
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
318 SSE2PSNR(mod->sse_v, pixels/4));
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
319 mp_msg(MSGT_MENCODER, MSGL_INFO,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
320 "xvid: Max PSNR y : %.2f dB, u : %.2f dB, v : %.2f dB\n",
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
321 SSE2PSNR(mod->min_sse_y, pixels),
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
322 SSE2PSNR(mod->min_sse_u, pixels/4),
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
323 SSE2PSNR(mod->min_sse_v, pixels/4));
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
324 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
325 #undef SSE2PSNR
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
326
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
327 /* ToDo: free matrices, and some string settings (quant method, matrix
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
328 * filenames...) */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
329
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
330 return;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
331 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
332
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
333 /*============================================================================
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
334 * control
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
335 *==========================================================================*/
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
336
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
337 static int
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
338 control(struct vf_instance_s* vf, int request, void* data)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
339 {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
340 return(CONTROL_UNKNOWN);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
341 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
342
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
343 /*============================================================================
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
344 * query_format
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
345 *==========================================================================*/
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
346
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
347 static int
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
348 query_format(struct vf_instance_s* vf, unsigned int fmt)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
349 {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
350 switch(fmt){
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
351 case IMGFMT_YV12:
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
352 case IMGFMT_IYUV:
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
353 case IMGFMT_I420:
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
354 return(VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
355 case IMGFMT_YUY2:
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
356 case IMGFMT_UYVY:
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
357 return(VFCAP_CSP_SUPPORTED);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
358 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
359 return(BAD);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
360 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
361
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
362 /*============================================================================
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
363 * put_image
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
364 *==========================================================================*/
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
365
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
366 static int
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
367 put_image(struct vf_instance_s* vf, mp_image_t *mpi)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
368 {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
369 int size;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
370 xvid_enc_stats_t stats;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
371 xvid_mplayer_module_t *mod = (xvid_mplayer_module_t *)vf->priv;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
372
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
373 /* Prepare the stats */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
374 memset(&stats,0,sizeof( xvid_enc_stats_t));
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
375 stats.version = XVID_VERSION;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
376
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
377 /* -------------------------------------------------------------------
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
378 * Set remaining information in the xvid_enc_frame_t structure
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
379 * NB: all the other struct members were initialized by
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
380 * dispatch_settings
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
381 * -----------------------------------------------------------------*/
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
382
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
383 if(set_frame_struct(mod, mpi) == BAD)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
384 return(BAD);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
385
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
386 /* -------------------------------------------------------------------
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
387 * Encode the frame
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
388 * ---------------------------------------------------------------- */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
389
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
390 size = xvid_encore(mod->instance, XVID_ENC_ENCODE, &mod->frame, &stats);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
391
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
392 /* Analyse the returned value */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
393 if(size<0) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
394 mp_msg(MSGT_MENCODER, MSGL_ERR,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
395 "xvid: xvidcore returned a '%s' error\n", errorstring(size));
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
396 return(BAD);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
397 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
398
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
399 /* If size is == 0, we're done with that frame */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
400 if(size == 0) return(FINE);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
401
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
402 /* Did xvidcore returned stats about an ecoded frame ? (asynchrone) */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
403 if(xvidenc_stats && stats.type > 0) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
404 mod->frames++;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
405 mod->sse_y += stats.sse_y;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
406 mod->sse_u += stats.sse_u;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
407 mod->sse_v += stats.sse_v;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
408
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
409 if(mod->min_sse_y > stats.sse_y) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
410 mod->min_sse_y = stats.sse_y;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
411 mod->min_sse_u = stats.sse_u;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
412 mod->min_sse_v = stats.sse_v;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
413 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
414
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
415 if(mod->max_sse_y < stats.sse_y) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
416 mod->max_sse_y = stats.sse_y;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
417 mod->max_sse_u = stats.sse_u;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
418 mod->max_sse_v = stats.sse_v;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
419 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
420 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
421
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
422 /* xvidcore outputed bitstream -- mux it */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
423 muxer_write_chunk(mod->mux,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
424 size,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
425 (mod->frame.out_flags & XVID_KEYFRAME)?0x10:0);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
426
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
427 return(FINE);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
428 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
429
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
430 /*============================================================================
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
431 * vf_open
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
432 *==========================================================================*/
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
433
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
434 static int
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
435 vf_open(vf_instance_t *vf, char* args)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
436 {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
437 xvid_mplayer_module_t *mod;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
438 xvid_gbl_init_t xvid_gbl_init;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
439 xvid_gbl_info_t xvid_gbl_info;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
440
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
441 /* Setting libmpcodec module API pointers */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
442 vf->config = config;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
443 vf->control = control;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
444 vf->uninit = uninit;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
445 vf->query_format = query_format;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
446 vf->put_image = put_image;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
447
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
448 /* Allocate the private part of the codec module */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
449 vf->priv = malloc(sizeof(xvid_mplayer_module_t));
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
450 mod = (xvid_mplayer_module_t*)vf->priv;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
451
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
452 if(mod == NULL) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
453 mp_msg(MSGT_MENCODER,MSGL_ERR,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
454 "xvid: memory allocation failure (private data)\n");
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
455 return(BAD);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
456 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
457
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
458 /* Initialize the module to zeros */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
459 memset(mod, 0, sizeof(xvid_mplayer_module_t));
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
460 mod->min_sse_y = mod->min_sse_u = mod->min_sse_v = INT_MAX;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
461 mod->max_sse_y = mod->max_sse_u = mod->max_sse_v = INT_MIN;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
462
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
463 /* Bind the Muxer */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
464 mod->mux = (muxer_stream_t*)args;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
465
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
466 /* Initialize muxer BITMAP header */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
467 mod->mux->bih = malloc(sizeof(BITMAPINFOHEADER));
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
468
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
469 if(mod->mux->bih == NULL) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
470 mp_msg(MSGT_MENCODER,MSGL_ERR,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
471 "xvid: memory allocation failure (BITMAP header)\n");
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
472 return(BAD);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
473 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
474
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
475 mod->mux->bih->biSize = sizeof(BITMAPINFOHEADER);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
476 mod->mux->bih->biWidth = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
477 mod->mux->bih->biHeight = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
478 mod->mux->bih->biPlanes = 1;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
479 mod->mux->bih->biBitCount = 24;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
480 mod->mux->bih->biCompression = mmioFOURCC('X','V','I','D');
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
481
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
482 /* Retrieve information about the host XviD library */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
483 memset(&xvid_gbl_info, 0, sizeof(xvid_gbl_info_t));
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
484 xvid_gbl_info.version = XVID_VERSION;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
485
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
486 if (xvid_global(NULL, XVID_GBL_INFO, &xvid_gbl_info, NULL) < 0) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
487 mp_msg(MSGT_MENCODER,MSGL_INFO, "xvid: could not get information about the library\n");
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
488 } else {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
489 mp_msg(MSGT_MENCODER,MSGL_INFO, "xvid: using library version %d.%d.%d (build %s)\n",
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
490 XVID_VERSION_MAJOR(xvid_gbl_info.actual_version),
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
491 XVID_VERSION_MINOR(xvid_gbl_info.actual_version),
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
492 XVID_VERSION_PATCH(xvid_gbl_info.actual_version),
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
493 xvid_gbl_info.build);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
494 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
495
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
496 /* Initialize the xvid_gbl_init structure */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
497 memset(&xvid_gbl_init, 0, sizeof(xvid_gbl_init_t));
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
498 xvid_gbl_init.version = XVID_VERSION;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
499
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
500 /* Initialize the xvidcore library */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
501 if (xvid_global(NULL, XVID_GBL_INIT, &xvid_gbl_init, NULL) < 0) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
502 mp_msg(MSGT_MENCODER,MSGL_ERR, "xvid: initialisation failure\n");
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
503 return(BAD);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
504 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
505
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
506 return(FINE);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
507 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
508
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
509 /*****************************************************************************
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
510 * Helper functions
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
511 ****************************************************************************/
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
512
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
513 static void *read_matrix(unsigned char *filename);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
514
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
515 static void dispatch_settings(xvid_mplayer_module_t *mod)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
516 {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
517 xvid_enc_create_t *create = &mod->create;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
518 xvid_enc_frame_t *frame = &mod->frame;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
519 xvid_plugin_single_t *onepass = &mod->onepass;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
520 xvid_plugin_2pass2_t *pass2 = &mod->pass2;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
521
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
522 const int motion_presets[7] =
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
523 {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
524 0,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
525 0,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
526 0,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
527 0,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
528 XVID_ME_HALFPELREFINE16,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
529 XVID_ME_HALFPELREFINE16 | XVID_ME_ADVANCEDDIAMOND16,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
530 XVID_ME_HALFPELREFINE16 | XVID_ME_EXTSEARCH16 |
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
531 XVID_ME_HALFPELREFINE8 | XVID_ME_USESQUARES16
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
532 };
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
533
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
534
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
535 /* -------------------------------------------------------------------
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
536 * Dispatch all settings having an impact on the "create" structure
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
537 * This includes plugins as they are passed to encore through the
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
538 * create structure
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
539 * -----------------------------------------------------------------*/
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
540
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
541 /* -------------------------------------------------------------------
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
542 * The create structure
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
543 * ---------------------------------------------------------------- */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
544
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
545 create->global = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
546
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
547 if(xvidenc_packed)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
548 create->global |= XVID_GLOBAL_PACKED;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
549
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
550 if(xvidenc_closed_gop)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
551 create->global |= XVID_GLOBAL_CLOSED_GOP;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
552
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
553 if(xvidenc_stats)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
554 create->global |= XVID_GLOBAL_EXTRASTATS_ENABLE;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
555
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
556 create->num_zones = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
557 create->zones = NULL;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
558 create->num_plugins = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
559 create->plugins = NULL;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
560 create->num_threads = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
561 create->max_bframes = xvidenc_max_bframes;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
562 create->bquant_ratio = xvidenc_bquant_ratio;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
563 create->bquant_offset = xvidenc_bquant_offset;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
564 create->max_key_interval = xvidenc_max_key_interval;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
565 create->frame_drop_ratio = xvidenc_frame_drop_ratio;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
566 create->min_quant[0] = xvidenc_min_quant[0];
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
567 create->min_quant[1] = xvidenc_min_quant[1];
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
568 create->min_quant[2] = xvidenc_min_quant[2];
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
569 create->max_quant[0] = xvidenc_max_quant[0];
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
570 create->max_quant[1] = xvidenc_max_quant[1];
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
571 create->max_quant[2] = xvidenc_max_quant[2];
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
572
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
573
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
574 /* -------------------------------------------------------------------
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
575 * The single pass plugin
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
576 * ---------------------------------------------------------------- */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
577
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
578 onepass->bitrate = xvidenc_bitrate;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
579 onepass->reaction_delay_factor = xvidenc_cbr_reaction_delay_factor;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
580 onepass->averaging_period = xvidenc_cbr_averaging_period;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
581 onepass->buffer = xvidenc_cbr_buffer;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
582
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
583 /* -------------------------------------------------------------------
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
584 * The pass2 plugin
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
585 * ---------------------------------------------------------------- */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
586
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
587 pass2->keyframe_boost = xvidenc_vbr_keyframe_boost;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
588 pass2->overflow_control_strength = xvidenc_vbr_overflow_control_strength;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
589 pass2->curve_compression_high = xvidenc_vbr_curve_compression_high;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
590 pass2->curve_compression_low = xvidenc_vbr_curve_compression_low;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
591 pass2->max_overflow_improvement = xvidenc_vbr_max_overflow_improvement;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
592 pass2->max_overflow_degradation = xvidenc_vbr_max_overflow_degradation;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
593 pass2->kfreduction = xvidenc_vbr_kfreduction;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
594 pass2->min_key_interval = xvidenc_vbr_min_key_interval;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
595 pass2->container_frame_overhead = xvidenc_vbr_container_frame_overhead;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
596
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
597 /* -------------------------------------------------------------------
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
598 * The frame structure
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
599 * ---------------------------------------------------------------- */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
600 frame->vol_flags = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
601 frame->vop_flags = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
602 frame->motion = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
603
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
604 frame->vop_flags |= XVID_VOP_HALFPEL;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
605 frame->motion |= motion_presets[xvidenc_motion];
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
606
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
607 if(xvidenc_stats)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
608 frame->vol_flags |= XVID_VOL_EXTRASTATS;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
609
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
610 if(xvidenc_greyscale)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
611 frame->vop_flags |= XVID_VOP_GREYSCALE;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
612
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
613 if(xvidenc_cartoon) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
614 frame->vop_flags |= XVID_VOP_CARTOON;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
615 frame->motion |= XVID_ME_DETECT_STATIC_MOTION;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
616 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
617
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
618 if(xvidenc_intra_matrix_file != NULL) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
619 frame->quant_intra_matrix = (unsigned char*)read_matrix(xvidenc_intra_matrix_file);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
620 if(frame->quant_intra_matrix != NULL) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
621 fprintf(stderr, "xvid: Loaded Intra matrix (switching to mpeg quantization type)\n");
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
622 if(xvidenc_quant_method) free(xvidenc_quant_method);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
623 xvidenc_quant_method = strdup("mpeg");
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
624 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
625 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
626 if(xvidenc_inter_matrix_file != NULL) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
627 frame->quant_inter_matrix = read_matrix(xvidenc_inter_matrix_file);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
628 if(frame->quant_inter_matrix) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
629 fprintf(stderr, "\nxvid: Loaded Inter matrix (switching to mpeg quantization type)\n");
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
630 if(xvidenc_quant_method) free(xvidenc_quant_method);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
631 xvidenc_quant_method = strdup("mpeg");
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
632 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
633 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
634 if(xvidenc_quant_method != NULL && !strcasecmp(xvidenc_quant_method, "mpeg")) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
635 frame->vol_flags |= XVID_VOL_MPEGQUANT;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
636 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
637 if(xvidenc_quarterpel) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
638 frame->vol_flags |= XVID_VOL_QUARTERPEL;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
639 frame->motion |= XVID_ME_QUARTERPELREFINE16;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
640 frame->motion |= XVID_ME_QUARTERPELREFINE8;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
641 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
642 if(xvidenc_gmc) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
643 frame->vol_flags |= XVID_VOL_GMC;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
644 frame->motion |= XVID_ME_GME_REFINE;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
645 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
646 if(xvidenc_interlaced) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
647 frame->vol_flags |= XVID_VOL_INTERLACING;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
648 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
649 if(xvidenc_trellis) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
650 frame->vop_flags |= XVID_VOP_TRELLISQUANT;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
651 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
652 if(xvidenc_hqacpred) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
653 frame->vop_flags |= XVID_VOP_HQACPRED;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
654 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
655 if(xvidenc_motion > 4) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
656 frame->vop_flags |= XVID_VOP_INTER4V;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
657 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
658 if(xvidenc_chromame) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
659 frame->motion |= XVID_ME_CHROMA_PVOP;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
660 frame->motion |= XVID_ME_CHROMA_BVOP;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
661 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
662 if(xvidenc_vhq >= 1) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
663 frame->vop_flags |= XVID_VOP_MODEDECISION_RD;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
664 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
665 if(xvidenc_vhq >= 2) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
666 frame->motion |= XVID_ME_HALFPELREFINE16_RD;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
667 frame->motion |= XVID_ME_QUARTERPELREFINE16_RD;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
668 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
669 if(xvidenc_vhq >= 3) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
670 frame->motion |= XVID_ME_HALFPELREFINE8_RD;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
671 frame->motion |= XVID_ME_QUARTERPELREFINE8_RD;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
672 frame->motion |= XVID_ME_CHECKPREDICTION_RD;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
673 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
674 if(xvidenc_vhq >= 4) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
675 frame->motion |= XVID_ME_EXTSEARCH_RD;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
676 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
677
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
678 /* motion level == 0 means no motion search which is equivalent to
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
679 * intra coding only */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
680 if(xvidenc_motion == 0) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
681 frame->type = XVID_TYPE_IVOP;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
682 } else {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
683 frame->type = XVID_TYPE_AUTO;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
684 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
685
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
686 frame->bframe_threshold = xvidenc_bframe_threshold;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
687
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
688 frame->par = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
689 if(xvidenc_par != NULL) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
690 if(strcasecmp(xvidenc_par, "pal43") == 0)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
691 frame->par = XVID_PAR_43_PAL;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
692 if(strcasecmp(xvidenc_par, "pal169") == 0)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
693 frame->par = XVID_PAR_169_PAL;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
694 if(strcasecmp(xvidenc_par, "ntsc43") == 0)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
695 frame->par = XVID_PAR_43_NTSC;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
696 if(strcasecmp(xvidenc_par, "ntsc169") == 0)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
697 frame->par = XVID_PAR_169_NTSC;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
698 if(strcasecmp(xvidenc_par, "ext") == 0)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
699 frame->par = XVID_PAR_EXT;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
700 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
701 if(frame->par == 0) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
702 frame->par = XVID_PAR_11_VGA;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
703 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
704 if(frame->par == XVID_PAR_EXT) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
705 if(xvidenc_par_width)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
706 frame->par_width = xvidenc_par_width;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
707 else
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
708 frame->par_width = 1;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
709
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
710 if(xvidenc_par_height)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
711 frame->par_height = xvidenc_par_height;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
712 else
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
713 frame->par_height = 1;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
714 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
715
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
716 return;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
717 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
718
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
719 static int set_create_struct(xvid_mplayer_module_t *mod)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
720 {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
721 int pass;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
722 xvid_enc_create_t *create = &mod->create;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
723
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
724 /* Most of the structure is initialized by dispatch settings, only a
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
725 * few things are missing */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
726 create->version = XVID_VERSION;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
727
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
728 /* Width and Height */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
729 create->width = mod->mux->bih->biWidth;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
730 create->height = mod->mux->bih->biHeight;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
731
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
732 /* FPS */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
733 create->fincr = mod->mux->h.dwScale;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
734 create->fbase = mod->mux->h.dwRate;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
735
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
736 /* Encodings zones */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
737 memset(mod->zones, 0, sizeof(mod->zones));
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
738 create->zones = mod->zones;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
739 create->num_zones = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
740
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
741 /* Plugins */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
742 memset(mod->plugins, 0, sizeof(mod->plugins));
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
743 create->plugins = mod->plugins;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
744 create->num_plugins = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
745
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
746 /* -------------------------------------------------------------------
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
747 * Initialize and bind the right rate controller plugin
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
748 * ---------------------------------------------------------------- */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
749
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
750 /* First we try to sort out configuration conflicts */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
751 if(xvidenc_quantizer != 0 && (xvidenc_bitrate || xvidenc_pass)) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
752 mp_msg(MSGT_MENCODER, MSGL_ERR,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
753 "xvid: you can't mix Fixed Quantizer Rate Control"
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
754 " with other Rate Control mechanisms\n");
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
755 return(BAD);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
756 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
757
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
758 if(xvidenc_bitrate != 0 && xvidenc_pass == 1) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
759 mp_msg(MSGT_MENCODER, MSGL_ERR,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
760 "xvid: bitrate setting is ignored during first pass\n");
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
761 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
762
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
763 /* Sort out which sort of pass we are supposed to do
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
764 * pass == 1<<0 CBR
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
765 * pass == 1<<1 Two pass first pass
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
766 * pass == 1<<2 Two pass second pass
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
767 * pass == 1<<3 Constant quantizer
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
768 */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
769 #define MODE_CBR (1<<0)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
770 #define MODE_2PASS1 (1<<1)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
771 #define MODE_2PASS2 (1<<2)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
772 #define MODE_QUANT (1<<3)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
773
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
774 pass = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
775
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
776 if(xvidenc_bitrate != 0 && xvidenc_pass == 0)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
777 pass |= MODE_CBR;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
778
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
779 if(xvidenc_pass == 1)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
780 pass |= MODE_2PASS1;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
781
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
782 if(xvidenc_bitrate != 0 && xvidenc_pass == 2)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
783 pass |= MODE_2PASS2;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
784
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
785 if(xvidenc_quantizer != 0 && xvidenc_pass == 0)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
786 pass |= MODE_QUANT;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
787
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
788 /* We must be in at least one RC mode */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
789 if(pass == 0) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
790 mp_msg(MSGT_MENCODER, MSGL_ERR,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
791 "xvid: you must specify one or a valid combination of "
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
792 "'bitrate', 'pass', 'quantizer' settings\n");
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
793 return(BAD);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
794 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
795
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
796 /* Sanity checking */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
797 if(pass != MODE_CBR && pass != MODE_QUANT &&
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
798 pass != MODE_2PASS1 && pass != MODE_2PASS2) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
799 mp_msg(MSGT_MENCODER, MSGL_ERR,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
800 "xvid: this code should not be reached - fill a bug "
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
801 "report\n");
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
802 return(BAD);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
803 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
804
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
805 /* This is a single pass encoding: either a CBR pass or a constant
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
806 * quantizer pass */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
807 if(pass == MODE_CBR || pass == MODE_QUANT) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
808 xvid_plugin_single_t *onepass = &mod->onepass;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
809
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
810 /* There is not much left to initialize after dispatch settings */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
811 onepass->version = XVID_VERSION;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
812 onepass->bitrate = xvidenc_bitrate*1000;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
813
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
814 /* Quantizer mode uses the same plugin, we have only to define
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
815 * a constant quantizer zone beginning at frame 0 */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
816 if(pass == MODE_QUANT) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
817 int base, incr;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
818
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
819 base = 100;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
820 incr = (int)xvidenc_quantizer*base;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
821
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
822 create->zones[create->num_zones].mode = XVID_ZONE_QUANT;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
823 create->zones[create->num_zones].frame = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
824 create->zones[create->num_zones].base = base;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
825 create->zones[create->num_zones].increment = incr;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
826 create->num_zones++;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
827
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
828 mp_msg(MSGT_MENCODER, MSGL_INFO,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
829 "xvid: Fixed Quant Rate Control -- quantizer=%d/%d=%2.2f\n",
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
830 incr,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
831 base,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
832 (float)(incr)/(float)(base));
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
833
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
834 } else {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
835 mp_msg(MSGT_MENCODER, MSGL_INFO,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
836 "xvid: CBR Rate Control -- bitrate=%dkbit/s\n",
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
837 xvidenc_bitrate);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
838 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
839
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
840 create->plugins[create->num_plugins].func = xvid_plugin_single;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
841 create->plugins[create->num_plugins].param = onepass;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
842 create->num_plugins++;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
843 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
844
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
845 /* This is the first pass of a Two pass process */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
846 if(pass == MODE_2PASS1) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
847 xvid_plugin_2pass1_t *pass1 = &mod->pass1;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
848
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
849 /* There is not much to initialize for this plugin */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
850 pass1->version = XVID_VERSION;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
851 pass1->filename = XVID_FIRST_PASS_FILENAME;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
852
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
853 create->plugins[create->num_plugins].func = xvid_plugin_2pass1;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
854 create->plugins[create->num_plugins].param = pass1;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
855 create->num_plugins++;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
856
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
857 mp_msg(MSGT_MENCODER, MSGL_INFO,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
858 "xvid: 2Pass Rate Control -- 1st pass\n");
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
859 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
860
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
861 /* This is the second pass of a Two pass process */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
862 if(pass == MODE_2PASS2) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
863 xvid_plugin_2pass2_t *pass2 = &mod->pass2;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
864
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
865 /* There is not much left to initialize after dispatch settings */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
866 pass2->version = XVID_VERSION;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
867 pass2->filename = XVID_FIRST_PASS_FILENAME;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
868
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
869 /* Positive bitrate values are bitrates as usual but if the
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
870 * value is negative it is considered as being a total size
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
871 * to reach (in kilobytes) */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
872 if(xvidenc_bitrate > 0) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
873 pass2->bitrate = xvidenc_bitrate*1000;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
874 mp_msg(MSGT_MENCODER, MSGL_INFO,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
875 "xvid: 2Pass Rate Control -- 2nd pass -- bitrate=%dkbit/s\n",
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
876 xvidenc_bitrate);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
877 } else {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
878 pass2->bitrate = xvidenc_bitrate;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
879 mp_msg(MSGT_MENCODER, MSGL_INFO,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
880 "xvid: 2Pass Rate Control -- 2nd pass -- total size=%dkB\n",
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
881 -xvidenc_bitrate);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
882 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
883
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
884 create->plugins[create->num_plugins].func = xvid_plugin_2pass2;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
885 create->plugins[create->num_plugins].param = pass2;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
886 create->num_plugins++;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
887 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
888
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
889 return(FINE);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
890 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
891
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
892 static int set_frame_struct(xvid_mplayer_module_t *mod, mp_image_t *mpi)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
893 {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
894 xvid_enc_frame_t *frame = &mod->frame;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
895
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
896 /* Most of the initialization is done during dispatch_settings */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
897 frame->version = XVID_VERSION;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
898
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
899 /* Bind output buffer */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
900 frame->bitstream = mod->mux->buffer;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
901 frame->length = -1;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
902
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
903 /* Frame format */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
904 switch(mpi->imgfmt) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
905 case IMGFMT_YV12:
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
906 case IMGFMT_IYUV:
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
907 case IMGFMT_I420:
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
908 frame->input.csp = XVID_CSP_USER;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
909 break;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
910 case IMGFMT_YUY2:
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
911 frame->input.csp = XVID_CSP_YUY2;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
912 break;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
913 case IMGFMT_UYVY:
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
914 frame->input.csp = XVID_CSP_UYVY;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
915 break;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
916 default:
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
917 mp_msg(MSGT_MENCODER, MSGL_ERR,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
918 "xvid: unsupported picture format (%s)!\n",
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
919 vo_format_name(mpi->imgfmt));
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
920 return(BAD);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
921 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
922
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
923 /* Bind source frame */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
924 frame->input.plane[0] = mpi->planes[0];
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
925 frame->input.plane[1] = mpi->planes[1];
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
926 frame->input.plane[2] = mpi->planes[2];
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
927 frame->input.stride[0] = mpi->stride[0];
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
928 frame->input.stride[1] = mpi->stride[1];
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
929 frame->input.stride[2] = mpi->stride[2];
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
930
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
931 /* Force the right quantizer -- It is internally managed by RC
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
932 * plugins */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
933 frame->quant = 0;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
934
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
935 return(FINE);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
936 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
937
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
938 static void *read_matrix(unsigned char *filename)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
939 {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
940 int i;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
941 unsigned char *matrix;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
942 FILE *input;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
943
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
944 /* Allocate matrix space */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
945 if((matrix = malloc(64*sizeof(unsigned char))) == NULL)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
946 return(NULL);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
947
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
948 /* Open the matrix file */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
949 if((input = fopen(filename, "rb")) == NULL) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
950 fprintf(stderr,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
951 "xvid: Error opening the matrix file %s\n",
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
952 filename);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
953 free(matrix);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
954 return(NULL);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
955 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
956
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
957 /* Read the matrix */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
958 for(i=0; i<64; i++) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
959
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
960 int value;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
961
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
962 /* If fscanf fails then get out of the loop */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
963 if(fscanf(input, "%d", &value) != 1) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
964 fprintf(stderr,
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
965 "xvid: Error reading the matrix file %s\n",
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
966 filename);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
967 free(matrix);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
968 fclose(input);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
969 return(NULL);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
970 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
971
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
972 /* Clamp the value to safe range */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
973 value = (value< 1)?1 :value;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
974 value = (value>255)?255:value;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
975 matrix[i] = value;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
976 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
977
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
978 /* Fills the rest with 1 */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
979 while(i<64) matrix[i++] = 1;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
980
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
981 /* We're done */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
982 fclose(input);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
983
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
984 return(matrix);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
985
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
986 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
987
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
988 static const char *errorstring(int err)
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
989 {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
990 char *error;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
991 switch(err) {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
992 case XVID_ERR_FAIL:
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
993 error = "General fault";
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
994 break;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
995 case XVID_ERR_MEMORY:
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
996 error = "Memory allocation error";
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
997 break;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
998 case XVID_ERR_FORMAT:
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
999 error = "File format error";
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1000 break;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1001 case XVID_ERR_VERSION:
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1002 error = "Structure version not supported";
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1003 break;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1004 case XVID_ERR_END:
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1005 error = "End of stream reached";
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1006 break;
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1007 default:
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1008 error = "Unknown";
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1009 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1010
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1011 return((const char *)error);
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1012 }
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1013
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1014 /*****************************************************************************
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1015 * Module structure definition
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1016 ****************************************************************************/
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1017
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1018 vf_info_t ve_info_xvid = {
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1019 "XviD 1.0 encoder",
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1020 "xvid",
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1021 "Marco Belli <elcabesa@inwind.it>, Edouard Gomez <ed.gomez@free.fr>",
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1022 "No comment",
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1023 vf_open
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1024 };
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1025
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1026
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1027 #endif /* HAVE_XVID4 */
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1028
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1029 /* Please do not change that tag comment.
7826e4e376c7 XviD Api4 driver from http://ed.gomez.free.fr/
iive
parents:
diff changeset
1030 * arch-tag: 42ccc257-0548-4a3e-9617-2876c4e8ac88 mplayer xvid encoder module */