annotate xvid_vbr.c @ 7984:a57c1fc0c2fc

change qscale type to int8 and fix qscale ordering
author michael
date Wed, 30 Oct 2002 20:50:33 +0000
parents ef1daba63c30
children 8e97c4629611
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7331
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1 /******************************************************************************
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
2 *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
3 * XviD VBR Library
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
4 *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
5 * Copyright (C) 2002 Edouard Gomez <ed.gomez@wanadoo.fr>
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
6 *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
7 * The curve treatment algorithm is based on work done by Foxer <email?> and
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
8 * Dirk Knop <dknop@gwdg.de> for the XviD vfw dynamic library.
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
9 *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
10 * This program is free software; you can redistribute it and/or modify
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
11 * it under the terms of the GNU General Public License as published by
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
12 * the Free Software Foundation; either version 2 of the License, or
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
13 * (at your option) any later version.
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
14 *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
15 * This program is distributed in the hope that it will be useful,
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
18 * GNU General Public License for more details.
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
19 *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
20 * You should have received a copy of the GNU General Public License
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
21 * along with this program; if not, write to the Free Software
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
23 *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
24 *****************************************************************************/
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
25
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
26 /* Standard Headers */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
27 #include <stdio.h>
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
28 #include <string.h>
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
29 #include <fcntl.h>
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
30 #include <stdlib.h>
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
31 #include <math.h>
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
32
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
33 /* Local headers */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
34 #include "xvid_vbr.h"
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
35
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
36 /******************************************************************************
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
37 * Build time constants
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
38 *****************************************************************************/
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
39
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
40 /*
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
41 * Portability note
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
42 * Perhaps the msvc headers define Pi with another constant name
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
43 */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
44 #define DEG2RAD (M_PI / 180.0)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
45
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
46 /* Defaults settings will be computed with the help of these constants */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
47 #define DEFAULT_DESIRED_SIZE 700
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
48 #define DEFAULT_AUDIO_BITRATE 128
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
49 #define DEFAULT_MOVIE_LENGTH 2
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
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
99 static __inline int util_frametype(vbr_control_t *state)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
100 {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
101
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
102 if(state->credits_start) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
103
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
104 if(state->cur_frame >= state->credits_start_begin &&
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
105 state->cur_frame < state->credits_start_end)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
106 return(FRAME_TYPE_STARTING_CREDITS);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
107
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
108 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
109
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
110 if(state->credits_end) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
111
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
112 if(state->cur_frame >= state->credits_end_begin &&
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
113 state->cur_frame < state->credits_end_end)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
114 return(FRAME_TYPE_STARTING_CREDITS);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
115
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
116 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
117
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
118 return(FRAME_TYPE_NORMAL_MOVIE);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
119
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
120
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
121 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
122
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
123 static __inline int util_creditsframes(vbr_control_t *state)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
124 {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
125
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
126 int frames = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
127
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
128 if(state->credits_start)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
129 frames += state->credits_start_end - state->credits_start_begin;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
130 if(state->credits_end)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
131 frames += state->credits_end_end - state->credits_end_begin;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
132
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
133 return(frames);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
134
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
135 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
136
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
137 /******************************************************************************
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
138 * Functions
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
139 *****************************************************************************/
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
140
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
141 /*****************************************************************************
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
142 * Function description :
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
143 *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
144 * This function initialiazes the vbr_control_t with safe defaults for all
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
145 * modes.
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
146 *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
147 * Return Values :
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
148 * = 0
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
149 ****************************************************************************/
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
150
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
151 int vbrSetDefaults(vbr_control_t *state)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
152 {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
153
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
154 /* Set all the structure to zero */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
155 memset(state, 0, sizeof(state));
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
156
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
157 /* Default mode is CBR */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
158 state->mode = VBR_MODE_1PASS;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
159
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
160 /* Default statistic filename */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
161 state->filename = DEFAULT_XVID_STATS_FILE;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
162
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;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
199 state->alt_curve_type = VBR_ALT_CURVE_LINEAR;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
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.
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
230 *
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 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
299
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
300 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
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
389 state->debug_quant_count[idx]++;
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
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
511 /* Initialize safe defaults for 2pass 1 */
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 |"
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
533 " mblocks | ublocks\n\n");
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)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
564
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
565
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);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
589
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
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
604 /* Skip the version line and the empty line */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
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
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
614 /* 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
615 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
616
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
617 /* Overwrite the keyframe field */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
618 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
619 state->nb_keyframes);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
620
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
621 /* Close the file */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
622 if(fclose(state->pass1_file) != 0)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
623 return(-1);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
624
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
625 return(0);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
626
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
627 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
628
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
629 /******************************************************************************
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
630 * 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
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 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
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 FILE *f;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
637 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
638 long long credits1_bytes;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
639 long long credits2_bytes;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
640 long long desired;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
641 long long total_bytes;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
642 long long itotal_bytes;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
643 long long start_curved;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
644 long long end_curved;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
645 double total1;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
646 double total2;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
647
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
648 vbr_control_t *state = sstate;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
649
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
650 /* Check the filename */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
651 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
652 return(-1);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
653
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
654 /* Initialize safe defaults for 2pass 2 */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
655 state->pass1_file = NULL;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
656 state->nb_frames = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
657 state->nb_keyframes = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
658
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
659 /* Open the 1st pass file */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
660 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
661 return(-1);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
662
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
663 state->pass1_file = f;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
664
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
665 /* 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
666 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
667
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
668 if(n != VBR_VERSION) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
669 fclose(state->pass1_file);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
670 state->pass1_file = NULL;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
671 return(-1);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
672 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
673
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
674 /* Skip the blank commented line */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
675 c = n = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
676 do {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
677
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
678 c = fgetc(state->pass1_file);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
679
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
680 if(c == EOF) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
681 fclose(state->pass1_file);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
682 state->pass1_file = NULL;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
683 return(-1);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
684 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
685
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
686 if(c == '\n') n++;
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 }while(n < 1);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
689
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 /* Get the number of frames */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
692 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
693
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
694 /* Compute the desired size */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
695 state->desired_size = (long long)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
696 (((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
697 (state->fps * 8.0));
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
698
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
699 /* Get the number of keyframes */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
700 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
701
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
702 /* Allocate memory space for the keyframe_location array */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
703 if((state->keyframe_locations
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
704 = (int*)malloc((state->nb_keyframes+1)*sizeof(int))) == NULL) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
705 fclose(state->pass1_file);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
706 state->pass1_file = NULL;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
707 return(-1);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
708 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
709
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
710 /* 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
711 c = n = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
712 do {
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 c = fgetc(state->pass1_file);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
715
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
716 if(c == EOF) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
717 fclose(state->pass1_file);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
718 state->pass1_file = NULL;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
719 return(-1);
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
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
722 if(c == '\n') n++;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
723
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
724 }while(n < 2);
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 /* Save position for future use */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
727 pos_firstframe = ftell(state->pass1_file);
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 /* Read and initialize some variables */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
730 credits1_bytes = credits2_bytes = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
731 total_bytes = itotal_bytes = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
732 start_curved = end_curved = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
733 credits_frames = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
734
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
735 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
736
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
737 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
738 int kblocks, mblocks, ublocks;
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 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
741 &quant, &keyframe, &frame_hbytes, &frame_bytes,
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
742 &kblocks, &mblocks, &ublocks);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
743
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
744 /* 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
745 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
746 credits1_bytes += frame_bytes;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
747 credits_frames++;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
748 continue;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
749 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
750
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
751 /* 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
752 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
753 credits2_bytes += frame_bytes;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
754 credits_frames++;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
755 continue;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
756 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
757
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
758 /* 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
759 if(keyframe) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
760 itotal_bytes += frame_bytes + frame_bytes *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
761 state->keyframe_boost / 100;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
762 total_bytes += frame_bytes *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
763 state->keyframe_boost / 100;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
764 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
765 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
766
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
767 total_bytes += frame_bytes;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
768
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
769 }
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 /*
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
772 * 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
773 * all other the last film segment
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 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
776
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
777 /* Compensate AVI overhead */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
778 desired = state->desired_size - state->nb_frames*24;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
779
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
780 switch(state->credits_mode) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
781 case VBR_CREDITS_MODE_QUANT :
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
782
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
783 state->movie_curve = (double)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
784 (total_bytes - credits1_bytes - credits2_bytes) /
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
785 (desired - credits1_bytes - credits2_bytes);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
786
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
787 start_curved = credits1_bytes;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
788 end_curved = credits2_bytes;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
789
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
790 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
791 case VBR_CREDITS_MODE_SIZE:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
792
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
793 /* start curve = (start / start desired size) */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
794 state->credits_start_curve = (double)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
795 (credits1_bytes / state->credits_start_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 /* end curve = (end / end desired size) */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
798 state->credits_end_curve = (double)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
799 (credits2_bytes / state->credits_end_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 start_curved = (long long)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
802 (credits1_bytes / state->credits_start_curve);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
803
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
804 end_curved = (long long)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
805 (credits2_bytes / state->credits_end_curve);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
806
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
807 /* 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
808 state->movie_curve = (double)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
809 (total_bytes - credits1_bytes - credits2_bytes) /
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
810 (desired - start_curved - end_curved);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
811
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
812 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
813 case VBR_CREDITS_MODE_RATE:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
814 default:
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 /* 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
817 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
818 ((double)total_bytes / desired) *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
819 ((double)100 / state->credits_quant_ratio);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
820
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
821 start_curved =
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
822 (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
823
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
824 end_curved =
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
825 (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
826
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
827 state->movie_curve = (double)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
828 (total_bytes - credits1_bytes - credits2_bytes) /
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
829 (desired - start_curved - end_curved);
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 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
832 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
833
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 * 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
836 * (frames - credits frames - keyframes)
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 state->average_frame = (double)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
839 (desired - start_curved - end_curved -
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
840 (itotal_bytes / state->movie_curve)) /
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
841 (state->nb_frames - util_creditsframes(state) -
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
842 state->nb_keyframes);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
843
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
844 /* Initialize alt curve parameters */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
845 if (state->use_alt_curve) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
846
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
847 state->alt_curve_low =
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
848 state->average_frame - state->average_frame *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
849 (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
850
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
851 state->alt_curve_low_diff =
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
852 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
853
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
854 state->alt_curve_high =
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
855 state->average_frame + state->average_frame *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
856 (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
857
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
858 state->alt_curve_high_diff =
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
859 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
860
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
861 if (state->alt_curve_use_auto) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
862
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
863 if (state->movie_curve > 1.0) {
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 state->alt_curve_min_rel_qual =
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
866 (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
867 (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
868
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
869 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
870 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
871 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
872 else {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
873 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
874 }
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 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
877
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
878 state->alt_curve_mid_qual =
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
879 (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
880
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
881 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
882
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
883 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
884
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
885 switch(state->alt_curve_type) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
886 case VBR_ALT_CURVE_AGGRESIVE:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
887 /* Sine Curve (high aggressiveness) */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
888 state->alt_curve_qual_dev *=
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
889 2.0 /
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
890 (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
891
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
892 state->alt_curve_mid_qual =
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
893 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
894 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 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
896
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
897 default:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
898 case VBR_ALT_CURVE_LINEAR:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
899 /* Linear (medium aggressiveness) */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
900 state->alt_curve_qual_dev *=
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
901 2.0 /
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
902 (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
903
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
904 state->alt_curve_mid_qual =
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
905 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
906 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 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
909
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
910 case VBR_ALT_CURVE_SOFT:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
911 /* Cosine Curve (low aggressiveness) */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
912 state->alt_curve_qual_dev *=
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
913 2.0 /
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
914 (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
915
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
916 state->alt_curve_mid_qual =
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
917 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
918 (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 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
921 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
922 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
923 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
924
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
925 /* 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
926 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
927
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
928 /* 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
929 total1 = total2 = 0.0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
930 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
931
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
932 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
933 int kblocks, mblocks, ublocks;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
934
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
935 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
936 &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 &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 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
940 continue;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
941
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
942 if(!keyframe) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
943
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
944 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
945 total1 += dbytes;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
946
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
947 if (state->use_alt_curve) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
948
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
949 if (dbytes > state->average_frame) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
950
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
951 if (dbytes >= state->alt_curve_high) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
952 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
953 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
954 else {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
955
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
956 switch(state->alt_curve_type) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
957 case VBR_ALT_CURVE_AGGRESIVE:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
958
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
959 total2 +=
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
960 dbytes *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
961 (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
962 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
963 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
964 default:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
965 case VBR_ALT_CURVE_LINEAR:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
966
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
967 total2 +=
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
968 dbytes *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
969 (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
970 (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
971 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
972 case VBR_ALT_CURVE_SOFT:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
973 total2 +=
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
974 dbytes *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
975 (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
976 (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
977 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
978 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
979 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
980 else {
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 if (dbytes <= state->alt_curve_low) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
983 total2 += dbytes;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
984 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
985 else {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
986
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
987 switch(state->alt_curve_type) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
988 case VBR_ALT_CURVE_AGGRESIVE:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
989 total2 +=
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
990 dbytes *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
991 (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
992 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
993 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
994 default:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
995 case VBR_ALT_CURVE_LINEAR:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
996 total2 +=
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
997 dbytes *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
998 (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
999 (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
1000 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1001 case VBR_ALT_CURVE_SOFT:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1002 total2 +=
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1003 dbytes *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1004 (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
1005 (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
1006 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1007 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1008 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1009 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1010 else {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1011 if (dbytes > state->average_frame) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1012 total2 +=
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1013 ((double)dbytes +
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1014 (state->average_frame - dbytes) *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1015 state->curve_compression_high / 100.0);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1016 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1017 else {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1018 total2 +=
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1019 ((double)dbytes +
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1020 (state->average_frame - dbytes) *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1021 state->curve_compression_low / 100.0);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1022 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1023 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1024 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1025 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1026
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1027 state->curve_comp_scale = total1 / total2;
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 if (state->use_alt_curve) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1030
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1031 double curve_temp, dbytes;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1032 int newquant, percent;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1033 int oldquant = 1;
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 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
1036 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
1037
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1038 state->curve_bias_bonus =
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1039 (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
1040 (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
1041 state->curve_comp_scale =
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1042 ((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
1043 total2;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1044
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1045
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1046 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
1047 dbytes = n;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1048 if (dbytes > state->average_frame)
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 if (dbytes >= state->alt_curve_high) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1051 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
1052 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1053 else {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1054 switch(state->alt_curve_type) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1055 case VBR_ALT_CURVE_AGGRESIVE:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1056 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
1057 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
1058 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1059 default:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1060 case VBR_ALT_CURVE_LINEAR:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1061 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
1062 (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
1063 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1064 case VBR_ALT_CURVE_SOFT:
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 (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
1067 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1068 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1069 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1070 else {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1071 if (dbytes <= state->alt_curve_low) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1072 curve_temp = dbytes;
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 switch(state->alt_curve_type) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1076 case VBR_ALT_CURVE_AGGRESIVE:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1077 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
1078 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
1079 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1080 default:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1081 case VBR_ALT_CURVE_LINEAR:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1082 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
1083 (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
1084 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1085 case VBR_ALT_CURVE_SOFT:
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 (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
1088 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1089 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1090 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1091
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1092 if (state->movie_curve > 1.0)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1093 dbytes *= state->movie_curve;
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 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
1096 if (newquant > 1)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1097 {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1098 if (newquant != oldquant)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1099 {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1100 oldquant = newquant;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1101 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
1102 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1103
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1104 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1105
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1106 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1107
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1108 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1109
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1110 state->overflow = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1111 state->KFoverflow = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1112 state->KFoverflow_partial = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1113 state->KF_idx = 1;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1114
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1115 for (n=0 ; n < 32 ; n++) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1116 state->quant_error[n] = 0.0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1117 state->quant_count[n] = 0;
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
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1120 state->curve_comp_error = 0.0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1121 state->last_quant = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1122
7436
ef1daba63c30 Sync with upstream version. According to Edouard Gomez:
kmkaplan
parents: 7331
diff changeset
1123 /*
ef1daba63c30 Sync with upstream version. According to Edouard Gomez:
kmkaplan
parents: 7331
diff changeset
1124 * 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
1125 * This means :
ef1daba63c30 Sync with upstream version. According to Edouard Gomez:
kmkaplan
parents: 7331
diff changeset
1126 * 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
1127 * 2 - Leads to artifacts because of 1
ef1daba63c30 Sync with upstream version. According to Edouard Gomez:
kmkaplan
parents: 7331
diff changeset
1128 */
ef1daba63c30 Sync with upstream version. According to Edouard Gomez:
kmkaplan
parents: 7331
diff changeset
1129 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
1130
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1131 /* 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
1132 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
1133
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 * 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
1136 * getintra/quant calls
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1137 * 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
1138 * 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
1139 * the overflow and so on...
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1140 */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1141 {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1142
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1143 /* Fake vars */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1144 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
1145
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1146 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
1147 &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
1148 &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
1149 &next_ublocks);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1150
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1151 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1152
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1153 /* Initialize the frame counter */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1154 state->cur_frame = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1155 state->last_keyframe = 0;
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 return(0);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1158
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1159 }
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 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
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 int quant;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1165 int intra;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1166 int bytes1, bytes2;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1167 int overflow;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1168 int capped_to_max_framesize = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1169 int KFdistance, KF_min_size;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1170 vbr_control_t *state = sstate;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1171
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1172 bytes1 = state->pass1_bytes;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1173 overflow = state->overflow / 8;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1174 /* To shut up gcc warning */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1175 bytes2 = bytes1;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1176
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1177
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1178 if (state->pass1_intra)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1179 {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1180 overflow = 0;
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
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1183 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
1184
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 switch (state->credits_mode) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1187 case VBR_CREDITS_MODE_QUANT :
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1188 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
1189 quant = state->pass1_intra ?
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1190 state->credits_quant_i:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1191 state->credits_quant_p;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1192 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1193 else {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1194 quant = state->credits_quant_p;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1195 }
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 state->bytes1 = bytes1;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1198 state->bytes2 = bytes1;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1199 state->desired_bytes2 = bytes1;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1200 return(quant);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1201 default:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1202 case VBR_CREDITS_MODE_RATE :
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1203 case VBR_CREDITS_MODE_SIZE :
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1204 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
1205 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
1206 else
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1207 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
1208 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1209 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1210 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1211 else {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1212 /* Foxer: apply curve compression outside credits */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1213 double dbytes, curve_temp;
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 bytes2 = bytes1;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1216
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1217 if (state->pass1_intra)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1218 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
1219 state->movie_curve;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1220 else
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1221 dbytes = bytes2 / state->movie_curve;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1222
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1223 /* 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
1224 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
1225 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
1226 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1227 else {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1228 bytes2 = (int)(state->curve_comp_error * dbytes /
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1229 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
1230
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1231 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
1232 bytes2 = (int)state->curve_comp_error;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1233 }
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 state->curve_comp_error -= bytes2;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1236
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1237 if (state->use_alt_curve) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1238
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1239 if (!state->pass1_intra) {
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 (dbytes > state->average_frame) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1242 if (dbytes >= state->alt_curve_high)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1243 curve_temp = dbytes * (state->alt_curve_mid_qual - state->alt_curve_qual_dev);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1244 else {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1245 switch(state->alt_curve_type) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1246 case VBR_ALT_CURVE_AGGRESIVE:
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 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
1249 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1250 default:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1251 case VBR_ALT_CURVE_LINEAR:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1252 curve_temp = dbytes * (state->alt_curve_mid_qual - state->alt_curve_qual_dev *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1253 (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
1254 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1255 case VBR_ALT_CURVE_SOFT:
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 (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
1258 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1259 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1260 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1261 else {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1262 if (dbytes <= state->alt_curve_low)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1263 curve_temp = dbytes;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1264 else {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1265 switch(state->alt_curve_type) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1266 case VBR_ALT_CURVE_AGGRESIVE:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1267 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
1268 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
1269 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1270 default:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1271 case VBR_ALT_CURVE_LINEAR:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1272 curve_temp = dbytes * (state->alt_curve_mid_qual - state->alt_curve_qual_dev *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1273 (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
1274 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1275 case VBR_ALT_CURVE_SOFT:
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 (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
1278 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1279 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1280 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1281
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1282 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
1283
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1284 bytes2 += ((int)curve_temp);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1285 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
1286
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 else {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1289 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
1290 bytes2 += ((int)dbytes);
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 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1293 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
1294 !state->pass1_intra) {
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 if (dbytes > state->average_frame) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1297 curve_temp = state->curve_comp_scale *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1298 ((double)dbytes + (state->average_frame - dbytes) *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1299 state->curve_compression_high / 100.0);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1300 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1301 else {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1302 curve_temp = state->curve_comp_scale *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1303 ((double)dbytes + (state->average_frame - dbytes) *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1304 state->curve_compression_low / 100.0);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1305 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1306
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1307 bytes2 += ((int)curve_temp);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1308 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
1309 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1310 else {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1311 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
1312 bytes2 += ((int)dbytes);
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
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1315 /* 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
1316 if (bytes2 > bytes1) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1317 state->curve_comp_error += bytes2 - bytes1;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1318 bytes2 = bytes1;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1319 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1320 else if (bytes2 < 1) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1321 state->curve_comp_error += --bytes2;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1322 bytes2 = 1;
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 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1325
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1326 state->desired_bytes2 = bytes2;
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 /* Ugly dependance between getquant and getintra */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1329 intra = state->getintra(state);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1330
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1331 if(intra) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1332
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1333 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
1334 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
1335
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1336 if (KFdistance < state->kftreshold) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1337 KFdistance = KFdistance - state->min_key_interval;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1338
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1339 if (KFdistance >= 0) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1340
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1341 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
1342 if (KF_min_size < 1)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1343 KF_min_size = 1;
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 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
1346 (state->kftreshold - state->min_key_interval);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1347
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1348 if (bytes2 < 1)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1349 bytes2 = 1;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1350 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1351 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1352 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1353
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1354 /*
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1355 * 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
1356 * too much/little bitrate
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 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
1359
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1360 /* 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
1361 if (labs(overflow) > labs(state->overflow)) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1362 overflow = state->overflow;
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
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1365 /* 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
1366 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
1367 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
1368 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
1369 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1370 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
1371 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
1372 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1373 else {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1374 bytes2 += overflow;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1375 }
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 if(bytes2 > state->max_framesize) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1378 capped_to_max_framesize = 1;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1379 bytes2 = state->max_framesize;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1380 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1381
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1382 if(bytes2 < 1) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1383 bytes2 = 1;
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 state->bytes1 = bytes1;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1387 state->bytes2 = bytes2;
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 /* very 'simple' quant<->filesize relationship */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1390 quant = state->pass1_quant * bytes1 / bytes2;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1391
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1392 if(quant < 1)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1393 quant = 1;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1394 else if(quant > 31)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1395 quant = 31;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1396 else if(!state->pass1_intra) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1397
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1398 /* 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
1399 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
1400
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1401 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
1402 state->quant_error[quant] -= 1.0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1403 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 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1406
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1407 /* we're done with credits */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1408 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
1409 return(quant);
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
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1412 if(intra) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1413
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1414 if (quant < state->min_iquant)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1415 quant = state->min_iquant;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1416 if (quant > state->max_iquant)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1417 quant = state->max_iquant;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1418 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1419 else {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1420
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1421 if(quant > state->max_pquant)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1422 quant = state->max_pquant;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1423 if(quant < state->min_pquant)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1424 quant = state->min_pquant;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1425
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1426 /* 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
1427 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
1428 if (quant > state->last_quant + 2)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1429 quant = state->last_quant + 2;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1430 if (quant < state->last_quant - 2)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1431 quant = state->last_quant - 2;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1432 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1433 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1434
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1435 return(quant);
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 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
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 int intra;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1443 vbr_control_t *state = 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 /* 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
1447 intra = state->pass1_intra;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1448
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1449 /* During credits, XviD will decide itself */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1450 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
1451
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 switch(state->credits_mode) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1454 default:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1455 case VBR_CREDITS_MODE_RATE :
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1456 case VBR_CREDITS_MODE_SIZE :
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1457 intra = -1;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1458 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1459 case VBR_CREDITS_MODE_QUANT :
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1460 /* Except in this case */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1461 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
1462 intra = -1;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1463 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1464 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1465
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1466 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1467
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1468 /* 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
1469 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
1470 intra = 1;
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 /*
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1473 * 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
1474 * requested minimum
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 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
1477 intra = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1478
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1479
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1480 /* 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
1481 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
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
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1485 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
1486 int quant,
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1487 int intra,
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1488 int header_bytes,
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1489 int total_bytes,
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1490 int kblocks,
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1491 int mblocks,
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1492 int ublocks)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1493
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1494
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1495 {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1496
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1497
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1498 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
1499 int tempdiv;
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 vbr_control_t *state = sstate;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1502
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1503 /*
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1504 * 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
1505 * from the xvid core
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 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
1509
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1510 state->quant_count[quant]++;
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 (state->pass1_intra) {
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->overflow += state->KFoverflow;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1515 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
1516
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1517 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
1518 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
1519
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1520 /* redistribute correctly (by koepi) */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1521 if (tempdiv > 1) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1522 /* non-consecutive keyframes */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1523 state->KFoverflow_partial = state->KFoverflow /
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1524 (tempdiv - 1);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1525 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1526 else {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1527 state->overflow += state->KFoverflow;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1528 state->KFoverflow = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1529 state->KFoverflow_partial = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1530 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1531 state->KF_idx++;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1532
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1533 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1534 else {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1535 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
1536 state->KFoverflow_partial;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1537 state->KFoverflow -= state->KFoverflow_partial;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1538 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1539 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1540 else {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1541
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1542 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
1543 state->overflow += state->KFoverflow;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1544 state->KFoverflow = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1545 state->KFoverflow_partial = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1546 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1547
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1548 /* Save old quant */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1549 state->last_quant = quant;
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 /* Update next frame data */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1552 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
1553 &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
1554 &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
1555 &next_ublocks);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1556
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1557 /* Save the last Keyframe pos */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1558 if(intra)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1559 state->last_keyframe = state->cur_frame;
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 /* Ok next frame */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1562 state->cur_frame++;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1563
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1564 return(0);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1565
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1566 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1567
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1568 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
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 vbr_control_t *state = sstate;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1572
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1573 if(state->pass1_file == NULL)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1574 return(-1);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1575
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1576 /* Close the file */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1577 if(fclose(state->pass1_file) != 0)
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 /* Free the memory */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1581 if(state->keyframe_locations)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1582 free(state->keyframe_locations);
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 return(0);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1585
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1586 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1587
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1588
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1589 /******************************************************************************
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1590 * 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
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 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
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 vbr_control_t *state = 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 if(state->fixed_quant < 1)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1599 state->fixed_quant = 1;
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 > 31)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1602 state->fixed_quant = 31;
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 state->cur_frame = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1605
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1606 return(0);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1607
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1608 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1609
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1610 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
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 vbr_control_t *state = 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 /* Credits' frame ? */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1616 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
1617
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1618 int quant;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1619
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1620 switch(state->credits_mode) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1621 case VBR_CREDITS_MODE_RATE:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1622 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
1623 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1624 case VBR_CREDITS_MODE_QUANT:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1625 quant = state->credits_fixed_quant;
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 default:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1628 quant = state->fixed_quant;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1629
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1630 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1631
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1632 return(quant);
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
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1636 /* No credit frame - return fixed quant */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1637 return(state->fixed_quant);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1638
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1639 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1640
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1641 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
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 return(-1);
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 }