Parent Directory | Revision Log
Revision 1.1.2.9 - (view) (download)
1 : | suxen_drol | 1.1.2.1 | /****************************************************************************** |
2 : | * | ||
3 : | edgomez | 1.1.2.5 | * XviD Bit Rate Controller Library |
4 : | * - VBR 2 pass bitrate controler implementation - | ||
5 : | suxen_drol | 1.1.2.1 | * |
6 : | edgomez | 1.1.2.5 | * Copyright (C) 2002-2003 Edouard Gomez <ed.gomez@free.fr> |
7 : | suxen_drol | 1.1.2.1 | * |
8 : | edgomez | 1.1.2.5 | * The curve treatment algorithm is the one implemented by Foxer <email?> and |
9 : | * Dirk Knop <dknop@gwdg.de> for the XviD vfw dynamic library. | ||
10 : | suxen_drol | 1.1.2.1 | * |
11 : | edgomez | 1.1.2.5 | * This program is free software; you can redistribute it and/or modify |
12 : | * it under the terms of the GNU General Public License as published by | ||
13 : | * the Free Software Foundation; either version 2 of the License, or | ||
14 : | * (at your option) any later version. | ||
15 : | suxen_drol | 1.1.2.1 | * |
16 : | edgomez | 1.1.2.5 | * This program is distributed in the hope that it will be useful, |
17 : | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
18 : | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
19 : | * GNU General Public License for more details. | ||
20 : | suxen_drol | 1.1.2.1 | * |
21 : | edgomez | 1.1.2.5 | * You should have received a copy of the GNU General Public License |
22 : | * along with this program; if not, write to the Free Software | ||
23 : | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
24 : | suxen_drol | 1.1.2.1 | * |
25 : | syskin | 1.1.2.9 | * $Id: plugin_2pass1.c,v 1.1.2.8 2003/11/09 20:49:21 edgomez Exp $ |
26 : | suxen_drol | 1.1.2.1 | * |
27 : | *****************************************************************************/ | ||
28 : | |||
29 : | #include <stdio.h> | ||
30 : | |||
31 : | #include "../xvid.h" | ||
32 : | #include "../image/image.h" | ||
33 : | |||
34 : | |||
35 : | /* context struct */ | ||
36 : | typedef struct | ||
37 : | { | ||
38 : | FILE * stat_file; | ||
39 : | suxen_drol | 1.1.2.3 | |
40 : | double fq_error; | ||
41 : | suxen_drol | 1.1.2.1 | } rc_2pass1_t; |
42 : | |||
43 : | |||
44 : | |||
45 : | static int rc_2pass1_create(xvid_plg_create_t * create, rc_2pass1_t ** handle) | ||
46 : | { | ||
47 : | xvid_plugin_2pass1_t * param = (xvid_plugin_2pass1_t *)create->param; | ||
48 : | rc_2pass1_t * rc; | ||
49 : | |||
50 : | /* check filename */ | ||
51 : | edgomez | 1.1.2.6 | if ((param->filename == NULL) || |
52 : | (param->filename != NULL && param->filename[0] == '\0')) | ||
53 : | suxen_drol | 1.1.2.1 | return XVID_ERR_FAIL; |
54 : | |||
55 : | /* allocate context struct */ | ||
56 : | if((rc = malloc(sizeof(rc_2pass1_t))) == NULL) | ||
57 : | return(XVID_ERR_MEMORY); | ||
58 : | |||
59 : | edgomez | 1.1.2.7 | /* Initialize safe defaults for 2pass 1 */ |
60 : | suxen_drol | 1.1.2.1 | rc->stat_file = NULL; |
61 : | |||
62 : | /* Open the 1st pass file */ | ||
63 : | edgomez | 1.1.2.8 | if((rc->stat_file = fopen(param->filename, "w+b")) == NULL) |
64 : | suxen_drol | 1.1.2.1 | return(XVID_ERR_FAIL); |
65 : | suxen_drol | 1.1.2.3 | |
66 : | suxen_drol | 1.1.2.1 | /* |
67 : | * The File Header | ||
68 : | */ | ||
69 : | edgomez | 1.1.2.8 | fprintf(rc->stat_file, "# XviD 2pass stat file (core version %d.%d.%d)\n", |
70 : | XVID_VERSION_MAJOR(XVID_VERSION), | ||
71 : | XVID_VERSION_MINOR(XVID_VERSION), | ||
72 : | XVID_VERSION_PATCH(XVID_VERSION)); | ||
73 : | fprintf(rc->stat_file, "# Please do not modify this file\n\n"); | ||
74 : | edgomez | 1.1.2.7 | |
75 : | suxen_drol | 1.1.2.3 | rc->fq_error = 0; |
76 : | suxen_drol | 1.1.2.1 | |
77 : | *handle = rc; | ||
78 : | return(0); | ||
79 : | } | ||
80 : | |||
81 : | |||
82 : | static int rc_2pass1_destroy(rc_2pass1_t * rc, xvid_plg_destroy_t * destroy) | ||
83 : | { | ||
84 : | fclose(rc->stat_file); | ||
85 : | free(rc); | ||
86 : | return(0); | ||
87 : | } | ||
88 : | |||
89 : | |||
90 : | static int rc_2pass1_before(rc_2pass1_t * rc, xvid_plg_data_t * data) | ||
91 : | { | ||
92 : | suxen_drol | 1.1.2.3 | if (data->quant <= 0) { |
93 : | if (data->zone && data->zone->mode == XVID_ZONE_QUANT) { | ||
94 : | rc->fq_error += (double)data->zone->increment / (double)data->zone->base; | ||
95 : | data->quant = (int)rc->fq_error; | ||
96 : | rc->fq_error -= data->quant; | ||
97 : | edgomez | 1.1.2.7 | |
98 : | suxen_drol | 1.1.2.3 | }else { |
99 : | data->quant = 2; | ||
100 : | } | ||
101 : | } | ||
102 : | suxen_drol | 1.1.2.1 | return 0; |
103 : | } | ||
104 : | |||
105 : | |||
106 : | static int rc_2pass1_after(rc_2pass1_t * rc, xvid_plg_data_t * data) | ||
107 : | { | ||
108 : | char type; | ||
109 : | |||
110 : | /* Frame type in ascii I/P/B */ | ||
111 : | switch(data->type) { | ||
112 : | case XVID_TYPE_IVOP: | ||
113 : | type = 'i'; | ||
114 : | break; | ||
115 : | case XVID_TYPE_PVOP: | ||
116 : | type = 'p'; | ||
117 : | break; | ||
118 : | case XVID_TYPE_BVOP: | ||
119 : | type = 'b'; | ||
120 : | break; | ||
121 : | case XVID_TYPE_SVOP: | ||
122 : | type = 's'; | ||
123 : | break; | ||
124 : | default: /* Should not go here */ | ||
125 : | return(XVID_ERR_FAIL); | ||
126 : | } | ||
127 : | |||
128 : | /* write the resulting statistics */ | ||
129 : | |||
130 : | fprintf(rc->stat_file, "%c %d %d %d %d %d\n", | ||
131 : | type, | ||
132 : | data->quant, | ||
133 : | data->kblks, | ||
134 : | data->mblks, | ||
135 : | suxen_drol | 1.1.2.2 | data->ublks, |
136 : | data->length); | ||
137 : | suxen_drol | 1.1.2.1 | |
138 : | return(0); | ||
139 : | } | ||
140 : | |||
141 : | |||
142 : | |||
143 : | int xvid_plugin_2pass1(void * handle, int opt, void * param1, void * param2) | ||
144 : | { | ||
145 : | switch(opt) | ||
146 : | { | ||
147 : | case XVID_PLG_INFO : | ||
148 : | syskin | 1.1.2.9 | case XVID_PLG_FRAME : |
149 : | suxen_drol | 1.1.2.1 | return 0; |
150 : | |||
151 : | case XVID_PLG_CREATE : | ||
152 : | return rc_2pass1_create((xvid_plg_create_t*)param1, param2); | ||
153 : | |||
154 : | case XVID_PLG_DESTROY : | ||
155 : | return rc_2pass1_destroy((rc_2pass1_t*)handle, (xvid_plg_destroy_t*)param1); | ||
156 : | |||
157 : | case XVID_PLG_BEFORE : | ||
158 : | return rc_2pass1_before((rc_2pass1_t*)handle, (xvid_plg_data_t*)param1); | ||
159 : | |||
160 : | case XVID_PLG_AFTER : | ||
161 : | return rc_2pass1_after((rc_2pass1_t*)handle, (xvid_plg_data_t*)param1); | ||
162 : | } | ||
163 : | |||
164 : | return XVID_ERR_FAIL; | ||
165 : | } |
No admin address has been configured | ViewVC Help |
Powered by ViewVC 1.0.4 |