Mercurial > mplayer.hg
annotate xvid_vbr.c @ 7331:7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
author | kmkaplan |
---|---|
date | Mon, 09 Sep 2002 11:47:54 +0000 |
parents | |
children | ef1daba63c30 |
rev | line source |
---|---|
7331
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1 /****************************************************************************** |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
2 * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
3 * XviD VBR Library |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
4 * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
5 * Copyright (C) 2002 Edouard Gomez <ed.gomez@wanadoo.fr> |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
6 * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
7 * The curve treatment algorithm is based on work done by Foxer <email?> and |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
8 * Dirk Knop <dknop@gwdg.de> for the XviD vfw dynamic library. |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
9 * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
10 * This program is free software; you can redistribute it and/or modify |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
11 * it under the terms of the GNU General Public License as published by |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
12 * the Free Software Foundation; either version 2 of the License, or |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
13 * (at your option) any later version. |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
14 * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
15 * This program is distributed in the hope that it will be useful, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
18 * GNU General Public License for more details. |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
19 * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
20 * You should have received a copy of the GNU General Public License |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
21 * along with this program; if not, write to the Free Software |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
23 * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
24 *****************************************************************************/ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
25 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
26 /* Standard Headers */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
27 #include <stdio.h> |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
28 #include <string.h> |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
29 #include <fcntl.h> |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
30 #include <stdlib.h> |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
31 #include <math.h> |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
32 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
33 /* Local headers */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
34 #include "xvid_vbr.h" |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
35 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
36 /****************************************************************************** |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
37 * Build time constants |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
38 *****************************************************************************/ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
39 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
40 /* |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
41 * Portability note |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
42 * Perhaps the msvc headers define Pi with another constant name |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
43 */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
44 #define DEG2RAD (M_PI / 180.0) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
45 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
46 /* Defaults settings will be computed with the help of these constants */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
47 #define DEFAULT_DESIRED_SIZE 700 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
48 #define DEFAULT_AUDIO_BITRATE 128 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
49 #define DEFAULT_MOVIE_LENGTH 2 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
50 #define DEFAULT_TWOPASS_BOOST 150 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
51 #define DEFAULT_FPS 25.0f |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
52 #define DEFAULT_CREDITS_SIZE 10 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
53 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
54 #define DEFAULT_XVID_DBG_FILE "xvid.dbg" |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
55 #define DEFAULT_XVID_STATS_FILE "xvid.stats" |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
56 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
57 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
58 /****************************************************************************** |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
59 * Local prototypes |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
60 *****************************************************************************/ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
61 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
62 /* Sub vbrInit cases functions */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
63 static vbr_init_function vbr_init_dummy; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
64 static vbr_init_function vbr_init_2pass1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
65 static vbr_init_function vbr_init_2pass2; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
66 static vbr_init_function vbr_init_fixedquant; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
67 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
68 /* Sub vbrGetQuant cases functions */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
69 static vbr_get_quant_function vbr_getquant_1pass; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
70 static vbr_get_quant_function vbr_getquant_2pass1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
71 static vbr_get_quant_function vbr_getquant_2pass2; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
72 static vbr_get_quant_function vbr_getquant_fixedquant; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
73 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
74 /* Sub vbrGetIntra cases functions */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
75 static vbr_get_intra_function vbr_getintra_1pass; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
76 static vbr_get_intra_function vbr_getintra_2pass1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
77 static vbr_get_intra_function vbr_getintra_2pass2; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
78 static vbr_get_intra_function vbr_getintra_fixedquant; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
79 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
80 /* Sub vbrUpdate prototypes */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
81 static vbr_update_function vbr_update_dummy; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
82 static vbr_update_function vbr_update_2pass1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
83 static vbr_update_function vbr_update_2pass2; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
84 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
85 /* Sub vbrFinish cases functions */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
86 static vbr_finish_function vbr_finish_dummy; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
87 static vbr_finish_function vbr_finish_2pass1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
88 static vbr_finish_function vbr_finish_2pass2; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
89 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
90 /* Is the encoder in the credits */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
91 #define FRAME_TYPE_NORMAL_MOVIE 0x00 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
92 #define FRAME_TYPE_STARTING_CREDITS 0x01 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
93 #define FRAME_TYPE_ENDING_CREDITS 0x02 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
94 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
95 /****************************************************************************** |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
96 * Inline utility functions |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
97 *****************************************************************************/ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
98 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
99 static __inline int util_frametype(vbr_control_t *state) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
100 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
101 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
102 if(state->credits_start) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
103 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
104 if(state->cur_frame >= state->credits_start_begin && |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
105 state->cur_frame < state->credits_start_end) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
106 return(FRAME_TYPE_STARTING_CREDITS); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
107 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
108 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
109 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
110 if(state->credits_end) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
111 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
112 if(state->cur_frame >= state->credits_end_begin && |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
113 state->cur_frame < state->credits_end_end) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
114 return(FRAME_TYPE_STARTING_CREDITS); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
115 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
116 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
117 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
118 return(FRAME_TYPE_NORMAL_MOVIE); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
119 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
120 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
121 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
122 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
123 static __inline int util_creditsframes(vbr_control_t *state) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
124 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
125 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
126 int frames = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
127 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
128 if(state->credits_start) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
129 frames += state->credits_start_end - state->credits_start_begin; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
130 if(state->credits_end) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
131 frames += state->credits_end_end - state->credits_end_begin; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
132 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
133 return(frames); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
134 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
135 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
136 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
137 /****************************************************************************** |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
138 * Functions |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
139 *****************************************************************************/ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
140 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
141 /***************************************************************************** |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
142 * Function description : |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
143 * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
144 * This function initialiazes the vbr_control_t with safe defaults for all |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
145 * modes. |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
146 * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
147 * Return Values : |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
148 * = 0 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
149 ****************************************************************************/ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
150 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
151 int vbrSetDefaults(vbr_control_t *state) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
152 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
153 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
154 /* Set all the structure to zero */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
155 memset(state, 0, sizeof(state)); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
156 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
157 /* Default mode is CBR */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
158 state->mode = VBR_MODE_1PASS; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
159 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
160 /* Default statistic filename */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
161 state->filename = DEFAULT_XVID_STATS_FILE; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
162 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
163 /* Default is a 2hour movie on 700Mo CD-ROM + 128kbit sound track */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
164 state->desired_size = DEFAULT_DESIRED_SIZE*1024*1024 - |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
165 DEFAULT_MOVIE_LENGTH*3600*DEFAULT_AUDIO_BITRATE*1000/8; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
166 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
167 /* Credits */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
168 state->credits_mode = VBR_CREDITS_MODE_RATE; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
169 state->credits_start = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
170 state->credits_start_begin = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
171 state->credits_start_end = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
172 state->credits_end = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
173 state->credits_end_begin = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
174 state->credits_end_end = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
175 state->credits_quant_ratio = 20; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
176 state->credits_fixed_quant = 20; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
177 state->credits_quant_i = 20; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
178 state->credits_quant_p = 20; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
179 state->credits_start_size = DEFAULT_CREDITS_SIZE*1024*1024; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
180 state->credits_end_size = DEFAULT_CREDITS_SIZE*1024*1024; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
181 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
182 /* Keyframe boost */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
183 state->keyframe_boost = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
184 state->kftreshold = 10; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
185 state->kfreduction = 20; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
186 state->min_key_interval = 1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
187 state->max_key_interval = (int)DEFAULT_FPS*10; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
188 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
189 /* Normal curve treatment */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
190 state->curve_compression_high = 25; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
191 state->curve_compression_low = 10; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
192 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
193 /* Alt curve */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
194 state->use_alt_curve = 1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
195 state->alt_curve_type = VBR_ALT_CURVE_LINEAR; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
196 state->alt_curve_low_dist = 90; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
197 state->alt_curve_high_dist = 500; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
198 state->alt_curve_min_rel_qual = 50; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
199 state->alt_curve_use_auto = 1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
200 state->alt_curve_auto_str = 30; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
201 state->alt_curve_use_auto_bonus_bias = 1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
202 state->alt_curve_bonus_bias = 50; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
203 state->bitrate_payback_method = VBR_PAYBACK_BIAS; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
204 state->bitrate_payback_delay = 250; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
205 state->twopass_max_bitrate = state->desired_size*8 / (120*60); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
206 state->twopass_max_overflow_improvement = 60; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
207 state->twopass_max_overflow_degradation = 60; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
208 state->max_iquant = 31; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
209 state->min_iquant = 1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
210 state->max_pquant = 31; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
211 state->min_pquant = 1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
212 state->fixed_quant = 3; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
213 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
214 state->max_framesize = (1.0/(float)DEFAULT_FPS) * state->twopass_max_bitrate / 8; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
215 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
216 state->fps = (float)DEFAULT_FPS; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
217 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
218 return(0); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
219 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
220 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
221 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
222 /***************************************************************************** |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
223 * Function description : |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
224 * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
225 * This function initialiaze the vbr_control_t state passed in parameter. |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
226 * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
227 * The initialization depends on state->mode, there are 4 modes allowed. |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
228 * Each mode description is done in the README file shipped with the lib. |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
229 * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
230 * Return values : |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
231 * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
232 * = 0 on success |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
233 * = -1 on error |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
234 *****************************************************************************/ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
235 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
236 int vbrInit(vbr_control_t *state) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
237 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
238 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
239 if(state == NULL) return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
240 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
241 /* Function pointers safe initialization */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
242 state->init = NULL; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
243 state->getquant = NULL; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
244 state->getintra = NULL; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
245 state->update = NULL; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
246 state->finish = NULL; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
247 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
248 if(state->debug) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
249 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
250 state->debug_file = fopen(DEFAULT_XVID_DBG_FILE, "w+"); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
251 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
252 if(state->debug_file == NULL) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
253 return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
254 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
255 setvbuf(state->debug_file, NULL, _IOLBF, 0); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
256 fprintf(state->debug_file, "# XviD Debug output\n"); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
257 fprintf(state->debug_file, "# quant | intra | header bytes" |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
258 "| total bytes | kblocks | mblocks | ublocks" |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
259 "| vbr overflow | vbr kf overflow" |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
260 "| vbr kf partial overflow\n\n"); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
261 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
262 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
263 /* Function pointers sub case initialization */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
264 switch(state->mode) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
265 case VBR_MODE_1PASS: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
266 state->init = vbr_init_dummy; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
267 state->getquant = vbr_getquant_1pass; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
268 state->getintra = vbr_getintra_1pass; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
269 state->update = vbr_update_dummy; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
270 state->finish = vbr_finish_dummy; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
271 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
272 case VBR_MODE_2PASS_1: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
273 state->init = vbr_init_2pass1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
274 state->getquant = vbr_getquant_2pass1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
275 state->getintra = vbr_getintra_2pass1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
276 state->update = vbr_update_2pass1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
277 state->finish = vbr_finish_2pass1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
278 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
279 case VBR_MODE_FIXED_QUANT: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
280 state->init = vbr_init_fixedquant; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
281 state->getquant = vbr_getquant_fixedquant; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
282 state->getintra = vbr_getintra_fixedquant; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
283 state->update = vbr_update_dummy; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
284 state->finish = vbr_finish_dummy; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
285 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
286 case VBR_MODE_2PASS_2: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
287 state->init = vbr_init_2pass2; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
288 state->getintra = vbr_getintra_2pass2; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
289 state->getquant = vbr_getquant_2pass2; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
290 state->update = vbr_update_2pass2; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
291 state->finish = vbr_finish_2pass2; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
292 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
293 default: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
294 return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
295 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
296 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
297 return(state->init(state)); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
298 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
299 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
300 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
301 /****************************************************************************** |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
302 * Function description : |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
303 * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
304 * This function returns an adapted quantizer according to the current vbr |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
305 * controler state |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
306 * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
307 * Return values : |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
308 * the quantizer value (0 <= value <= 31) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
309 * (0 is a special case, means : let XviD decide) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
310 * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
311 *****************************************************************************/ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
312 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
313 int vbrGetQuant(vbr_control_t *state) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
314 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
315 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
316 /* Returns Zero, so XviD decides alone */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
317 if(state == NULL || state->getquant == NULL) return(0); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
318 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
319 return(state->getquant(state)); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
320 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
321 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
322 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
323 /****************************************************************************** |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
324 * Function description : |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
325 * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
326 * This function returns the type of the frame to be encoded next (I or P/B) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
327 * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
328 * Return values : |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
329 * = -1 let the XviD encoder decide wether or not the next frame is I |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
330 * = 0 no I frame |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
331 * = 1 force keyframe |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
332 * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
333 *****************************************************************************/ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
334 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
335 int vbrGetIntra(vbr_control_t *state) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
336 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
337 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
338 /* Returns -1, means let XviD decide */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
339 if(state == NULL || state->getintra == NULL) return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
340 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
341 return(state->getintra(state)); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
342 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
343 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
344 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
345 /****************************************************************************** |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
346 * Function description : |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
347 * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
348 * This function updates the vbr control state according to collected statistics |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
349 * from XviD core |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
350 * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
351 * Return values : |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
352 * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
353 * = 0 on success |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
354 * = -1 on error |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
355 *****************************************************************************/ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
356 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
357 int vbrUpdate(vbr_control_t *state, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
358 int quant, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
359 int intra, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
360 int header_bytes, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
361 int total_bytes, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
362 int kblocks, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
363 int mblocks, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
364 int ublocks) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
365 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
366 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
367 if(state == NULL || state->update == NULL) return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
368 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
369 if(state->debug && state->debug_file != NULL) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
370 int idx; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
371 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
372 fprintf(state->debug_file, "%d %d %d %d %d %d %d %d %d %d\n", |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
373 quant, intra, header_bytes, total_bytes, kblocks, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
374 mblocks, ublocks, state->overflow, state->KFoverflow, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
375 state->KFoverflow_partial); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
376 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
377 idx = quant; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
378 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
379 if(quant < 1) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
380 idx = 1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
381 if(quant > 31) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
382 idx = 31; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
383 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
384 idx--; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
385 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
386 state->debug_quant_count[idx]++; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
387 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
388 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
389 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
390 return(state->update(state, quant, intra, header_bytes, total_bytes, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
391 kblocks, mblocks, ublocks)); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
392 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
393 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
394 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
395 /****************************************************************************** |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
396 * Function description : |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
397 * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
398 * This function stops the vbr controller |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
399 * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
400 * Return values : |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
401 * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
402 * = 0 on success |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
403 * = -1 on error |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
404 *****************************************************************************/ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
405 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
406 int vbrFinish(vbr_control_t *state) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
407 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
408 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
409 if(state == NULL || state->finish == NULL) return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
410 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
411 if(state->debug && state->debug_file != NULL) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
412 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
413 int i; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
414 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
415 fprintf(state->debug_file, "\n\n"); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
416 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
417 for(i=0; i<79; i++) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
418 fprintf(state->debug_file, "#"); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
419 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
420 fprintf(state->debug_file, "\n# Quantizer distribution :\n\n"); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
421 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
422 for(i=0;i<32; i++) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
423 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
424 fprintf(state->debug_file, "# quant %d : %d\n", |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
425 i+1, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
426 state->debug_quant_count[i]); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
427 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
428 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
429 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
430 fclose(state->debug_file); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
431 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
432 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
433 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
434 return(state->finish(state)); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
435 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
436 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
437 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
438 /****************************************************************************** |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
439 * Dummy functions - Used when a mode does not need such a function |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
440 *****************************************************************************/ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
441 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
442 static int vbr_init_dummy(void *sstate) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
443 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
444 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
445 vbr_control_t *state = sstate; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
446 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
447 state->cur_frame = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
448 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
449 return(0); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
450 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
451 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
452 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
453 static int vbr_update_dummy(void *state, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
454 int quant, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
455 int intra, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
456 int header_bytes, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
457 int total_bytes, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
458 int kblocks, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
459 int mblocks, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
460 int ublocks) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
461 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
462 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
463 ((vbr_control_t*)state)->cur_frame++; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
464 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
465 return(0); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
466 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
467 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
468 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
469 static int vbr_finish_dummy(void *state) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
470 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
471 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
472 return(0); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
473 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
474 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
475 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
476 /****************************************************************************** |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
477 * 1 pass mode - XviD will do its job alone. |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
478 *****************************************************************************/ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
479 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
480 static int vbr_getquant_1pass(void *state) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
481 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
482 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
483 return(0); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
484 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
485 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
486 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
487 static int vbr_getintra_1pass(void *state) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
488 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
489 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
490 return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
491 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
492 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
493 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
494 /****************************************************************************** |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
495 * 2 pass mode - first pass functions |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
496 *****************************************************************************/ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
497 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
498 static int vbr_init_2pass1(void *sstate) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
499 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
500 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
501 FILE *f; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
502 vbr_control_t *state = sstate; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
503 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
504 /* Check the filename */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
505 if(state->filename == NULL || state->filename[0] == '\0') |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
506 return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
507 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
508 /* Initialize safe defaults for 2pass 1 */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
509 state->pass1_file = NULL; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
510 state->nb_frames = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
511 state->nb_keyframes = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
512 state->cur_frame = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
513 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
514 /* Open the 1st pass file */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
515 if((f = fopen(state->filename, "w+")) == NULL) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
516 return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
517 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
518 /* |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
519 * The File Header |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
520 * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
521 * The extra white spaces will be used during the vbrFinish to write |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
522 * the resulting number of frames and keyframes (10 spaces == maximum |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
523 * string length of an int on 32bit machines, i don't think anyone is |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
524 * encoding more than 4 billion frames :-) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
525 */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
526 fprintf(f, "# ASCII XviD vbr stat file version %d\n#\n", VBR_VERSION); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
527 fprintf(f, "# frames : \n"); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
528 fprintf(f, "# keyframes : \n"); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
529 fprintf(f, "#\n# quant | intra | header bytes | total bytes | kblocks |" |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
530 " mblocks | ublocks\n\n"); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
531 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
532 /* Save file pointer */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
533 state->pass1_file = f; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
534 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
535 return(0); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
536 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
537 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
538 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
539 static int vbr_getquant_2pass1(void *state) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
540 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
541 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
542 return(2); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
543 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
544 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
545 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
546 static int vbr_getintra_2pass1(void *state) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
547 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
548 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
549 return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
550 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
551 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
552 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
553 static int vbr_update_2pass1(void *sstate, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
554 int quant, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
555 int intra, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
556 int header_bytes, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
557 int total_bytes, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
558 int kblocks, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
559 int mblocks, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
560 int ublocks) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
561 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
562 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
563 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
564 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
565 vbr_control_t *state = sstate; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
566 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
567 if(state->pass1_file == NULL) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
568 return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
569 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
570 /* Writes the resulting statistics */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
571 fprintf(state->pass1_file, "%d %d %d %d %d %d %d\n", |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
572 quant, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
573 intra, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
574 header_bytes, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
575 total_bytes, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
576 kblocks, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
577 mblocks, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
578 ublocks); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
579 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
580 /* Update vbr control state */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
581 if(intra) state->nb_keyframes++; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
582 state->nb_frames++; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
583 state->cur_frame++; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
584 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
585 return(0); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
586 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
587 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
588 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
589 static int vbr_finish_2pass1(void *sstate) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
590 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
591 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
592 int c, i; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
593 vbr_control_t *state = sstate; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
594 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
595 if(state->pass1_file == NULL) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
596 return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
597 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
598 /* Goto to the file beginning */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
599 fseek(state->pass1_file, 0, SEEK_SET); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
600 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
601 /* Skip the version line and the empty line */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
602 c = i = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
603 do { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
604 c = fgetc(state->pass1_file); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
605 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
606 if(c == EOF) return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
607 if(c == '\n') i++; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
608 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
609 }while(i < 2); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
610 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
611 /* Overwrite the frame field - safe as we have written extra spaces */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
612 fprintf(state->pass1_file, "# frames : %.10d\n", state->nb_frames); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
613 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
614 /* Overwrite the keyframe field */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
615 fprintf(state->pass1_file, "# keyframes : %.10d\n", |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
616 state->nb_keyframes); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
617 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
618 /* Close the file */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
619 if(fclose(state->pass1_file) != 0) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
620 return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
621 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
622 return(0); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
623 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
624 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
625 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
626 /****************************************************************************** |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
627 * 2 pass mode - 2nd pass functions (Need to be finished) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
628 *****************************************************************************/ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
629 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
630 static int vbr_init_2pass2(void *sstate) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
631 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
632 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
633 FILE *f; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
634 int c, n, pos_firstframe, credits_frames; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
635 long long credits1_bytes; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
636 long long credits2_bytes; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
637 long long desired; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
638 long long total_bytes; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
639 long long itotal_bytes; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
640 long long start_curved; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
641 long long end_curved; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
642 double total1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
643 double total2; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
644 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
645 vbr_control_t *state = sstate; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
646 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
647 /* Check the filename */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
648 if(state->filename == NULL || state->filename[0] == '\0') |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
649 return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
650 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
651 /* Initialize safe defaults for 2pass 2 */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
652 state->pass1_file = NULL; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
653 state->nb_frames = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
654 state->nb_keyframes = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
655 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
656 /* Open the 1st pass file */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
657 if((f = fopen(state->filename, "r")) == NULL) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
658 return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
659 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
660 state->pass1_file = f; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
661 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
662 /* Get the file version and check against current version */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
663 fscanf(state->pass1_file, "# ASCII XviD vbr stat file version %d\n", &n); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
664 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
665 if(n != VBR_VERSION) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
666 fclose(state->pass1_file); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
667 state->pass1_file = NULL; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
668 return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
669 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
670 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
671 /* Skip the blank commented line */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
672 c = n = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
673 do { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
674 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
675 c = fgetc(state->pass1_file); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
676 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
677 if(c == EOF) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
678 fclose(state->pass1_file); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
679 state->pass1_file = NULL; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
680 return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
681 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
682 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
683 if(c == '\n') n++; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
684 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
685 }while(n < 1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
686 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
687 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
688 /* Get the number of frames */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
689 fscanf(state->pass1_file, "# frames : %d\n", &state->nb_frames); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
690 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
691 /* Compute the desired size */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
692 state->desired_size = (long long) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
693 (((long long)state->nb_frames * (long long)state->desired_bitrate) / |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
694 (state->fps * 8.0)); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
695 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
696 /* Get the number of keyframes */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
697 fscanf(state->pass1_file, "# keyframes : %d\n", &state->nb_keyframes); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
698 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
699 /* Allocate memory space for the keyframe_location array */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
700 if((state->keyframe_locations |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
701 = (int*)malloc((state->nb_keyframes+1)*sizeof(int))) == NULL) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
702 fclose(state->pass1_file); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
703 state->pass1_file = NULL; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
704 return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
705 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
706 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
707 /* Skip the blank commented line and the colum description */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
708 c = n = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
709 do { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
710 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
711 c = fgetc(state->pass1_file); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
712 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
713 if(c == EOF) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
714 fclose(state->pass1_file); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
715 state->pass1_file = NULL; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
716 return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
717 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
718 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
719 if(c == '\n') n++; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
720 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
721 }while(n < 2); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
722 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
723 /* Save position for future use */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
724 pos_firstframe = ftell(state->pass1_file); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
725 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
726 /* Read and initialize some variables */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
727 credits1_bytes = credits2_bytes = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
728 total_bytes = itotal_bytes = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
729 start_curved = end_curved = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
730 credits_frames = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
731 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
732 for(state->cur_frame = c = 0; state->cur_frame<state->nb_frames; state->cur_frame++) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
733 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
734 int quant, keyframe, frame_hbytes, frame_bytes; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
735 int kblocks, mblocks, ublocks; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
736 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
737 fscanf(state->pass1_file, "%d %d %d %d %d %d %d\n", |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
738 &quant, &keyframe, &frame_hbytes, &frame_bytes, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
739 &kblocks, &mblocks, &ublocks); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
740 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
741 /* Is the frame in the beginning credits */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
742 if(util_frametype(state) == FRAME_TYPE_STARTING_CREDITS) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
743 credits1_bytes += frame_bytes; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
744 credits_frames++; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
745 continue; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
746 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
747 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
748 /* Is the frame in the eding credits */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
749 if(util_frametype(state) == FRAME_TYPE_ENDING_CREDITS) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
750 credits2_bytes += frame_bytes; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
751 credits_frames++; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
752 continue; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
753 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
754 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
755 /* We only care about Keyframes when not in credits */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
756 if(keyframe) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
757 itotal_bytes += frame_bytes + frame_bytes * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
758 state->keyframe_boost / 100; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
759 total_bytes += frame_bytes * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
760 state->keyframe_boost / 100; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
761 state->keyframe_locations[c++] = state->cur_frame; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
762 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
763 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
764 total_bytes += frame_bytes; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
765 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
766 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
767 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
768 /* |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
769 * Last frame is treated like an I Frame so we can dispatch overflow |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
770 * all other the last film segment |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
771 */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
772 state->keyframe_locations[c] = state->cur_frame; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
773 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
774 /* Compensate AVI overhead */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
775 desired = state->desired_size - state->nb_frames*24; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
776 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
777 switch(state->credits_mode) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
778 case VBR_CREDITS_MODE_QUANT : |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
779 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
780 state->movie_curve = (double) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
781 (total_bytes - credits1_bytes - credits2_bytes) / |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
782 (desired - credits1_bytes - credits2_bytes); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
783 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
784 start_curved = credits1_bytes; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
785 end_curved = credits2_bytes; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
786 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
787 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
788 case VBR_CREDITS_MODE_SIZE: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
789 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
790 /* start curve = (start / start desired size) */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
791 state->credits_start_curve = (double) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
792 (credits1_bytes / state->credits_start_size); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
793 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
794 /* end curve = (end / end desired size) */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
795 state->credits_end_curve = (double) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
796 (credits2_bytes / state->credits_end_size); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
797 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
798 start_curved = (long long) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
799 (credits1_bytes / state->credits_start_curve); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
800 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
801 end_curved = (long long) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
802 (credits2_bytes / state->credits_end_curve); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
803 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
804 /* movie curve=(total-credits)/(desired_size-curved credits) */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
805 state->movie_curve = (double) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
806 (total_bytes - credits1_bytes - credits2_bytes) / |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
807 (desired - start_curved - end_curved); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
808 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
809 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
810 case VBR_CREDITS_MODE_RATE: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
811 default: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
812 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
813 /* credits curve = (total/desired_size)*(100/credits_rate) */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
814 state->credits_start_curve = state->credits_end_curve = |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
815 ((double)total_bytes / desired) * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
816 ((double)100 / state->credits_quant_ratio); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
817 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
818 start_curved = |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
819 (long long)(credits1_bytes/state->credits_start_curve); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
820 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
821 end_curved = |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
822 (long long)(credits2_bytes/state->credits_end_curve); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
823 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
824 state->movie_curve = (double) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
825 (total_bytes - credits1_bytes - credits2_bytes) / |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
826 (desired - start_curved - end_curved); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
827 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
828 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
829 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
830 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
831 /* |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
832 * average frame size = (desired - curved credits - curved keyframes) / |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
833 * (frames - credits frames - keyframes) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
834 */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
835 state->average_frame = (double) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
836 (desired - start_curved - end_curved - |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
837 (itotal_bytes / state->movie_curve)) / |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
838 (state->nb_frames - util_creditsframes(state) - |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
839 state->nb_keyframes); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
840 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
841 /* Initialize alt curve parameters */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
842 if (state->use_alt_curve) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
843 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
844 state->alt_curve_low = |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
845 state->average_frame - state->average_frame * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
846 (double)(state->alt_curve_low_dist / 100.0); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
847 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
848 state->alt_curve_low_diff = |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
849 state->average_frame - state->alt_curve_low; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
850 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
851 state->alt_curve_high = |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
852 state->average_frame + state->average_frame * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
853 (double)(state->alt_curve_high_dist / 100.0); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
854 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
855 state->alt_curve_high_diff = |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
856 state->alt_curve_high - state->average_frame; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
857 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
858 if (state->alt_curve_use_auto) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
859 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
860 if (state->movie_curve > 1.0) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
861 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
862 state->alt_curve_min_rel_qual = |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
863 (int)(100.0 - (100.0 - 100.0 / state->movie_curve) * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
864 (double)state->alt_curve_auto_str / 100.0); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
865 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
866 if (state->alt_curve_min_rel_qual < 20) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
867 state->alt_curve_min_rel_qual = 20; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
868 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
869 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
870 state->alt_curve_min_rel_qual = 100; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
871 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
872 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
873 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
874 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
875 state->alt_curve_mid_qual = |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
876 (1.0 + (double)state->alt_curve_min_rel_qual / 100.0) / 2.0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
877 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
878 state->alt_curve_qual_dev = 1.0 - state->alt_curve_mid_qual; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
879 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
880 if (state->alt_curve_low_dist > 100) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
881 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
882 switch(state->alt_curve_type) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
883 case VBR_ALT_CURVE_AGGRESIVE: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
884 /* Sine Curve (high aggressiveness) */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
885 state->alt_curve_qual_dev *= |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
886 2.0 / |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
887 (1.0 + sin(DEG2RAD * (state->average_frame * 90.0 / state->alt_curve_low_diff))); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
888 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
889 state->alt_curve_mid_qual = |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
890 1.0 - state->alt_curve_qual_dev * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
891 sin(DEG2RAD * (state->average_frame * 90.0 / state->alt_curve_low_diff)); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
892 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
893 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
894 default: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
895 case VBR_ALT_CURVE_LINEAR: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
896 /* Linear (medium aggressiveness) */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
897 state->alt_curve_qual_dev *= |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
898 2.0 / |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
899 (1.0 + state->average_frame / state->alt_curve_low_diff); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
900 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
901 state->alt_curve_mid_qual = |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
902 1.0 - state->alt_curve_qual_dev * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
903 state->average_frame / state->alt_curve_low_diff; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
904 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
905 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
906 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
907 case VBR_ALT_CURVE_SOFT: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
908 /* Cosine Curve (low aggressiveness) */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
909 state->alt_curve_qual_dev *= |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
910 2.0 / |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
911 (1.0 + (1.0 - cos(DEG2RAD * (state->average_frame * 90.0 / state->alt_curve_low_diff)))); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
912 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
913 state->alt_curve_mid_qual = |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
914 1.0 - state->alt_curve_qual_dev * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
915 (1.0 - cos(DEG2RAD * (state->average_frame * 90.0 / state->alt_curve_low_diff))); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
916 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
917 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
918 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
919 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
920 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
921 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
922 /* Go to the first non credits frame stats line into file */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
923 fseek(state->pass1_file, pos_firstframe, SEEK_SET); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
924 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
925 /* Perform prepass to compensate for over/undersizing */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
926 total1 = total2 = 0.0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
927 for(state->cur_frame=0; state->cur_frame<state->nb_frames; state->cur_frame++) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
928 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
929 int quant, keyframe, frame_hbytes, frame_bytes; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
930 int kblocks, mblocks, ublocks; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
931 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
932 fscanf(state->pass1_file, "%d %d %d %d %d %d %d\n", |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
933 &quant, &keyframe, &frame_hbytes, &frame_bytes, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
934 &kblocks, &mblocks, &ublocks); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
935 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
936 if(util_frametype(state) != FRAME_TYPE_NORMAL_MOVIE) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
937 continue; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
938 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
939 if(!keyframe) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
940 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
941 double dbytes = frame_bytes / state->movie_curve; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
942 total1 += dbytes; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
943 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
944 if (state->use_alt_curve) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
945 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
946 if (dbytes > state->average_frame) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
947 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
948 if (dbytes >= state->alt_curve_high) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
949 total2 += dbytes * (state->alt_curve_mid_qual - state->alt_curve_qual_dev); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
950 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
951 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
952 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
953 switch(state->alt_curve_type) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
954 case VBR_ALT_CURVE_AGGRESIVE: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
955 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
956 total2 += |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
957 dbytes * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
958 (state->alt_curve_mid_qual - state->alt_curve_qual_dev * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
959 sin(DEG2RAD * ((dbytes - state->average_frame) * 90.0 / state->alt_curve_high_diff))); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
960 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
961 default: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
962 case VBR_ALT_CURVE_LINEAR: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
963 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
964 total2 += |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
965 dbytes * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
966 (state->alt_curve_mid_qual - state->alt_curve_qual_dev * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
967 (dbytes - state->average_frame) / state->alt_curve_high_diff); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
968 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
969 case VBR_ALT_CURVE_SOFT: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
970 total2 += |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
971 dbytes * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
972 (state->alt_curve_mid_qual - state->alt_curve_qual_dev * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
973 (1.0 - cos(DEG2RAD * ((dbytes - state->average_frame) * 90.0 / state->alt_curve_high_diff)))); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
974 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
975 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
976 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
977 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
978 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
979 if (dbytes <= state->alt_curve_low) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
980 total2 += dbytes; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
981 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
982 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
983 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
984 switch(state->alt_curve_type) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
985 case VBR_ALT_CURVE_AGGRESIVE: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
986 total2 += |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
987 dbytes * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
988 (state->alt_curve_mid_qual - state->alt_curve_qual_dev * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
989 sin(DEG2RAD * ((dbytes - state->average_frame) * 90.0 / state->alt_curve_low_diff))); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
990 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
991 default: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
992 case VBR_ALT_CURVE_LINEAR: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
993 total2 += |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
994 dbytes * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
995 (state->alt_curve_mid_qual - state->alt_curve_qual_dev * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
996 (dbytes - state->average_frame) / state->alt_curve_low_diff); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
997 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
998 case VBR_ALT_CURVE_SOFT: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
999 total2 += |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1000 dbytes * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1001 (state->alt_curve_mid_qual + state->alt_curve_qual_dev * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1002 (1.0 - cos(DEG2RAD * ((dbytes - state->average_frame) * 90.0 / state->alt_curve_low_diff)))); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1003 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1004 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1005 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1006 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1007 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1008 if (dbytes > state->average_frame) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1009 total2 += |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1010 ((double)dbytes + |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1011 (state->average_frame - dbytes) * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1012 state->curve_compression_high / 100.0); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1013 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1014 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1015 total2 += |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1016 ((double)dbytes + |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1017 (state->average_frame - dbytes) * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1018 state->curve_compression_low / 100.0); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1019 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1020 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1021 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1022 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1023 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1024 state->curve_comp_scale = total1 / total2; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1025 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1026 if (state->use_alt_curve) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1027 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1028 double curve_temp, dbytes; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1029 int newquant, percent; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1030 int oldquant = 1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1031 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1032 if (state->alt_curve_use_auto_bonus_bias) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1033 state->alt_curve_bonus_bias = state->alt_curve_min_rel_qual; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1034 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1035 state->curve_bias_bonus = |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1036 (total1 - total2) * (double)state->alt_curve_bonus_bias / |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1037 (100.0 * (double)(state->nb_frames - util_creditsframes(state) - state->nb_keyframes)); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1038 state->curve_comp_scale = |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1039 ((total1 - total2) * (1.0 - (double)state->alt_curve_bonus_bias / 100.0) + total2) / |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1040 total2; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1041 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1042 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1043 for (n=1; n <= (int)(state->alt_curve_high*2) + 1; n++) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1044 dbytes = n; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1045 if (dbytes > state->average_frame) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1046 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1047 if (dbytes >= state->alt_curve_high) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1048 curve_temp = dbytes * (state->alt_curve_mid_qual - state->alt_curve_qual_dev); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1049 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1050 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1051 switch(state->alt_curve_type) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1052 case VBR_ALT_CURVE_AGGRESIVE: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1053 curve_temp = dbytes * (state->alt_curve_mid_qual - state->alt_curve_qual_dev * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1054 sin(DEG2RAD * ((dbytes - state->average_frame) * 90.0 / state->alt_curve_high_diff))); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1055 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1056 default: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1057 case VBR_ALT_CURVE_LINEAR: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1058 curve_temp = dbytes * (state->alt_curve_mid_qual - state->alt_curve_qual_dev * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1059 (dbytes - state->average_frame) / state->alt_curve_high_diff); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1060 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1061 case VBR_ALT_CURVE_SOFT: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1062 curve_temp = dbytes * (state->alt_curve_mid_qual - state->alt_curve_qual_dev * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1063 (1.0 - cos(DEG2RAD * ((dbytes - state->average_frame) * 90.0 / state->alt_curve_high_diff)))); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1064 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1065 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1066 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1067 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1068 if (dbytes <= state->alt_curve_low) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1069 curve_temp = dbytes; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1070 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1071 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1072 switch(state->alt_curve_type) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1073 case VBR_ALT_CURVE_AGGRESIVE: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1074 curve_temp = dbytes * (state->alt_curve_mid_qual - state->alt_curve_qual_dev * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1075 sin(DEG2RAD * ((dbytes - state->average_frame) * 90.0 / state->alt_curve_low_diff))); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1076 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1077 default: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1078 case VBR_ALT_CURVE_LINEAR: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1079 curve_temp = dbytes * (state->alt_curve_mid_qual - state->alt_curve_qual_dev * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1080 (dbytes - state->average_frame) / state->alt_curve_low_diff); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1081 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1082 case VBR_ALT_CURVE_SOFT: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1083 curve_temp = dbytes * (state->alt_curve_mid_qual + state->alt_curve_qual_dev * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1084 (1.0 - cos(DEG2RAD * ((dbytes - state->average_frame) * 90.0 / state->alt_curve_low_diff)))); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1085 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1086 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1087 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1088 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1089 if (state->movie_curve > 1.0) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1090 dbytes *= state->movie_curve; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1091 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1092 newquant = (int)(dbytes * 2.0 / (curve_temp * state->curve_comp_scale + state->curve_bias_bonus)); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1093 if (newquant > 1) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1094 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1095 if (newquant != oldquant) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1096 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1097 oldquant = newquant; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1098 percent = (int)((n - state->average_frame) * 100.0 / state->average_frame); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1099 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1100 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1101 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1102 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1103 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1104 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1105 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1106 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1107 state->overflow = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1108 state->KFoverflow = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1109 state->KFoverflow_partial = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1110 state->KF_idx = 1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1111 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1112 for (n=0 ; n < 32 ; n++) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1113 state->quant_error[n] = 0.0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1114 state->quant_count[n] = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1115 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1116 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1117 state->curve_comp_error = 0.0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1118 state->last_quant = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1119 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1120 /* Two pass maximum boost computed from frame mean */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1121 state->twopass_max_bitrate = DEFAULT_TWOPASS_BOOST/100.0 * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1122 state->average_frame * state->fps * 8; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1123 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1124 state->max_framesize = state->average_frame * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1125 DEFAULT_TWOPASS_BOOST/100.0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1126 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1127 /* Get back to the beginning of frame statistics */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1128 fseek(state->pass1_file, pos_firstframe, SEEK_SET); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1129 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1130 /* |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1131 * Small hack : We have to get next frame stats before the |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1132 * getintra/quant calls |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1133 * User clients update the data when they call vbrUpdate |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1134 * we are just bypassing this because we don't have to update |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1135 * the overflow and so on... |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1136 */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1137 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1138 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1139 /* Fake vars */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1140 int next_hbytes, next_kblocks, next_mblocks, next_ublocks; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1141 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1142 fscanf(state->pass1_file, "%d %d %d %d %d %d %d\n", |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1143 &state->pass1_quant, &state->pass1_intra, &next_hbytes, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1144 &state->pass1_bytes, &next_kblocks, &next_mblocks, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1145 &next_ublocks); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1146 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1147 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1148 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1149 /* Initialize the frame counter */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1150 state->cur_frame = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1151 state->last_keyframe = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1152 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1153 return(0); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1154 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1155 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1156 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1157 static int vbr_getquant_2pass2(void *sstate) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1158 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1159 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1160 int quant; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1161 int intra; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1162 int bytes1, bytes2; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1163 int overflow; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1164 int capped_to_max_framesize = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1165 int KFdistance, KF_min_size; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1166 vbr_control_t *state = sstate; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1167 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1168 bytes1 = state->pass1_bytes; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1169 overflow = state->overflow / 8; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1170 /* To shut up gcc warning */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1171 bytes2 = bytes1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1172 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1173 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1174 if (state->pass1_intra) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1175 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1176 overflow = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1177 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1178 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1179 if (util_frametype(state) != FRAME_TYPE_NORMAL_MOVIE) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1180 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1181 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1182 switch (state->credits_mode) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1183 case VBR_CREDITS_MODE_QUANT : |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1184 if (state->credits_quant_i != state->credits_quant_p) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1185 quant = state->pass1_intra ? |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1186 state->credits_quant_i: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1187 state->credits_quant_p; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1188 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1189 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1190 quant = state->credits_quant_p; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1191 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1192 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1193 state->bytes1 = bytes1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1194 state->bytes2 = bytes1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1195 state->desired_bytes2 = bytes1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1196 return(quant); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1197 default: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1198 case VBR_CREDITS_MODE_RATE : |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1199 case VBR_CREDITS_MODE_SIZE : |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1200 if(util_frametype(state) == FRAME_TYPE_STARTING_CREDITS) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1201 bytes2 = (int)(bytes1 / state->credits_start_curve); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1202 else |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1203 bytes2 = (int)(bytes1 / state->credits_end_curve); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1204 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1205 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1206 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1207 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1208 /* Foxer: apply curve compression outside credits */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1209 double dbytes, curve_temp; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1210 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1211 bytes2 = bytes1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1212 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1213 if (state->pass1_intra) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1214 dbytes = ((int)(bytes2 + bytes2 * state->keyframe_boost / 100)) / |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1215 state->movie_curve; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1216 else |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1217 dbytes = bytes2 / state->movie_curve; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1218 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1219 /* spread the compression error accross payback_delay frames */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1220 if (state->bitrate_payback_method == VBR_PAYBACK_BIAS) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1221 bytes2 = (int)(state->curve_comp_error / state->bitrate_payback_delay); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1222 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1223 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1224 bytes2 = (int)(state->curve_comp_error * dbytes / |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1225 state->average_frame / state->bitrate_payback_delay); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1226 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1227 if (labs(bytes2) > fabs(state->curve_comp_error)) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1228 bytes2 = (int)state->curve_comp_error; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1229 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1230 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1231 state->curve_comp_error -= bytes2; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1232 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1233 if (state->use_alt_curve) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1234 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1235 if (!state->pass1_intra) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1236 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1237 if (dbytes > state->average_frame) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1238 if (dbytes >= state->alt_curve_high) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1239 curve_temp = dbytes * (state->alt_curve_mid_qual - state->alt_curve_qual_dev); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1240 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1241 switch(state->alt_curve_type) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1242 case VBR_ALT_CURVE_AGGRESIVE: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1243 curve_temp = dbytes * (state->alt_curve_mid_qual - state->alt_curve_qual_dev * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1244 sin(DEG2RAD * ((dbytes - state->average_frame) * 90.0 / state->alt_curve_high_diff))); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1245 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1246 default: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1247 case VBR_ALT_CURVE_LINEAR: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1248 curve_temp = dbytes * (state->alt_curve_mid_qual - state->alt_curve_qual_dev * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1249 (dbytes - state->average_frame) / state->alt_curve_high_diff); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1250 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1251 case VBR_ALT_CURVE_SOFT: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1252 curve_temp = dbytes * (state->alt_curve_mid_qual - state->alt_curve_qual_dev * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1253 (1.0 - cos(DEG2RAD * ((dbytes - state->average_frame) * 90.0 / state->alt_curve_high_diff)))); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1254 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1255 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1256 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1257 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1258 if (dbytes <= state->alt_curve_low) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1259 curve_temp = dbytes; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1260 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1261 switch(state->alt_curve_type) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1262 case VBR_ALT_CURVE_AGGRESIVE: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1263 curve_temp = dbytes * (state->alt_curve_mid_qual - state->alt_curve_qual_dev * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1264 sin(DEG2RAD * ((dbytes - state->average_frame) * 90.0 / state->alt_curve_low_diff))); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1265 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1266 default: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1267 case VBR_ALT_CURVE_LINEAR: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1268 curve_temp = dbytes * (state->alt_curve_mid_qual - state->alt_curve_qual_dev * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1269 (dbytes - state->average_frame) / state->alt_curve_low_diff); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1270 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1271 case VBR_ALT_CURVE_SOFT: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1272 curve_temp = dbytes * (state->alt_curve_mid_qual + state->alt_curve_qual_dev * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1273 (1.0 - cos(DEG2RAD * ((dbytes - state->average_frame) * 90.0 / state->alt_curve_low_diff)))); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1274 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1275 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1276 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1277 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1278 curve_temp = curve_temp * state->curve_comp_scale + state->curve_bias_bonus; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1279 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1280 bytes2 += ((int)curve_temp); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1281 state->curve_comp_error += curve_temp - ((int)curve_temp); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1282 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1283 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1284 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1285 state->curve_comp_error += dbytes - ((int)dbytes); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1286 bytes2 += ((int)dbytes); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1287 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1288 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1289 else if ((state->curve_compression_high + state->curve_compression_low) && |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1290 !state->pass1_intra) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1291 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1292 if (dbytes > state->average_frame) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1293 curve_temp = state->curve_comp_scale * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1294 ((double)dbytes + (state->average_frame - dbytes) * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1295 state->curve_compression_high / 100.0); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1296 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1297 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1298 curve_temp = state->curve_comp_scale * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1299 ((double)dbytes + (state->average_frame - dbytes) * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1300 state->curve_compression_low / 100.0); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1301 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1302 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1303 bytes2 += ((int)curve_temp); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1304 state->curve_comp_error += curve_temp - ((int)curve_temp); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1305 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1306 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1307 state->curve_comp_error += dbytes - ((int)dbytes); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1308 bytes2 += ((int)dbytes); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1309 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1310 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1311 /* cap bytes2 to first pass size, lowers number of quant=1 frames */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1312 if (bytes2 > bytes1) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1313 state->curve_comp_error += bytes2 - bytes1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1314 bytes2 = bytes1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1315 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1316 else if (bytes2 < 1) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1317 state->curve_comp_error += --bytes2; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1318 bytes2 = 1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1319 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1320 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1321 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1322 state->desired_bytes2 = bytes2; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1323 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1324 /* Ugly dependance between getquant and getintra */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1325 intra = state->getintra(state); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1326 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1327 if(intra) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1328 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1329 KFdistance = state->keyframe_locations[state->KF_idx] - |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1330 state->keyframe_locations[state->KF_idx - 1]; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1331 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1332 if (KFdistance < state->kftreshold) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1333 KFdistance = KFdistance - state->min_key_interval; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1334 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1335 if (KFdistance >= 0) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1336 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1337 KF_min_size = bytes2 * (100 - state->kfreduction) / 100; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1338 if (KF_min_size < 1) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1339 KF_min_size = 1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1340 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1341 bytes2 = KF_min_size + (bytes2 - KF_min_size) * KFdistance / |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1342 (state->kftreshold - state->min_key_interval); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1343 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1344 if (bytes2 < 1) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1345 bytes2 = 1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1346 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1347 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1348 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1349 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1350 /* |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1351 * Foxer: scale overflow in relation to average size, so smaller frames don't get |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1352 * too much/little bitrate |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1353 */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1354 overflow = (int)((double)overflow * bytes2 / state->average_frame); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1355 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1356 /* Foxer: reign in overflow with huge frames */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1357 if (labs(overflow) > labs(state->overflow)) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1358 overflow = state->overflow; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1359 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1360 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1361 /* Foxer: make sure overflow doesn't run away */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1362 if(overflow > bytes2 * state->twopass_max_overflow_improvement / 100) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1363 bytes2 += (overflow <= bytes2) ? bytes2 * state->twopass_max_overflow_improvement / 100 : |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1364 overflow * state->twopass_max_overflow_improvement / 100; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1365 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1366 else if(overflow < bytes2 * state->twopass_max_overflow_degradation / -100) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1367 bytes2 += bytes2 * state->twopass_max_overflow_degradation / -100; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1368 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1369 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1370 bytes2 += overflow; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1371 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1372 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1373 if(bytes2 > state->max_framesize) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1374 capped_to_max_framesize = 1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1375 bytes2 = state->max_framesize; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1376 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1377 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1378 if(bytes2 < 1) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1379 bytes2 = 1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1380 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1381 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1382 state->bytes1 = bytes1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1383 state->bytes2 = bytes2; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1384 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1385 /* very 'simple' quant<->filesize relationship */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1386 quant = state->pass1_quant * bytes1 / bytes2; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1387 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1388 if(quant < 1) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1389 quant = 1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1390 else if(quant > 31) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1391 quant = 31; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1392 else if(!state->pass1_intra) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1393 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1394 /* Foxer: aid desired quantizer precision by accumulating decision error */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1395 state->quant_error[quant] += ((double)(state->pass1_quant * bytes1) / bytes2) - quant; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1396 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1397 if (state->quant_error[quant] >= 1.0) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1398 state->quant_error[quant] -= 1.0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1399 quant++; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1400 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1401 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1402 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1403 /* we're done with credits */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1404 if(util_frametype(state) != FRAME_TYPE_NORMAL_MOVIE) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1405 return(quant); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1406 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1407 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1408 if(intra) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1409 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1410 if (quant < state->min_iquant) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1411 quant = state->min_iquant; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1412 if (quant > state->max_iquant) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1413 quant = state->max_iquant; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1414 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1415 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1416 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1417 if(quant > state->max_pquant) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1418 quant = state->max_pquant; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1419 if(quant < state->min_pquant) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1420 quant = state->min_pquant; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1421 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1422 /* subsequent frame quants can only be +- 2 */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1423 if(state->last_quant && capped_to_max_framesize == 0) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1424 if (quant > state->last_quant + 2) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1425 quant = state->last_quant + 2; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1426 if (quant < state->last_quant - 2) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1427 quant = state->last_quant - 2; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1428 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1429 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1430 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1431 return(quant); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1432 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1433 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1434 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1435 static int vbr_getintra_2pass2(void *sstate) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1436 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1437 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1438 int intra; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1439 vbr_control_t *state = sstate; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1440 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1441 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1442 /* Get next intra state (fetched by update) */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1443 intra = state->pass1_intra; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1444 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1445 /* During credits, XviD will decide itself */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1446 if(util_frametype(state) != FRAME_TYPE_NORMAL_MOVIE) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1447 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1448 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1449 switch(state->credits_mode) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1450 default: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1451 case VBR_CREDITS_MODE_RATE : |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1452 case VBR_CREDITS_MODE_SIZE : |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1453 intra = -1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1454 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1455 case VBR_CREDITS_MODE_QUANT : |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1456 /* Except in this case */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1457 if (state->credits_quant_i == state->credits_quant_p) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1458 intra = -1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1459 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1460 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1461 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1462 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1463 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1464 /* Force I Frame when max_key_interval is reached */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1465 if((state->cur_frame - state->last_keyframe) > state->max_key_interval) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1466 intra = 1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1467 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1468 /* |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1469 * Force P or B Frames for frames whose distance is less than the |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1470 * requested minimum |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1471 */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1472 if((state->cur_frame - state->last_keyframe) < state->min_key_interval) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1473 intra = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1474 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1475 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1476 /* Return the given intra mode except for first frame */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1477 return((state->cur_frame==0)?1:intra); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1478 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1479 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1480 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1481 static int vbr_update_2pass2(void *sstate, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1482 int quant, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1483 int intra, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1484 int header_bytes, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1485 int total_bytes, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1486 int kblocks, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1487 int mblocks, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1488 int ublocks) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1489 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1490 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1491 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1492 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1493 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1494 int next_hbytes, next_kblocks, next_mblocks, next_ublocks; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1495 int tempdiv; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1496 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1497 vbr_control_t *state = sstate; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1498 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1499 /* |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1500 * We do not depend on getintra/quant because we have the real results |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1501 * from the xvid core |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1502 */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1503 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1504 if (util_frametype(state) == FRAME_TYPE_NORMAL_MOVIE) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1505 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1506 state->quant_count[quant]++; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1507 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1508 if (state->pass1_intra) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1509 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1510 state->overflow += state->KFoverflow; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1511 state->KFoverflow = state->desired_bytes2 - total_bytes; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1512 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1513 tempdiv = (state->keyframe_locations[state->KF_idx] - |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1514 state->keyframe_locations[state->KF_idx - 1]); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1515 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1516 /* redistribute correctly (by koepi) */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1517 if (tempdiv > 1) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1518 /* non-consecutive keyframes */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1519 state->KFoverflow_partial = state->KFoverflow / |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1520 (tempdiv - 1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1521 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1522 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1523 state->overflow += state->KFoverflow; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1524 state->KFoverflow = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1525 state->KFoverflow_partial = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1526 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1527 state->KF_idx++; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1528 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1529 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1530 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1531 state->overflow += state->desired_bytes2 - total_bytes + |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1532 state->KFoverflow_partial; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1533 state->KFoverflow -= state->KFoverflow_partial; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1534 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1535 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1536 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1537 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1538 state->overflow += state->desired_bytes2 - total_bytes; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1539 state->overflow += state->KFoverflow; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1540 state->KFoverflow = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1541 state->KFoverflow_partial = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1542 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1543 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1544 /* Save old quant */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1545 state->last_quant = quant; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1546 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1547 /* Update next frame data */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1548 fscanf(state->pass1_file, "%d %d %d %d %d %d %d\n", |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1549 &state->pass1_quant, &state->pass1_intra, &next_hbytes, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1550 &state->pass1_bytes, &next_kblocks, &next_mblocks, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1551 &next_ublocks); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1552 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1553 /* Save the last Keyframe pos */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1554 if(intra) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1555 state->last_keyframe = state->cur_frame; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1556 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1557 /* Ok next frame */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1558 state->cur_frame++; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1559 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1560 return(0); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1561 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1562 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1563 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1564 static int vbr_finish_2pass2(void *sstate) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1565 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1566 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1567 vbr_control_t *state = sstate; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1568 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1569 if(state->pass1_file == NULL) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1570 return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1571 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1572 /* Close the file */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1573 if(fclose(state->pass1_file) != 0) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1574 return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1575 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1576 /* Free the memory */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1577 if(state->keyframe_locations) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1578 free(state->keyframe_locations); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1579 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1580 return(0); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1581 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1582 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1583 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1584 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1585 /****************************************************************************** |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1586 * Fixed quant mode - Most of the functions will be dummy functions |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1587 *****************************************************************************/ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1588 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1589 static int vbr_init_fixedquant(void *sstate) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1590 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1591 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1592 vbr_control_t *state = sstate; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1593 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1594 if(state->fixed_quant < 1) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1595 state->fixed_quant = 1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1596 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1597 if(state->fixed_quant > 31) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1598 state->fixed_quant = 31; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1599 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1600 state->cur_frame = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1601 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1602 return(0); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1603 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1604 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1605 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1606 static int vbr_getquant_fixedquant(void *sstate) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1607 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1608 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1609 vbr_control_t *state = sstate; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1610 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1611 /* Credits' frame ? */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1612 if(util_frametype(state) != FRAME_TYPE_NORMAL_MOVIE) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1613 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1614 int quant; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1615 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1616 switch(state->credits_mode) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1617 case VBR_CREDITS_MODE_RATE: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1618 quant = state->fixed_quant * state->credits_quant_ratio; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1619 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1620 case VBR_CREDITS_MODE_QUANT: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1621 quant = state->credits_fixed_quant; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1622 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1623 default: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1624 quant = state->fixed_quant; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1625 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1626 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1627 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1628 return(quant); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1629 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1630 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1631 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1632 /* No credit frame - return fixed quant */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1633 return(state->fixed_quant); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1634 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1635 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1636 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1637 static int vbr_getintra_fixedquant(void *state) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1638 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1639 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1640 return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1641 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1642 } |