Mercurial > mplayer.hg
annotate xvid_vbr.c @ 37172:cad608ae7295
Fix incorrect use of pal2gray_alpha for av_sub.
It would clear previously draw subtitle rectangles
at the same vertical position, and it could potentially
write outside the destination.
author | reimar |
---|---|
date | Sat, 06 Sep 2014 19:52:00 +0000 |
parents | 50ba718698ea |
children |
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 */ |
35241
3ca6a7d60396
Fix typo causing memset to not properly initialize the struct.
reimar
parents:
32511
diff
changeset
|
155 memset(state, 0, sizeof(*state)); |
7331
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 */ |
37044
50ba718698ea
xvid_vbr: Sanity-check parsed variable before using it to malloc.
reimar
parents:
35241
diff
changeset
|
706 if(state->nb_keyframes < 0 || |
50ba718698ea
xvid_vbr: Sanity-check parsed variable before using it to malloc.
reimar
parents:
35241
diff
changeset
|
707 state->nb_keyframes >= 0x7fffffff / sizeof(int) || |
50ba718698ea
xvid_vbr: Sanity-check parsed variable before using it to malloc.
reimar
parents:
35241
diff
changeset
|
708 (state->keyframe_locations |
18869 | 709 = 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
|
710 fclose(state->pass1_file); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
711 state->pass1_file = NULL; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
712 return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
713 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
714 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
715 /* 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
|
716 c = n = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
717 do { |
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 c = fgetc(state->pass1_file); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
720 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
721 if(c == EOF) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
722 fclose(state->pass1_file); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
723 state->pass1_file = NULL; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
724 return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
725 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
726 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
727 if(c == '\n') n++; |
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 }while(n < 2); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
730 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
731 /* Save position for future use */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
732 pos_firstframe = ftell(state->pass1_file); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
733 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
734 /* Read and initialize some variables */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
735 credits1_bytes = credits2_bytes = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
736 total_bytes = itotal_bytes = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
737 start_curved = end_curved = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
738 credits_frames = 0; |
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 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
|
741 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
742 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
|
743 int kblocks, mblocks, ublocks; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
744 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
745 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
|
746 &quant, &keyframe, &frame_hbytes, &frame_bytes, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
747 &kblocks, &mblocks, &ublocks); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
748 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
749 /* 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
|
750 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
|
751 credits1_bytes += frame_bytes; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
752 credits_frames++; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
753 continue; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
754 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
755 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
756 /* 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
|
757 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
|
758 credits2_bytes += frame_bytes; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
759 credits_frames++; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
760 continue; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
761 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
762 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
763 /* 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
|
764 if(keyframe) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
765 itotal_bytes += frame_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 total_bytes += frame_bytes * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
768 state->keyframe_boost / 100; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
769 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
|
770 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
771 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29248
diff
changeset
|
772 total_bytes += frame_bytes; |
7331
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 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
776 /* |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
777 * 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
|
778 * all other the last film segment |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
779 */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
780 state->keyframe_locations[c] = state->cur_frame; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
781 |
8096 | 782 desired = state->desired_size; |
7331
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
783 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
784 switch(state->credits_mode) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
785 case VBR_CREDITS_MODE_QUANT : |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
786 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
787 state->movie_curve = (double) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
788 (total_bytes - credits1_bytes - credits2_bytes) / |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
789 (desired - credits1_bytes - credits2_bytes); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
790 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
791 start_curved = credits1_bytes; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
792 end_curved = credits2_bytes; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
793 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
794 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
795 case VBR_CREDITS_MODE_SIZE: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
796 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
797 /* start curve = (start / start desired size) */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
798 state->credits_start_curve = (double) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
799 (credits1_bytes / state->credits_start_size); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
800 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
801 /* end curve = (end / end desired size) */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
802 state->credits_end_curve = (double) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
803 (credits2_bytes / state->credits_end_size); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
804 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
805 start_curved = (long long) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
806 (credits1_bytes / state->credits_start_curve); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
807 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
808 end_curved = (long long) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
809 (credits2_bytes / state->credits_end_curve); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
810 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
811 /* 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
|
812 state->movie_curve = (double) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
813 (total_bytes - credits1_bytes - credits2_bytes) / |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
814 (desired - start_curved - end_curved); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
815 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
816 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
817 case VBR_CREDITS_MODE_RATE: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
818 default: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
819 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
820 /* 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
|
821 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
|
822 ((double)total_bytes / desired) * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
823 ((double)100 / state->credits_quant_ratio); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
824 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
825 start_curved = |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
826 (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
|
827 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
828 end_curved = |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
829 (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
|
830 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
831 state->movie_curve = (double) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
832 (total_bytes - credits1_bytes - credits2_bytes) / |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
833 (desired - start_curved - end_curved); |
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 break; |
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 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
838 /* |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
839 * 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
|
840 * (frames - credits frames - keyframes) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
841 */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
842 state->average_frame = (double) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
843 (desired - start_curved - end_curved - |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
844 (itotal_bytes / state->movie_curve)) / |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
845 (state->nb_frames - util_creditsframes(state) - |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
846 state->nb_keyframes); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
847 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
848 /* Initialize alt curve parameters */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
849 if (state->use_alt_curve) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
850 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
851 state->alt_curve_low = |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
852 state->average_frame - state->average_frame * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
853 (double)(state->alt_curve_low_dist / 100.0); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
854 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
855 state->alt_curve_low_diff = |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
856 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
|
857 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
858 state->alt_curve_high = |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
859 state->average_frame + state->average_frame * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
860 (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
|
861 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
862 state->alt_curve_high_diff = |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
863 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
|
864 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
865 if (state->alt_curve_use_auto) { |
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 if (state->movie_curve > 1.0) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
868 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
869 state->alt_curve_min_rel_qual = |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
870 (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
|
871 (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
|
872 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
873 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
|
874 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
|
875 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
876 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
877 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
|
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 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
881 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
882 state->alt_curve_mid_qual = |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
883 (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
|
884 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
885 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
|
886 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
887 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
|
888 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
889 switch(state->alt_curve_type) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
890 case VBR_ALT_CURVE_AGGRESIVE: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
891 /* Sine Curve (high aggressiveness) */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
892 state->alt_curve_qual_dev *= |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
893 2.0 / |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
894 (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
|
895 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
896 state->alt_curve_mid_qual = |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
897 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
|
898 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
|
899 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
900 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
901 default: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
902 case VBR_ALT_CURVE_LINEAR: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
903 /* Linear (medium aggressiveness) */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
904 state->alt_curve_qual_dev *= |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
905 2.0 / |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
906 (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
|
907 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
908 state->alt_curve_mid_qual = |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
909 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
|
910 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
|
911 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
912 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
913 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
914 case VBR_ALT_CURVE_SOFT: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
915 /* Cosine Curve (low aggressiveness) */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
916 state->alt_curve_qual_dev *= |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
917 2.0 / |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
918 (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
|
919 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
920 state->alt_curve_mid_qual = |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
921 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
|
922 (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
|
923 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
924 break; |
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 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
928 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
929 /* 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
|
930 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
|
931 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
932 /* 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
|
933 total1 = total2 = 0.0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
934 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
|
935 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
936 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
|
937 int kblocks, mblocks, ublocks; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
938 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
939 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
|
940 &quant, &keyframe, &frame_hbytes, &frame_bytes, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
941 &kblocks, &mblocks, &ublocks); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
942 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
943 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
|
944 continue; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
945 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
946 if(!keyframe) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
947 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
948 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
|
949 total1 += dbytes; |
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 (state->use_alt_curve) { |
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->average_frame) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
954 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
955 if (dbytes >= state->alt_curve_high) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
956 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
|
957 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
958 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
959 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
960 switch(state->alt_curve_type) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
961 case VBR_ALT_CURVE_AGGRESIVE: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
962 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
963 total2 += |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
964 dbytes * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
965 (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
|
966 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
|
967 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
968 default: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
969 case VBR_ALT_CURVE_LINEAR: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
970 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
971 total2 += |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
972 dbytes * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
973 (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
|
974 (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
|
975 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
976 case VBR_ALT_CURVE_SOFT: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
977 total2 += |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
978 dbytes * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
979 (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
|
980 (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
|
981 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
982 } |
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 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
985 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
986 if (dbytes <= state->alt_curve_low) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
987 total2 += dbytes; |
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 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
990 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
991 switch(state->alt_curve_type) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
992 case VBR_ALT_CURVE_AGGRESIVE: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
993 total2 += |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
994 dbytes * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
995 (state->alt_curve_mid_qual - state->alt_curve_qual_dev * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
996 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
|
997 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
998 default: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
999 case VBR_ALT_CURVE_LINEAR: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1000 total2 += |
29248 | 1001 dbytes * |
7331
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1002 (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
|
1003 (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
|
1004 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1005 case VBR_ALT_CURVE_SOFT: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1006 total2 += |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1007 dbytes * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1008 (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
|
1009 (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
|
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 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1013 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1014 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1015 if (dbytes > state->average_frame) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1016 total2 += |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1017 ((double)dbytes + |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1018 (state->average_frame - dbytes) * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1019 state->curve_compression_high / 100.0); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1020 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1021 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1022 total2 += |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1023 ((double)dbytes + |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1024 (state->average_frame - dbytes) * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1025 state->curve_compression_low / 100.0); |
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 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1028 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1029 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29248
diff
changeset
|
1030 |
7331
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1031 state->curve_comp_scale = total1 / total2; |
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 if (state->use_alt_curve) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1034 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1035 double curve_temp, dbytes; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1036 int newquant, percent; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1037 int oldquant = 1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1038 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1039 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
|
1040 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
|
1041 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1042 state->curve_bias_bonus = |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1043 (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
|
1044 (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
|
1045 state->curve_comp_scale = |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1046 ((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
|
1047 total2; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1048 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1049 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1050 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
|
1051 dbytes = n; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1052 if (dbytes > state->average_frame) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1053 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1054 if (dbytes >= state->alt_curve_high) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1055 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
|
1056 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1057 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1058 switch(state->alt_curve_type) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1059 case VBR_ALT_CURVE_AGGRESIVE: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1060 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
|
1061 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
|
1062 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1063 default: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1064 case VBR_ALT_CURVE_LINEAR: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1065 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
|
1066 (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
|
1067 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1068 case VBR_ALT_CURVE_SOFT: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1069 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
|
1070 (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
|
1071 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1072 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1073 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1074 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1075 if (dbytes <= state->alt_curve_low) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1076 curve_temp = dbytes; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1077 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1078 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1079 switch(state->alt_curve_type) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1080 case VBR_ALT_CURVE_AGGRESIVE: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1081 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
|
1082 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
|
1083 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1084 default: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1085 case VBR_ALT_CURVE_LINEAR: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1086 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
|
1087 (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
|
1088 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1089 case VBR_ALT_CURVE_SOFT: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1090 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
|
1091 (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
|
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 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1095 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1096 if (state->movie_curve > 1.0) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1097 dbytes *= state->movie_curve; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1098 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1099 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
|
1100 if (newquant > 1) |
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 if (newquant != oldquant) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1103 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1104 oldquant = newquant; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1105 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
|
1106 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1107 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1108 } |
29248 | 1109 |
7331
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 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1113 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1114 state->overflow = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1115 state->KFoverflow = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1116 state->KFoverflow_partial = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1117 state->KF_idx = 1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1118 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1119 for (n=0 ; n < 32 ; n++) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1120 state->quant_error[n] = 0.0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1121 state->quant_count[n] = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1122 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1123 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1124 state->curve_comp_error = 0.0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1125 state->last_quant = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1126 |
7436
ef1daba63c30
Sync with upstream version. According to Edouard Gomez:
kmkaplan
parents:
7331
diff
changeset
|
1127 /* |
ef1daba63c30
Sync with upstream version. According to Edouard Gomez:
kmkaplan
parents:
7331
diff
changeset
|
1128 * 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
|
1129 * This means : |
ef1daba63c30
Sync with upstream version. According to Edouard Gomez:
kmkaplan
parents:
7331
diff
changeset
|
1130 * 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
|
1131 * 2 - Leads to artifacts because of 1 |
ef1daba63c30
Sync with upstream version. According to Edouard Gomez:
kmkaplan
parents:
7331
diff
changeset
|
1132 */ |
ef1daba63c30
Sync with upstream version. According to Edouard Gomez:
kmkaplan
parents:
7331
diff
changeset
|
1133 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
|
1134 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1135 /* 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
|
1136 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
|
1137 |
29248 | 1138 /* |
7331
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1139 * 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
|
1140 * getintra/quant calls |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1141 * 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
|
1142 * 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
|
1143 * the overflow and so on... |
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 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1146 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1147 /* Fake vars */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1148 int next_hbytes, next_kblocks, next_mblocks, next_ublocks; |
29248 | 1149 |
7331
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1150 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
|
1151 &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
|
1152 &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
|
1153 &next_ublocks); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1154 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1155 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1156 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1157 /* Initialize the frame counter */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1158 state->cur_frame = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1159 state->last_keyframe = 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 return(0); |
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 } |
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 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
|
1166 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1167 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1168 int quant; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1169 int intra; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1170 int bytes1, bytes2; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1171 int overflow; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1172 int capped_to_max_framesize = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1173 int KFdistance, KF_min_size; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1174 vbr_control_t *state = sstate; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1175 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1176 bytes1 = state->pass1_bytes; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1177 overflow = state->overflow / 8; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1178 /* To shut up gcc warning */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1179 bytes2 = bytes1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1180 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1181 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1182 if (state->pass1_intra) |
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 overflow = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1185 } |
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 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
|
1188 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1189 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1190 switch (state->credits_mode) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1191 case VBR_CREDITS_MODE_QUANT : |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1192 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
|
1193 quant = state->pass1_intra ? |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1194 state->credits_quant_i: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1195 state->credits_quant_p; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1196 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1197 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1198 quant = state->credits_quant_p; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1199 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1200 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1201 state->bytes1 = bytes1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1202 state->bytes2 = bytes1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1203 state->desired_bytes2 = bytes1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1204 return(quant); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1205 default: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1206 case VBR_CREDITS_MODE_RATE : |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1207 case VBR_CREDITS_MODE_SIZE : |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1208 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
|
1209 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
|
1210 else |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1211 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
|
1212 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1213 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1214 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1215 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1216 /* Foxer: apply curve compression outside credits */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1217 double dbytes, curve_temp; |
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 bytes2 = bytes1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1220 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1221 if (state->pass1_intra) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1222 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
|
1223 state->movie_curve; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1224 else |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1225 dbytes = bytes2 / state->movie_curve; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1226 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1227 /* 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
|
1228 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
|
1229 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
|
1230 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1231 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1232 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
|
1233 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
|
1234 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1235 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
|
1236 bytes2 = (int)state->curve_comp_error; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1237 } |
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 state->curve_comp_error -= bytes2; |
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->use_alt_curve) { |
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 (!state->pass1_intra) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1244 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1245 if (dbytes > state->average_frame) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1246 if (dbytes >= state->alt_curve_high) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1247 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
|
1248 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1249 switch(state->alt_curve_type) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1250 case VBR_ALT_CURVE_AGGRESIVE: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1251 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
|
1252 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
|
1253 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1254 default: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1255 case VBR_ALT_CURVE_LINEAR: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1256 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
|
1257 (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
|
1258 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1259 case VBR_ALT_CURVE_SOFT: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1260 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
|
1261 (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
|
1262 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1263 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1264 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1265 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1266 if (dbytes <= state->alt_curve_low) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1267 curve_temp = dbytes; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1268 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1269 switch(state->alt_curve_type) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1270 case VBR_ALT_CURVE_AGGRESIVE: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1271 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
|
1272 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
|
1273 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1274 default: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1275 case VBR_ALT_CURVE_LINEAR: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1276 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
|
1277 (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
|
1278 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1279 case VBR_ALT_CURVE_SOFT: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1280 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
|
1281 (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
|
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 } |
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 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
|
1287 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1288 bytes2 += ((int)curve_temp); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1289 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
|
1290 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1291 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1292 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1293 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
|
1294 bytes2 += ((int)dbytes); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1295 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1296 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1297 else 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
|
1298 !state->pass1_intra) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1299 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1300 if (dbytes > state->average_frame) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1301 curve_temp = state->curve_comp_scale * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1302 ((double)dbytes + (state->average_frame - dbytes) * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1303 state->curve_compression_high / 100.0); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1304 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1305 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1306 curve_temp = state->curve_comp_scale * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1307 ((double)dbytes + (state->average_frame - dbytes) * |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1308 state->curve_compression_low / 100.0); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1309 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1310 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1311 bytes2 += ((int)curve_temp); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1312 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
|
1313 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1314 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1315 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
|
1316 bytes2 += ((int)dbytes); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1317 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1318 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1319 /* 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
|
1320 if (bytes2 > bytes1) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1321 state->curve_comp_error += bytes2 - bytes1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1322 bytes2 = bytes1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1323 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1324 else if (bytes2 < 1) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1325 state->curve_comp_error += --bytes2; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1326 bytes2 = 1; |
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 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1329 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1330 state->desired_bytes2 = bytes2; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1331 |
22316
f3d7a1b58a82
cosmetics: Fix some common typos, appropiate --> appropRiate,
diego
parents:
18869
diff
changeset
|
1332 /* 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
|
1333 intra = state->getintra(state); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1334 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1335 if(intra) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1336 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1337 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
|
1338 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
|
1339 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1340 if (KFdistance < state->kftreshold) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1341 KFdistance = KFdistance - state->min_key_interval; |
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 if (KFdistance >= 0) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1344 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1345 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
|
1346 if (KF_min_size < 1) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1347 KF_min_size = 1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1348 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1349 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
|
1350 (state->kftreshold - state->min_key_interval); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1351 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1352 if (bytes2 < 1) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1353 bytes2 = 1; |
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 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1358 /* |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1359 * 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
|
1360 * too much/little bitrate |
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 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
|
1363 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1364 /* 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
|
1365 if (labs(overflow) > labs(state->overflow)) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1366 overflow = state->overflow; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1367 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1368 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1369 /* 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
|
1370 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
|
1371 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
|
1372 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
|
1373 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1374 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
|
1375 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
|
1376 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1377 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1378 bytes2 += overflow; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1379 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1380 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1381 if(bytes2 > state->max_framesize) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1382 capped_to_max_framesize = 1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1383 bytes2 = state->max_framesize; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1384 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1385 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1386 if(bytes2 < 1) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1387 bytes2 = 1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1388 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1389 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1390 state->bytes1 = bytes1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1391 state->bytes2 = bytes2; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1392 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1393 /* very 'simple' quant<->filesize relationship */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1394 quant = state->pass1_quant * bytes1 / bytes2; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1395 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1396 if(quant < 1) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1397 quant = 1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1398 else if(quant > 31) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1399 quant = 31; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1400 else if(!state->pass1_intra) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1401 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1402 /* 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
|
1403 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
|
1404 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1405 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
|
1406 state->quant_error[quant] -= 1.0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1407 quant++; |
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 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1410 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1411 /* we're done with credits */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1412 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
|
1413 return(quant); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1414 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1415 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1416 if(intra) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1417 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1418 if (quant < state->min_iquant) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1419 quant = state->min_iquant; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1420 if (quant > state->max_iquant) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1421 quant = state->max_iquant; |
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 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1424 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1425 if(quant > state->max_pquant) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1426 quant = state->max_pquant; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1427 if(quant < state->min_pquant) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1428 quant = state->min_pquant; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1429 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1430 /* 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
|
1431 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
|
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 if (quant < state->last_quant - 2) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1435 quant = state->last_quant - 2; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1436 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1437 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1438 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1439 return(quant); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1440 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1441 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1442 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1443 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
|
1444 { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1445 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1446 int intra; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1447 vbr_control_t *state = sstate; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1448 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29248
diff
changeset
|
1449 |
7331
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1450 /* 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
|
1451 intra = state->pass1_intra; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1452 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1453 /* During credits, XviD will decide itself */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1454 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
|
1455 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1456 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1457 switch(state->credits_mode) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1458 default: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1459 case VBR_CREDITS_MODE_RATE : |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1460 case VBR_CREDITS_MODE_SIZE : |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1461 intra = -1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1462 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1463 case VBR_CREDITS_MODE_QUANT : |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1464 /* Except in this case */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1465 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
|
1466 intra = -1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1467 break; |
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 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1471 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1472 /* 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
|
1473 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
|
1474 intra = 1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1475 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1476 /* |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1477 * 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
|
1478 * requested minimum |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1479 */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1480 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
|
1481 intra = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1482 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1483 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1484 /* 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
|
1485 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
|
1486 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1487 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1488 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1489 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
|
1490 int quant, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1491 int intra, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1492 int header_bytes, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1493 int total_bytes, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1494 int kblocks, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1495 int mblocks, |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1496 int ublocks) |
29248 | 1497 |
7331
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 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1501 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1502 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
|
1503 int tempdiv; |
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 vbr_control_t *state = sstate; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1506 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1507 /* |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1508 * 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
|
1509 * from the xvid core |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1510 */ |
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 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
|
1513 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1514 state->quant_count[quant]++; |
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 if (state->pass1_intra) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1517 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1518 state->overflow += state->KFoverflow; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1519 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
|
1520 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1521 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
|
1522 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
|
1523 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1524 /* redistribute correctly (by koepi) */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1525 if (tempdiv > 1) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1526 /* non-consecutive keyframes */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1527 state->KFoverflow_partial = state->KFoverflow / |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1528 (tempdiv - 1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1529 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1530 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1531 state->overflow += state->KFoverflow; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1532 state->KFoverflow = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1533 state->KFoverflow_partial = 0; |
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 state->KF_idx++; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1536 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1537 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1538 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1539 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
|
1540 state->KFoverflow_partial; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1541 state->KFoverflow -= state->KFoverflow_partial; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1542 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1543 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1544 else { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1545 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1546 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
|
1547 state->overflow += state->KFoverflow; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1548 state->KFoverflow = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1549 state->KFoverflow_partial = 0; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1550 } |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1551 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1552 /* Save old quant */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1553 state->last_quant = quant; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1554 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1555 /* Update next frame data */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1556 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
|
1557 &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
|
1558 &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
|
1559 &next_ublocks); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1560 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1561 /* Save the last Keyframe pos */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1562 if(intra) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1563 state->last_keyframe = state->cur_frame; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1564 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1565 /* Ok next frame */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1566 state->cur_frame++; |
29248 | 1567 |
7331
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1568 return(0); |
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 } |
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 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
|
1573 { |
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 vbr_control_t *state = sstate; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1576 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1577 if(state->pass1_file == NULL) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1578 return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1579 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1580 /* Close the file */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1581 if(fclose(state->pass1_file) != 0) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1582 return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1583 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1584 /* Free the memory */ |
32511
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
29263
diff
changeset
|
1585 free(state->keyframe_locations); |
7331
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 return(0); |
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 |
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 * 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
|
1594 *****************************************************************************/ |
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 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
|
1597 { |
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 vbr_control_t *state = sstate; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1600 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1601 if(state->fixed_quant < 1) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1602 state->fixed_quant = 1; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1603 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1604 if(state->fixed_quant > 31) |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1605 state->fixed_quant = 31; |
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 state->cur_frame = 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 return(0); |
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 } |
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 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
|
1614 { |
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 vbr_control_t *state = sstate; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1617 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1618 /* Credits' frame ? */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1619 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
|
1620 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1621 int quant; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1622 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1623 switch(state->credits_mode) { |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1624 case VBR_CREDITS_MODE_RATE: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1625 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
|
1626 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1627 case VBR_CREDITS_MODE_QUANT: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1628 quant = state->credits_fixed_quant; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1629 break; |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1630 default: |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1631 quant = state->fixed_quant; |
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 } |
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 return(quant); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1636 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1637 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29248
diff
changeset
|
1638 |
7331
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1639 /* No credit frame - return fixed quant */ |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1640 return(state->fixed_quant); |
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 } |
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 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
|
1645 { |
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 return(-1); |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1648 |
7ec253a97341
Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff
changeset
|
1649 } |