Mercurial > mplayer.hg
annotate xvid_vbr.c @ 33404:7dfe52e4f2e1
Fix play duration calculation error.
Acording to the ASF documentation, the play duration is zero
if the preroll value is greater than the play duration.
The new way of determination (suggested by reimar) prevents
overflows as well.
author | ib |
---|---|
date | Tue, 24 May 2011 13:35:26 +0000 |
parents | b39155e98ac3 |
children | 3ca6a7d60396 |
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 |
29248 | 4 * |
7331
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 |
17367
401b440a6d76
Update licensing information: The FSF changed postal address.
diego
parents:
8096
diff
changeset
|
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
7331
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 |
7436
ef1daba63c30
Sync with upstream version. According to Edouard Gomez:
kmkaplan
parents:
7331
diff
changeset
|
50 #define DEFAULT_TWOPASS_BOOST 1000 |
7331
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
51 #define DEFAULT_FPS 25.0f |
7436
ef1daba63c30
Sync with upstream version. According to Edouard Gomez:
kmkaplan
parents:
7331
diff
changeset
|
52 #define DEFAULT_CREDITS_SIZE 0 |
7331
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 |
23306
f37b8ec947ca
"inline" is used elsewhere and more portable than "__inline"
reimar
parents:
22316
diff
changeset
|
99 static inline int util_frametype(vbr_control_t *state) |
7331
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) |
8072
8e97c4629611
- When a frame is in the ending credits zone, say so.
rguyom
parents:
7436
diff
changeset
|
114 return(FRAME_TYPE_ENDING_CREDITS); |
7331
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 |
23306
f37b8ec947ca
"inline" is used elsewhere and more portable than "__inline"
reimar
parents:
22316
diff
changeset
|
123 static inline int util_creditsframes(vbr_control_t *state) |
7331
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 |
7436
ef1daba63c30
Sync with upstream version. According to Edouard Gomez:
kmkaplan
parents:
7331
diff
changeset
|
163 /* |
ef1daba63c30
Sync with upstream version. According to Edouard Gomez:
kmkaplan
parents:
7331
diff
changeset
|
164 * Default is a 2hour movie on 700Mo CD-ROM + 128kbit sound track |
ef1daba63c30
Sync with upstream version. According to Edouard Gomez:
kmkaplan
parents:
7331
diff
changeset
|
165 * This represents a target bitrate of 687kbit/s |
ef1daba63c30
Sync with upstream version. According to Edouard Gomez:
kmkaplan
parents:
7331
diff
changeset
|
166 */ |
7331
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
167 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
|
168 DEFAULT_MOVIE_LENGTH*3600*DEFAULT_AUDIO_BITRATE*1000/8; |
7436
ef1daba63c30
Sync with upstream version. According to Edouard Gomez:
kmkaplan
parents:
7331
diff
changeset
|
169 state->desired_bitrate = state->desired_size*8/(DEFAULT_MOVIE_LENGTH*3600); |
7331
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
170 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
171 /* Credits */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
172 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
|
173 state->credits_start = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
174 state->credits_start_begin = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
175 state->credits_start_end = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
176 state->credits_end = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
177 state->credits_end_begin = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
178 state->credits_end_end = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
179 state->credits_quant_ratio = 20; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
180 state->credits_fixed_quant = 20; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
181 state->credits_quant_i = 20; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
182 state->credits_quant_p = 20; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
183 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
|
184 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
|
185 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
186 /* Keyframe boost */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
187 state->keyframe_boost = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
188 state->kftreshold = 10; |
7436
ef1daba63c30
Sync with upstream version. According to Edouard Gomez:
kmkaplan
parents:
7331
diff
changeset
|
189 state->kfreduction = 30; |
7331
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
190 state->min_key_interval = 1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
191 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
|
192 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
193 /* Normal curve treatment */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
194 state->curve_compression_high = 25; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
195 state->curve_compression_low = 10; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
196 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
197 /* Alt curve */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
198 state->use_alt_curve = 1; |
29248 | 199 state->alt_curve_type = VBR_ALT_CURVE_LINEAR; |
7331
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
200 state->alt_curve_low_dist = 90; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
201 state->alt_curve_high_dist = 500; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
202 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
|
203 state->alt_curve_use_auto = 1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
204 state->alt_curve_auto_str = 30; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
205 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
|
206 state->alt_curve_bonus_bias = 50; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
207 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
|
208 state->bitrate_payback_delay = 250; |
7436
ef1daba63c30
Sync with upstream version. According to Edouard Gomez:
kmkaplan
parents:
7331
diff
changeset
|
209 state->twopass_max_bitrate = DEFAULT_TWOPASS_BOOST*state->desired_bitrate; |
7331
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
210 state->twopass_max_overflow_improvement = 60; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
211 state->twopass_max_overflow_degradation = 60; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
212 state->max_iquant = 31; |
7436
ef1daba63c30
Sync with upstream version. According to Edouard Gomez:
kmkaplan
parents:
7331
diff
changeset
|
213 state->min_iquant = 2; |
7331
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
214 state->max_pquant = 31; |
7436
ef1daba63c30
Sync with upstream version. According to Edouard Gomez:
kmkaplan
parents:
7331
diff
changeset
|
215 state->min_pquant = 2; |
7331
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
216 state->fixed_quant = 3; |
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 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
|
219 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
220 state->fps = (float)DEFAULT_FPS; |
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 return(0); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
223 |
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 |
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 * Function description : |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
228 * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
229 * This function initialiaze the vbr_control_t state passed in parameter. |
29248 | 230 * |
7331
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
231 * 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
|
232 * 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
|
233 * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
234 * Return values : |
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 * = 0 on success |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
237 * = -1 on error |
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 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
240 int vbrInit(vbr_control_t *state) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
241 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
242 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
243 if(state == NULL) return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
244 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
245 /* Function pointers safe initialization */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
246 state->init = NULL; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
247 state->getquant = NULL; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
248 state->getintra = NULL; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
249 state->update = NULL; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
250 state->finish = NULL; |
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) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
253 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
254 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
|
255 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
256 if(state->debug_file == NULL) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
257 return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
258 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
259 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
|
260 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
|
261 "| total bytes | kblocks | mblocks | ublocks" |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
262 "| vbr overflow | vbr kf overflow" |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
263 "| vbr kf partial overflow\n\n"); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
264 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
265 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
266 /* Function pointers sub case initialization */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
267 switch(state->mode) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
268 case VBR_MODE_1PASS: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
269 state->init = vbr_init_dummy; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
270 state->getquant = vbr_getquant_1pass; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
271 state->getintra = vbr_getintra_1pass; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
272 state->update = vbr_update_dummy; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
273 state->finish = vbr_finish_dummy; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
274 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
275 case VBR_MODE_2PASS_1: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
276 state->init = vbr_init_2pass1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
277 state->getquant = vbr_getquant_2pass1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
278 state->getintra = vbr_getintra_2pass1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
279 state->update = vbr_update_2pass1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
280 state->finish = vbr_finish_2pass1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
281 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
282 case VBR_MODE_FIXED_QUANT: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
283 state->init = vbr_init_fixedquant; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
284 state->getquant = vbr_getquant_fixedquant; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
285 state->getintra = vbr_getintra_fixedquant; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
286 state->update = vbr_update_dummy; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
287 state->finish = vbr_finish_dummy; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
288 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
289 case VBR_MODE_2PASS_2: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
290 state->init = vbr_init_2pass2; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
291 state->getintra = vbr_getintra_2pass2; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
292 state->getquant = vbr_getquant_2pass2; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
293 state->update = vbr_update_2pass2; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
294 state->finish = vbr_finish_2pass2; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
295 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
296 default: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
297 return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
298 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29248
diff
changeset
|
299 |
7331
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
300 return(state->init(state)); |
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 } |
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 /****************************************************************************** |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
305 * Function description : |
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 * 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
|
308 * controler state |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
309 * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
310 * Return values : |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
311 * the quantizer value (0 <= value <= 31) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
312 * (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
|
313 * |
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 int vbrGetQuant(vbr_control_t *state) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
317 { |
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 /* Returns Zero, so XviD decides alone */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
320 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
|
321 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
322 return(state->getquant(state)); |
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 } |
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 /****************************************************************************** |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
327 * Function description : |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
328 * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
329 * 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
|
330 * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
331 * Return values : |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
332 * = -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
|
333 * = 0 no I frame |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
334 * = 1 force keyframe |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
335 * |
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 int vbrGetIntra(vbr_control_t *state) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
339 { |
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 /* Returns -1, means let XviD decide */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
342 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
|
343 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
344 return(state->getintra(state)); |
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 } |
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 /****************************************************************************** |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
349 * Function description : |
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 * 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
|
352 * from XviD core |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
353 * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
354 * Return values : |
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 * = 0 on success |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
357 * = -1 on error |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
358 *****************************************************************************/ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
359 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
360 int vbrUpdate(vbr_control_t *state, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
361 int quant, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
362 int intra, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
363 int header_bytes, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
364 int total_bytes, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
365 int kblocks, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
366 int mblocks, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
367 int ublocks) |
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 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
370 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
|
371 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
372 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
|
373 int idx; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
374 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
375 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
|
376 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
|
377 mblocks, ublocks, state->overflow, state->KFoverflow, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
378 state->KFoverflow_partial); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
379 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
380 idx = quant; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
381 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
382 if(quant < 1) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
383 idx = 1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
384 if(quant > 31) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
385 idx = 31; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
386 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
387 idx--; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
388 |
29248 | 389 state->debug_quant_count[idx]++; |
7331
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
390 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
391 } |
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 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
|
394 kblocks, mblocks, ublocks)); |
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 } |
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 /****************************************************************************** |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
399 * Function description : |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
400 * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
401 * This function stops the vbr controller |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
402 * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
403 * Return values : |
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 * = 0 on success |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
406 * = -1 on error |
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 int vbrFinish(vbr_control_t *state) |
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 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
412 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
|
413 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
414 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
|
415 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
416 int i; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
417 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
418 fprintf(state->debug_file, "\n\n"); |
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 for(i=0; i<79; i++) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
421 fprintf(state->debug_file, "#"); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
422 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
423 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
|
424 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
425 for(i=0;i<32; i++) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
426 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
427 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
|
428 i+1, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
429 state->debug_quant_count[i]); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
430 |
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 fclose(state->debug_file); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
434 |
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 return(state->finish(state)); |
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 } |
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 * 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
|
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 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
|
446 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
447 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
448 vbr_control_t *state = sstate; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
449 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
450 state->cur_frame = 0; |
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 return(0); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
453 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
454 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
455 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
456 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
|
457 int quant, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
458 int intra, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
459 int header_bytes, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
460 int total_bytes, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
461 int kblocks, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
462 int mblocks, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
463 int ublocks) |
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 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
466 ((vbr_control_t*)state)->cur_frame++; |
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 return(0); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
469 |
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 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
|
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 return(0); |
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 } |
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 * 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
|
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 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
|
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 return(0); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
487 |
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 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
|
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 return(-1); |
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 } |
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 * 2 pass mode - first pass functions |
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 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
|
502 { |
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 FILE *f; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
505 vbr_control_t *state = sstate; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
506 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
507 /* Check the filename */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
508 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
|
509 return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
510 |
29248 | 511 /* Initialize safe defaults for 2pass 1 */ |
7331
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
512 state->pass1_file = NULL; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
513 state->nb_frames = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
514 state->nb_keyframes = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
515 state->cur_frame = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
516 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
517 /* Open the 1st pass file */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
518 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
|
519 return(-1); |
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 /* |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
522 * The File Header |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
523 * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
524 * 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
|
525 * 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
|
526 * 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
|
527 * encoding more than 4 billion frames :-) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
528 */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
529 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
|
530 fprintf(f, "# frames : \n"); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
531 fprintf(f, "# keyframes : \n"); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
532 fprintf(f, "#\n# quant | intra | header bytes | total bytes | kblocks |" |
29248 | 533 " mblocks | ublocks\n\n"); |
7331
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 /* Save file pointer */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
536 state->pass1_file = f; |
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 return(0); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
539 |
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 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
|
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 return(2); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
546 |
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 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
|
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 return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
553 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
554 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
555 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
556 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
|
557 int quant, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
558 int intra, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
559 int header_bytes, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
560 int total_bytes, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
561 int kblocks, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
562 int mblocks, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
563 int ublocks) |
29248 | 564 |
7331
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
565 |
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 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
568 vbr_control_t *state = sstate; |
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 if(state->pass1_file == NULL) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
571 return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
572 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
573 /* Writes the resulting statistics */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
574 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
|
575 quant, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
576 intra, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
577 header_bytes, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
578 total_bytes, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
579 kblocks, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
580 mblocks, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
581 ublocks); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
582 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
583 /* Update vbr control state */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
584 if(intra) state->nb_keyframes++; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
585 state->nb_frames++; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
586 state->cur_frame++; |
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 return(0); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29248
diff
changeset
|
589 |
7331
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 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
|
593 { |
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 int c, i; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
596 vbr_control_t *state = sstate; |
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 if(state->pass1_file == NULL) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
599 return(-1); |
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 /* Goto to the file beginning */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
602 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
|
603 |
8072
8e97c4629611
- When a frame is in the ending credits zone, say so.
rguyom
parents:
7436
diff
changeset
|
604 /* Skip the version line and the empty line */ |
7331
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
605 c = i = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
606 do { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
607 c = fgetc(state->pass1_file); |
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 if(c == EOF) return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
610 if(c == '\n') i++; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
611 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
612 }while(i < 2); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
613 |
8072
8e97c4629611
- When a frame is in the ending credits zone, say so.
rguyom
parents:
7436
diff
changeset
|
614 /* Prepare to write to the stream */ |
8085 | 615 fseek( state->pass1_file, 0L, SEEK_CUR ); |
8072
8e97c4629611
- When a frame is in the ending credits zone, say so.
rguyom
parents:
7436
diff
changeset
|
616 |
7331
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
617 /* 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
|
618 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
|
619 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
620 /* Overwrite the keyframe field */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
621 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
|
622 state->nb_keyframes); |
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 /* Close the file */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
625 if(fclose(state->pass1_file) != 0) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
626 return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
627 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
628 return(0); |
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 } |
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 * 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
|
634 *****************************************************************************/ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
635 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
636 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
|
637 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
638 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
639 FILE *f; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
640 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
|
641 long long credits1_bytes; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
642 long long credits2_bytes; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
643 long long desired; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
644 long long total_bytes; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
645 long long itotal_bytes; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
646 long long start_curved; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
647 long long end_curved; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
648 double total1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
649 double total2; |
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 vbr_control_t *state = sstate; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
652 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
653 /* Check the filename */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
654 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
|
655 return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
656 |
29248 | 657 /* Initialize safe defaults for 2pass 2 */ |
7331
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
658 state->pass1_file = NULL; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
659 state->nb_frames = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
660 state->nb_keyframes = 0; |
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 /* Open the 1st pass file */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
663 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
|
664 return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
665 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
666 state->pass1_file = f; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
667 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
668 /* 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
|
669 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
|
670 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
671 if(n != VBR_VERSION) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
672 fclose(state->pass1_file); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
673 state->pass1_file = NULL; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
674 return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
675 } |
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 /* Skip the blank commented line */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
678 c = n = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
679 do { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
680 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
681 c = fgetc(state->pass1_file); |
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 == EOF) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
684 fclose(state->pass1_file); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
685 state->pass1_file = NULL; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
686 return(-1); |
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 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
689 if(c == '\n') n++; |
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 }while(n < 1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
692 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
693 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
694 /* Get the number of frames */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
695 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
|
696 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
697 /* Compute the desired size */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
698 state->desired_size = (long long) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
699 (((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
|
700 (state->fps * 8.0)); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
701 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
702 /* Get the number of keyframes */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
703 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
|
704 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
705 /* 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
|
706 if((state->keyframe_locations |
18869 | 707 = malloc((state->nb_keyframes+1)*sizeof(int))) == NULL) { |
7331
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
708 fclose(state->pass1_file); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
709 state->pass1_file = NULL; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
710 return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
711 } |
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 /* 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
|
714 c = n = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
715 do { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
716 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
717 c = fgetc(state->pass1_file); |
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 == EOF) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
720 fclose(state->pass1_file); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
721 state->pass1_file = NULL; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
722 return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
723 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
724 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
725 if(c == '\n') n++; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
726 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
727 }while(n < 2); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
728 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
729 /* Save position for future use */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
730 pos_firstframe = ftell(state->pass1_file); |
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 /* Read and initialize some variables */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
733 credits1_bytes = credits2_bytes = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
734 total_bytes = itotal_bytes = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
735 start_curved = end_curved = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
736 credits_frames = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
737 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
738 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
|
739 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
740 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
|
741 int kblocks, mblocks, ublocks; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
742 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
743 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
|
744 &quant, &keyframe, &frame_hbytes, &frame_bytes, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
745 &kblocks, &mblocks, &ublocks); |
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 /* 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
|
748 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
|
749 credits1_bytes += frame_bytes; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
750 credits_frames++; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
751 continue; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
752 } |
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 /* 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
|
755 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
|
756 credits2_bytes += frame_bytes; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
757 credits_frames++; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
758 continue; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
759 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
760 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
761 /* 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
|
762 if(keyframe) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
763 itotal_bytes += frame_bytes + frame_bytes * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
764 state->keyframe_boost / 100; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
765 total_bytes += frame_bytes * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
766 state->keyframe_boost / 100; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
767 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
|
768 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
769 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29248
diff
changeset
|
770 total_bytes += frame_bytes; |
7331
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 } |
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 /* |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
775 * 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
|
776 * all other the last film segment |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
777 */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
778 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
|
779 |
8096 | 780 desired = state->desired_size; |
7331
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
781 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
782 switch(state->credits_mode) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
783 case VBR_CREDITS_MODE_QUANT : |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
784 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
785 state->movie_curve = (double) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
786 (total_bytes - credits1_bytes - credits2_bytes) / |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
787 (desired - credits1_bytes - credits2_bytes); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
788 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
789 start_curved = credits1_bytes; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
790 end_curved = credits2_bytes; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
791 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
792 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
793 case VBR_CREDITS_MODE_SIZE: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
794 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
795 /* start curve = (start / start desired size) */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
796 state->credits_start_curve = (double) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
797 (credits1_bytes / state->credits_start_size); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
798 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
799 /* end curve = (end / end desired size) */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
800 state->credits_end_curve = (double) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
801 (credits2_bytes / state->credits_end_size); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
802 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
803 start_curved = (long long) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
804 (credits1_bytes / state->credits_start_curve); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
805 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
806 end_curved = (long long) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
807 (credits2_bytes / state->credits_end_curve); |
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 /* 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
|
810 state->movie_curve = (double) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
811 (total_bytes - credits1_bytes - credits2_bytes) / |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
812 (desired - start_curved - end_curved); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
813 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
814 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
815 case VBR_CREDITS_MODE_RATE: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
816 default: |
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 /* 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
|
819 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
|
820 ((double)total_bytes / desired) * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
821 ((double)100 / state->credits_quant_ratio); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
822 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
823 start_curved = |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
824 (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
|
825 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
826 end_curved = |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
827 (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
|
828 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
829 state->movie_curve = (double) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
830 (total_bytes - credits1_bytes - credits2_bytes) / |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
831 (desired - start_curved - end_curved); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
832 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
833 break; |
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 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
836 /* |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
837 * 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
|
838 * (frames - credits frames - keyframes) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
839 */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
840 state->average_frame = (double) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
841 (desired - start_curved - end_curved - |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
842 (itotal_bytes / state->movie_curve)) / |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
843 (state->nb_frames - util_creditsframes(state) - |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
844 state->nb_keyframes); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
845 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
846 /* Initialize alt curve parameters */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
847 if (state->use_alt_curve) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
848 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
849 state->alt_curve_low = |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
850 state->average_frame - state->average_frame * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
851 (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
|
852 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
853 state->alt_curve_low_diff = |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
854 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
|
855 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
856 state->alt_curve_high = |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
857 state->average_frame + state->average_frame * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
858 (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
|
859 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
860 state->alt_curve_high_diff = |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
861 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
|
862 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
863 if (state->alt_curve_use_auto) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
864 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
865 if (state->movie_curve > 1.0) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
866 |
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 = |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
868 (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
|
869 (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
|
870 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
871 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
|
872 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
|
873 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
874 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
875 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
|
876 } |
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 } |
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 state->alt_curve_mid_qual = |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
881 (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
|
882 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
883 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
|
884 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
885 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
|
886 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
887 switch(state->alt_curve_type) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
888 case VBR_ALT_CURVE_AGGRESIVE: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
889 /* Sine Curve (high aggressiveness) */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
890 state->alt_curve_qual_dev *= |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
891 2.0 / |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
892 (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
|
893 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
894 state->alt_curve_mid_qual = |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
895 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
|
896 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
|
897 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
898 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
899 default: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
900 case VBR_ALT_CURVE_LINEAR: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
901 /* Linear (medium aggressiveness) */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
902 state->alt_curve_qual_dev *= |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
903 2.0 / |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
904 (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
|
905 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
906 state->alt_curve_mid_qual = |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
907 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
|
908 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
|
909 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
910 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
911 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
912 case VBR_ALT_CURVE_SOFT: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
913 /* Cosine Curve (low aggressiveness) */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
914 state->alt_curve_qual_dev *= |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
915 2.0 / |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
916 (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
|
917 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
918 state->alt_curve_mid_qual = |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
919 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
|
920 (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
|
921 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
922 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
923 } |
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 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
926 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
927 /* 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
|
928 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
|
929 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
930 /* 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
|
931 total1 = total2 = 0.0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
932 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
|
933 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
934 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
|
935 int kblocks, mblocks, ublocks; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
936 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
937 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
|
938 &quant, &keyframe, &frame_hbytes, &frame_bytes, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
939 &kblocks, &mblocks, &ublocks); |
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 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
|
942 continue; |
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(!keyframe) { |
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 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
|
947 total1 += dbytes; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
948 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
949 if (state->use_alt_curve) { |
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 if (dbytes > state->average_frame) { |
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 if (dbytes >= state->alt_curve_high) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
954 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
|
955 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
956 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
957 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
958 switch(state->alt_curve_type) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
959 case VBR_ALT_CURVE_AGGRESIVE: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
960 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
961 total2 += |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
962 dbytes * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
963 (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
|
964 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
|
965 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
966 default: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
967 case VBR_ALT_CURVE_LINEAR: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
968 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
969 total2 += |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
970 dbytes * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
971 (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
|
972 (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
|
973 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
974 case VBR_ALT_CURVE_SOFT: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
975 total2 += |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
976 dbytes * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
977 (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
|
978 (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
|
979 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
980 } |
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 if (dbytes <= state->alt_curve_low) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
985 total2 += dbytes; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
986 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
987 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
988 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
989 switch(state->alt_curve_type) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
990 case VBR_ALT_CURVE_AGGRESIVE: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
991 total2 += |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
992 dbytes * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
993 (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
|
994 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
|
995 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
996 default: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
997 case VBR_ALT_CURVE_LINEAR: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
998 total2 += |
29248 | 999 dbytes * |
7331
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1000 (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
|
1001 (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
|
1002 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1003 case VBR_ALT_CURVE_SOFT: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1004 total2 += |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1005 dbytes * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1006 (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
|
1007 (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
|
1008 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1009 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1010 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1011 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1012 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1013 if (dbytes > state->average_frame) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1014 total2 += |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1015 ((double)dbytes + |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1016 (state->average_frame - dbytes) * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1017 state->curve_compression_high / 100.0); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1018 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1019 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1020 total2 += |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1021 ((double)dbytes + |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1022 (state->average_frame - dbytes) * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1023 state->curve_compression_low / 100.0); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1024 } |
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 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1027 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29248
diff
changeset
|
1028 |
7331
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1029 state->curve_comp_scale = total1 / total2; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1030 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1031 if (state->use_alt_curve) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1032 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1033 double curve_temp, dbytes; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1034 int newquant, percent; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1035 int oldquant = 1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1036 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1037 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
|
1038 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
|
1039 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1040 state->curve_bias_bonus = |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1041 (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
|
1042 (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
|
1043 state->curve_comp_scale = |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1044 ((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
|
1045 total2; |
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 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1048 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
|
1049 dbytes = n; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1050 if (dbytes > state->average_frame) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1051 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1052 if (dbytes >= state->alt_curve_high) { |
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 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1055 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1056 switch(state->alt_curve_type) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1057 case VBR_ALT_CURVE_AGGRESIVE: |
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 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
|
1060 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1061 default: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1062 case VBR_ALT_CURVE_LINEAR: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1063 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
|
1064 (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
|
1065 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1066 case VBR_ALT_CURVE_SOFT: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1067 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
|
1068 (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
|
1069 } |
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 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1072 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1073 if (dbytes <= state->alt_curve_low) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1074 curve_temp = dbytes; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1075 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1076 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1077 switch(state->alt_curve_type) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1078 case VBR_ALT_CURVE_AGGRESIVE: |
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 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
|
1081 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1082 default: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1083 case VBR_ALT_CURVE_LINEAR: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1084 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
|
1085 (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
|
1086 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1087 case VBR_ALT_CURVE_SOFT: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1088 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
|
1089 (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
|
1090 } |
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 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1093 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1094 if (state->movie_curve > 1.0) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1095 dbytes *= state->movie_curve; |
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 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
|
1098 if (newquant > 1) |
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 if (newquant != oldquant) |
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 oldquant = newquant; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1103 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
|
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 } |
29248 | 1107 |
7331
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1108 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1109 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1110 } |
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 state->overflow = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1113 state->KFoverflow = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1114 state->KFoverflow_partial = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1115 state->KF_idx = 1; |
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 for (n=0 ; n < 32 ; n++) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1118 state->quant_error[n] = 0.0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1119 state->quant_count[n] = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1120 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1121 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1122 state->curve_comp_error = 0.0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1123 state->last_quant = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1124 |
7436
ef1daba63c30
Sync with upstream version. According to Edouard Gomez:
kmkaplan
parents:
7331
diff
changeset
|
1125 /* |
ef1daba63c30
Sync with upstream version. According to Edouard Gomez:
kmkaplan
parents:
7331
diff
changeset
|
1126 * Above this frame size limit, normal vbr rules will not apply |
ef1daba63c30
Sync with upstream version. According to Edouard Gomez:
kmkaplan
parents:
7331
diff
changeset
|
1127 * This means : |
ef1daba63c30
Sync with upstream version. According to Edouard Gomez:
kmkaplan
parents:
7331
diff
changeset
|
1128 * 1 - Quant can de/increase more than -/+2 between 2 frames |
ef1daba63c30
Sync with upstream version. According to Edouard Gomez:
kmkaplan
parents:
7331
diff
changeset
|
1129 * 2 - Leads to artifacts because of 1 |
ef1daba63c30
Sync with upstream version. According to Edouard Gomez:
kmkaplan
parents:
7331
diff
changeset
|
1130 */ |
ef1daba63c30
Sync with upstream version. According to Edouard Gomez:
kmkaplan
parents:
7331
diff
changeset
|
1131 state->max_framesize = state->twopass_max_bitrate/state->fps; |
7331
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1132 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1133 /* 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
|
1134 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
|
1135 |
29248 | 1136 /* |
7331
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1137 * 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
|
1138 * getintra/quant calls |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1139 * 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
|
1140 * 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
|
1141 * the overflow and so on... |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1142 */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1143 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1144 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1145 /* Fake vars */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1146 int next_hbytes, next_kblocks, next_mblocks, next_ublocks; |
29248 | 1147 |
7331
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1148 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
|
1149 &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
|
1150 &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
|
1151 &next_ublocks); |
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 } |
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 /* Initialize the frame counter */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1156 state->cur_frame = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1157 state->last_keyframe = 0; |
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 return(0); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1160 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1161 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1162 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1163 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
|
1164 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1165 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1166 int quant; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1167 int intra; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1168 int bytes1, bytes2; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1169 int overflow; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1170 int capped_to_max_framesize = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1171 int KFdistance, KF_min_size; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1172 vbr_control_t *state = sstate; |
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 bytes1 = state->pass1_bytes; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1175 overflow = state->overflow / 8; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1176 /* To shut up gcc warning */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1177 bytes2 = bytes1; |
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 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1180 if (state->pass1_intra) |
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 overflow = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1183 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1184 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1185 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
|
1186 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1187 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1188 switch (state->credits_mode) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1189 case VBR_CREDITS_MODE_QUANT : |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1190 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
|
1191 quant = state->pass1_intra ? |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1192 state->credits_quant_i: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1193 state->credits_quant_p; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1194 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1195 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1196 quant = state->credits_quant_p; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1197 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1198 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1199 state->bytes1 = bytes1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1200 state->bytes2 = bytes1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1201 state->desired_bytes2 = bytes1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1202 return(quant); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1203 default: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1204 case VBR_CREDITS_MODE_RATE : |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1205 case VBR_CREDITS_MODE_SIZE : |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1206 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
|
1207 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
|
1208 else |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1209 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
|
1210 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1211 } |
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 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1214 /* Foxer: apply curve compression outside credits */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1215 double dbytes, curve_temp; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1216 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1217 bytes2 = bytes1; |
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 if (state->pass1_intra) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1220 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
|
1221 state->movie_curve; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1222 else |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1223 dbytes = bytes2 / state->movie_curve; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1224 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1225 /* 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
|
1226 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
|
1227 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
|
1228 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1229 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1230 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
|
1231 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
|
1232 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1233 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
|
1234 bytes2 = (int)state->curve_comp_error; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1235 } |
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 state->curve_comp_error -= bytes2; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1238 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1239 if (state->use_alt_curve) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1240 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1241 if (!state->pass1_intra) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1242 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1243 if (dbytes > state->average_frame) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1244 if (dbytes >= state->alt_curve_high) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1245 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
|
1246 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1247 switch(state->alt_curve_type) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1248 case VBR_ALT_CURVE_AGGRESIVE: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1249 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
|
1250 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
|
1251 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1252 default: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1253 case VBR_ALT_CURVE_LINEAR: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1254 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
|
1255 (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
|
1256 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1257 case VBR_ALT_CURVE_SOFT: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1258 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
|
1259 (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
|
1260 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1261 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1262 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1263 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1264 if (dbytes <= state->alt_curve_low) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1265 curve_temp = dbytes; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1266 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1267 switch(state->alt_curve_type) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1268 case VBR_ALT_CURVE_AGGRESIVE: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1269 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
|
1270 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
|
1271 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1272 default: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1273 case VBR_ALT_CURVE_LINEAR: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1274 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
|
1275 (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
|
1276 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1277 case VBR_ALT_CURVE_SOFT: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1278 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
|
1279 (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
|
1280 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1281 } |
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 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
|
1285 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1286 bytes2 += ((int)curve_temp); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1287 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
|
1288 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1289 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1290 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1291 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
|
1292 bytes2 += ((int)dbytes); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1293 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1294 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1295 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
|
1296 !state->pass1_intra) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1297 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1298 if (dbytes > state->average_frame) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1299 curve_temp = state->curve_comp_scale * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1300 ((double)dbytes + (state->average_frame - dbytes) * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1301 state->curve_compression_high / 100.0); |
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 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1304 curve_temp = state->curve_comp_scale * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1305 ((double)dbytes + (state->average_frame - dbytes) * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1306 state->curve_compression_low / 100.0); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1307 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1308 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1309 bytes2 += ((int)curve_temp); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1310 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
|
1311 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1312 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1313 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
|
1314 bytes2 += ((int)dbytes); |
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 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1317 /* 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
|
1318 if (bytes2 > bytes1) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1319 state->curve_comp_error += bytes2 - bytes1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1320 bytes2 = bytes1; |
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 else if (bytes2 < 1) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1323 state->curve_comp_error += --bytes2; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1324 bytes2 = 1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1325 } |
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 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1328 state->desired_bytes2 = bytes2; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1329 |
22316
f3d7a1b58a82
cosmetics: Fix some common typos, appropiate --> appropRiate,
diego
parents:
18869
diff
changeset
|
1330 /* Ugly dependence between getquant and getintra */ |
7331
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1331 intra = state->getintra(state); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1332 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1333 if(intra) { |
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 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
|
1336 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
|
1337 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1338 if (KFdistance < state->kftreshold) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1339 KFdistance = KFdistance - state->min_key_interval; |
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 if (KFdistance >= 0) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1342 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1343 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
|
1344 if (KF_min_size < 1) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1345 KF_min_size = 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 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
|
1348 (state->kftreshold - state->min_key_interval); |
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 if (bytes2 < 1) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1351 bytes2 = 1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1352 } |
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 } |
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 /* |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1357 * 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
|
1358 * too much/little bitrate |
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 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
|
1361 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1362 /* 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
|
1363 if (labs(overflow) > labs(state->overflow)) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1364 overflow = state->overflow; |
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 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1367 /* 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
|
1368 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
|
1369 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
|
1370 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
|
1371 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1372 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
|
1373 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
|
1374 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1375 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1376 bytes2 += overflow; |
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 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1379 if(bytes2 > state->max_framesize) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1380 capped_to_max_framesize = 1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1381 bytes2 = state->max_framesize; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1382 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1383 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1384 if(bytes2 < 1) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1385 bytes2 = 1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1386 } |
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 state->bytes1 = bytes1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1389 state->bytes2 = bytes2; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1390 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1391 /* very 'simple' quant<->filesize relationship */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1392 quant = state->pass1_quant * bytes1 / bytes2; |
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 if(quant < 1) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1395 quant = 1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1396 else if(quant > 31) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1397 quant = 31; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1398 else if(!state->pass1_intra) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1399 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1400 /* 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
|
1401 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
|
1402 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1403 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
|
1404 state->quant_error[quant] -= 1.0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1405 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 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1409 /* we're done with credits */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1410 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
|
1411 return(quant); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1412 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1413 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1414 if(intra) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1415 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1416 if (quant < state->min_iquant) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1417 quant = state->min_iquant; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1418 if (quant > state->max_iquant) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1419 quant = state->max_iquant; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1420 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1421 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1422 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1423 if(quant > state->max_pquant) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1424 quant = state->max_pquant; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1425 if(quant < state->min_pquant) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1426 quant = state->min_pquant; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1427 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1428 /* 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
|
1429 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
|
1430 if (quant > state->last_quant + 2) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1431 quant = state->last_quant + 2; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1432 if (quant < state->last_quant - 2) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1433 quant = state->last_quant - 2; |
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 } |
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 return(quant); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1438 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1439 } |
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 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
|
1442 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1443 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1444 int intra; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1445 vbr_control_t *state = sstate; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1446 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29248
diff
changeset
|
1447 |
7331
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1448 /* 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
|
1449 intra = state->pass1_intra; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1450 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1451 /* During credits, XviD will decide itself */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1452 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
|
1453 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1454 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1455 switch(state->credits_mode) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1456 default: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1457 case VBR_CREDITS_MODE_RATE : |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1458 case VBR_CREDITS_MODE_SIZE : |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1459 intra = -1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1460 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1461 case VBR_CREDITS_MODE_QUANT : |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1462 /* Except in this case */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1463 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
|
1464 intra = -1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1465 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1466 } |
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 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1470 /* 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
|
1471 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
|
1472 intra = 1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1473 |
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 * 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
|
1476 * requested minimum |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1477 */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1478 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
|
1479 intra = 0; |
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 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1482 /* 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
|
1483 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
|
1484 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1485 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1486 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1487 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
|
1488 int quant, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1489 int intra, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1490 int header_bytes, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1491 int total_bytes, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1492 int kblocks, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1493 int mblocks, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1494 int ublocks) |
29248 | 1495 |
7331
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 { |
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 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
|
1501 int tempdiv; |
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 vbr_control_t *state = sstate; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1504 |
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 * 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
|
1507 * from the xvid core |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1508 */ |
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 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
|
1511 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1512 state->quant_count[quant]++; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1513 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1514 if (state->pass1_intra) { |
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 state->overflow += state->KFoverflow; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1517 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
|
1518 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1519 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
|
1520 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
|
1521 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1522 /* redistribute correctly (by koepi) */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1523 if (tempdiv > 1) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1524 /* non-consecutive keyframes */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1525 state->KFoverflow_partial = state->KFoverflow / |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1526 (tempdiv - 1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1527 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1528 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1529 state->overflow += state->KFoverflow; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1530 state->KFoverflow = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1531 state->KFoverflow_partial = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1532 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1533 state->KF_idx++; |
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 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
|
1538 state->KFoverflow_partial; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1539 state->KFoverflow -= state->KFoverflow_partial; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1540 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1541 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1542 else { |
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 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
|
1545 state->overflow += state->KFoverflow; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1546 state->KFoverflow = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1547 state->KFoverflow_partial = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1548 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1549 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1550 /* Save old quant */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1551 state->last_quant = quant; |
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 /* Update next frame data */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1554 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
|
1555 &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
|
1556 &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
|
1557 &next_ublocks); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1558 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1559 /* Save the last Keyframe pos */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1560 if(intra) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1561 state->last_keyframe = state->cur_frame; |
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 /* Ok next frame */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1564 state->cur_frame++; |
29248 | 1565 |
7331
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1566 return(0); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1567 |
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 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1570 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
|
1571 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1572 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1573 vbr_control_t *state = sstate; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1574 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1575 if(state->pass1_file == NULL) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1576 return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1577 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1578 /* Close the file */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1579 if(fclose(state->pass1_file) != 0) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1580 return(-1); |
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 /* Free the memory */ |
32511
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
29263
diff
changeset
|
1583 free(state->keyframe_locations); |
7331
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 return(0); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1586 |
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 |
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 * 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
|
1592 *****************************************************************************/ |
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 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
|
1595 { |
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 vbr_control_t *state = sstate; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1598 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1599 if(state->fixed_quant < 1) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1600 state->fixed_quant = 1; |
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 if(state->fixed_quant > 31) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1603 state->fixed_quant = 31; |
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 state->cur_frame = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1606 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1607 return(0); |
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 } |
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 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
|
1612 { |
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 vbr_control_t *state = sstate; |
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 /* Credits' frame ? */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1617 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
|
1618 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1619 int quant; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1620 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1621 switch(state->credits_mode) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1622 case VBR_CREDITS_MODE_RATE: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1623 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
|
1624 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1625 case VBR_CREDITS_MODE_QUANT: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1626 quant = state->credits_fixed_quant; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1627 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1628 default: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1629 quant = state->fixed_quant; |
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 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1633 return(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 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29248
diff
changeset
|
1636 |
7331
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1637 /* No credit frame - return fixed quant */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1638 return(state->fixed_quant); |
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 } |
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 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
|
1643 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1644 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1645 return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1646 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1647 } |