annotate xvid_vbr.c @ 8082:d630c877c05c

1) "-ovc divx4" doesn't encode using XViD anymore 2) added options and defaults to "-xvidencopts" following ve_xvid.c modifications
author rguyom
date Sun, 03 Nov 2002 14:49:45 +0000
parents 8e97c4629611
children ce06bf810d5a
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)
8072
8e97c4629611 - When a frame is in the ending credits zone, say so.
rguyom
parents: 7436
diff changeset
114 return(FRAME_TYPE_ENDING_CREDITS);
7331
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
115
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
116 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
117
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
118 return(FRAME_TYPE_NORMAL_MOVIE);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
119
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
120
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
121 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
122
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
8072
8e97c4629611 - When a frame is in the ending credits zone, say so.
rguyom
parents: 7436
diff changeset
604 /* Skip the version line and the empty line */
7331
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
605 c = i = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
606 do {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
607 c = fgetc(state->pass1_file);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
608
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
609 if(c == EOF) return(-1);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
610 if(c == '\n') i++;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
611
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
612 }while(i < 2);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
613
8072
8e97c4629611 - When a frame is in the ending credits zone, say so.
rguyom
parents: 7436
diff changeset
614 /* Prepare to write to the stream */
8e97c4629611 - When a frame is in the ending credits zone, say so.
rguyom
parents: 7436
diff changeset
615 fseek( state->pass1_file, ftell( state->pass1_file ), SEEK_SET );
8e97c4629611 - When a frame is in the ending credits zone, say so.
rguyom
parents: 7436
diff changeset
616
7331
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
617 /* Overwrite the frame field - safe as we have written extra spaces */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
618 fprintf(state->pass1_file, "# frames : %.10d\n", state->nb_frames);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
619
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
620 /* Overwrite the keyframe field */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
621 fprintf(state->pass1_file, "# keyframes : %.10d\n",
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
622 state->nb_keyframes);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
623
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
624 /* Close the file */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
625 if(fclose(state->pass1_file) != 0)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
626 return(-1);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
627
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
628 return(0);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
629
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
630 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
631
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
632 /******************************************************************************
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
633 * 2 pass mode - 2nd pass functions (Need to be finished)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
634 *****************************************************************************/
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
635
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
636 static int vbr_init_2pass2(void *sstate)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
637 {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
638
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
639 FILE *f;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
640 int c, n, pos_firstframe, credits_frames;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
641 long long credits1_bytes;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
642 long long credits2_bytes;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
643 long long desired;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
644 long long total_bytes;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
645 long long itotal_bytes;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
646 long long start_curved;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
647 long long end_curved;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
648 double total1;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
649 double total2;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
650
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
651 vbr_control_t *state = sstate;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
652
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
653 /* Check the filename */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
654 if(state->filename == NULL || state->filename[0] == '\0')
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
655 return(-1);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
656
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
657 /* Initialize safe defaults for 2pass 2 */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
658 state->pass1_file = NULL;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
659 state->nb_frames = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
660 state->nb_keyframes = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
661
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
662 /* Open the 1st pass file */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
663 if((f = fopen(state->filename, "r")) == NULL)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
664 return(-1);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
665
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
666 state->pass1_file = f;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
667
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
668 /* Get the file version and check against current version */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
669 fscanf(state->pass1_file, "# ASCII XviD vbr stat file version %d\n", &n);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
670
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
671 if(n != VBR_VERSION) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
672 fclose(state->pass1_file);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
673 state->pass1_file = NULL;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
674 return(-1);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
675 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
676
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
677 /* Skip the blank commented line */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
678 c = n = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
679 do {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
680
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
681 c = fgetc(state->pass1_file);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
682
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
683 if(c == EOF) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
684 fclose(state->pass1_file);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
685 state->pass1_file = NULL;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
686 return(-1);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
687 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
688
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
689 if(c == '\n') n++;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
690
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
691 }while(n < 1);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
692
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
693
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
694 /* Get the number of frames */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
695 fscanf(state->pass1_file, "# frames : %d\n", &state->nb_frames);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
696
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
697 /* Compute the desired size */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
698 state->desired_size = (long long)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
699 (((long long)state->nb_frames * (long long)state->desired_bitrate) /
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
700 (state->fps * 8.0));
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
701
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
702 /* Get the number of keyframes */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
703 fscanf(state->pass1_file, "# keyframes : %d\n", &state->nb_keyframes);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
704
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
705 /* Allocate memory space for the keyframe_location array */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
706 if((state->keyframe_locations
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
707 = (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
708 fclose(state->pass1_file);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
709 state->pass1_file = NULL;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
710 return(-1);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
711 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
712
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
713 /* Skip the blank commented line and the colum description */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
714 c = n = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
715 do {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
716
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
717 c = fgetc(state->pass1_file);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
718
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
719 if(c == EOF) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
720 fclose(state->pass1_file);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
721 state->pass1_file = NULL;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
722 return(-1);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
723 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
724
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
725 if(c == '\n') n++;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
726
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
727 }while(n < 2);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
728
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
729 /* Save position for future use */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
730 pos_firstframe = ftell(state->pass1_file);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
731
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
732 /* Read and initialize some variables */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
733 credits1_bytes = credits2_bytes = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
734 total_bytes = itotal_bytes = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
735 start_curved = end_curved = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
736 credits_frames = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
737
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
738 for(state->cur_frame = c = 0; state->cur_frame<state->nb_frames; state->cur_frame++) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
739
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
740 int quant, keyframe, frame_hbytes, frame_bytes;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
741 int kblocks, mblocks, ublocks;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
742
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
743 fscanf(state->pass1_file, "%d %d %d %d %d %d %d\n",
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
744 &quant, &keyframe, &frame_hbytes, &frame_bytes,
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
745 &kblocks, &mblocks, &ublocks);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
746
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
747 /* Is the frame in the beginning credits */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
748 if(util_frametype(state) == FRAME_TYPE_STARTING_CREDITS) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
749 credits1_bytes += frame_bytes;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
750 credits_frames++;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
751 continue;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
752 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
753
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
754 /* Is the frame in the eding credits */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
755 if(util_frametype(state) == FRAME_TYPE_ENDING_CREDITS) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
756 credits2_bytes += frame_bytes;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
757 credits_frames++;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
758 continue;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
759 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
760
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
761 /* We only care about Keyframes when not in credits */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
762 if(keyframe) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
763 itotal_bytes += frame_bytes + frame_bytes *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
764 state->keyframe_boost / 100;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
765 total_bytes += frame_bytes *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
766 state->keyframe_boost / 100;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
767 state->keyframe_locations[c++] = state->cur_frame;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
768 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
769
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
770 total_bytes += frame_bytes;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
771
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
772 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
773
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
774 /*
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
775 * Last frame is treated like an I Frame so we can dispatch overflow
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
776 * all other the last film segment
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
777 */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
778 state->keyframe_locations[c] = state->cur_frame;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
779
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
780 /* Compensate AVI overhead */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
781 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
782
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
783 switch(state->credits_mode) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
784 case VBR_CREDITS_MODE_QUANT :
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
785
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
786 state->movie_curve = (double)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
787 (total_bytes - credits1_bytes - credits2_bytes) /
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
788 (desired - credits1_bytes - 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 start_curved = credits1_bytes;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
791 end_curved = credits2_bytes;
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 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
794 case VBR_CREDITS_MODE_SIZE:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
795
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
796 /* start curve = (start / start desired size) */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
797 state->credits_start_curve = (double)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
798 (credits1_bytes / state->credits_start_size);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
799
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
800 /* end curve = (end / end desired size) */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
801 state->credits_end_curve = (double)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
802 (credits2_bytes / state->credits_end_size);
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 start_curved = (long long)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
805 (credits1_bytes / state->credits_start_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 end_curved = (long long)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
808 (credits2_bytes / state->credits_end_curve);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
809
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
810 /* 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
811 state->movie_curve = (double)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
812 (total_bytes - credits1_bytes - credits2_bytes) /
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
813 (desired - start_curved - end_curved);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
814
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
815 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
816 case VBR_CREDITS_MODE_RATE:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
817 default:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
818
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
819 /* 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
820 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
821 ((double)total_bytes / desired) *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
822 ((double)100 / state->credits_quant_ratio);
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 start_curved =
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
825 (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
826
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
827 end_curved =
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
828 (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
829
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
830 state->movie_curve = (double)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
831 (total_bytes - credits1_bytes - credits2_bytes) /
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
832 (desired - start_curved - end_curved);
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 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
835 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
836
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
837 /*
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
838 * 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
839 * (frames - credits frames - keyframes)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
840 */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
841 state->average_frame = (double)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
842 (desired - start_curved - end_curved -
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
843 (itotal_bytes / state->movie_curve)) /
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
844 (state->nb_frames - util_creditsframes(state) -
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
845 state->nb_keyframes);
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 /* Initialize alt curve parameters */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
848 if (state->use_alt_curve) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
849
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
850 state->alt_curve_low =
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
851 state->average_frame - state->average_frame *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
852 (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
853
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
854 state->alt_curve_low_diff =
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
855 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
856
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
857 state->alt_curve_high =
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
858 state->average_frame + state->average_frame *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
859 (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
860
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
861 state->alt_curve_high_diff =
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
862 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
863
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
864 if (state->alt_curve_use_auto) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
865
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
866 if (state->movie_curve > 1.0) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
867
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
868 state->alt_curve_min_rel_qual =
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
869 (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
870 (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
871
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
872 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
873 state->alt_curve_min_rel_qual = 20;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
874 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
875 else {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
876 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
877 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
878
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
879 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
880
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
881 state->alt_curve_mid_qual =
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
882 (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
883
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
884 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
885
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
886 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
887
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
888 switch(state->alt_curve_type) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
889 case VBR_ALT_CURVE_AGGRESIVE:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
890 /* Sine Curve (high aggressiveness) */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
891 state->alt_curve_qual_dev *=
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
892 2.0 /
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
893 (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
894
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
895 state->alt_curve_mid_qual =
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
896 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
897 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
898 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
899
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
900 default:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
901 case VBR_ALT_CURVE_LINEAR:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
902 /* Linear (medium aggressiveness) */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
903 state->alt_curve_qual_dev *=
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
904 2.0 /
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
905 (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
906
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
907 state->alt_curve_mid_qual =
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
908 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
909 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
910
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
911 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
912
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
913 case VBR_ALT_CURVE_SOFT:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
914 /* Cosine Curve (low aggressiveness) */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
915 state->alt_curve_qual_dev *=
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
916 2.0 /
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
917 (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
918
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
919 state->alt_curve_mid_qual =
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
920 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
921 (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
922
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
923 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
924 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
925 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
926 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
927
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
928 /* 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
929 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
930
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
931 /* 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
932 total1 = total2 = 0.0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
933 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
934
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
935 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
936 int kblocks, mblocks, ublocks;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
937
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
938 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
939 &quant, &keyframe, &frame_hbytes, &frame_bytes,
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
940 &kblocks, &mblocks, &ublocks);
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(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
943 continue;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
944
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
945 if(!keyframe) {
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 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
948 total1 += dbytes;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
949
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
950 if (state->use_alt_curve) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
951
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
952 if (dbytes > state->average_frame) {
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 if (dbytes >= state->alt_curve_high) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
955 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
956 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
957 else {
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 switch(state->alt_curve_type) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
960 case VBR_ALT_CURVE_AGGRESIVE:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
961
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
962 total2 +=
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
963 dbytes *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
964 (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
965 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
966 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
967 default:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
968 case VBR_ALT_CURVE_LINEAR:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
969
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
970 total2 +=
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
971 dbytes *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
972 (state->alt_curve_mid_qual - state->alt_curve_qual_dev *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
973 (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
974 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
975 case VBR_ALT_CURVE_SOFT:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
976 total2 +=
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
977 dbytes *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
978 (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
979 (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
980 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
981 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
982 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
983 else {
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 if (dbytes <= state->alt_curve_low) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
986 total2 += dbytes;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
987 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
988 else {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
989
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
990 switch(state->alt_curve_type) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
991 case VBR_ALT_CURVE_AGGRESIVE:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
992 total2 +=
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
993 dbytes *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
994 (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
995 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
996 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
997 default:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
998 case VBR_ALT_CURVE_LINEAR:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
999 total2 +=
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1000 dbytes *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1001 (state->alt_curve_mid_qual - state->alt_curve_qual_dev *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1002 (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
1003 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1004 case VBR_ALT_CURVE_SOFT:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1005 total2 +=
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1006 dbytes *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1007 (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
1008 (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
1009 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1010 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1011 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1012 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1013 else {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1014 if (dbytes > state->average_frame) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1015 total2 +=
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1016 ((double)dbytes +
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1017 (state->average_frame - dbytes) *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1018 state->curve_compression_high / 100.0);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1019 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1020 else {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1021 total2 +=
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1022 ((double)dbytes +
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1023 (state->average_frame - dbytes) *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1024 state->curve_compression_low / 100.0);
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 }
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
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1030 state->curve_comp_scale = total1 / total2;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1031
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1032 if (state->use_alt_curve) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1033
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1034 double curve_temp, dbytes;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1035 int newquant, percent;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1036 int oldquant = 1;
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 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
1039 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
1040
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1041 state->curve_bias_bonus =
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1042 (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
1043 (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
1044 state->curve_comp_scale =
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1045 ((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
1046 total2;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1047
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1048
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1049 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
1050 dbytes = n;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1051 if (dbytes > state->average_frame)
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 if (dbytes >= state->alt_curve_high) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1054 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
1055 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1056 else {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1057 switch(state->alt_curve_type) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1058 case VBR_ALT_CURVE_AGGRESIVE:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1059 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
1060 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
1061 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1062 default:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1063 case VBR_ALT_CURVE_LINEAR:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1064 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
1065 (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
1066 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1067 case VBR_ALT_CURVE_SOFT:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1068 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
1069 (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
1070 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1071 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1072 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1073 else {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1074 if (dbytes <= state->alt_curve_low) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1075 curve_temp = dbytes;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1076 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1077 else {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1078 switch(state->alt_curve_type) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1079 case VBR_ALT_CURVE_AGGRESIVE:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1080 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
1081 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
1082 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1083 default:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1084 case VBR_ALT_CURVE_LINEAR:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1085 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
1086 (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
1087 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1088 case VBR_ALT_CURVE_SOFT:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1089 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
1090 (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
1091 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1092 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1093 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1094
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1095 if (state->movie_curve > 1.0)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1096 dbytes *= state->movie_curve;
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 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
1099 if (newquant > 1)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1100 {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1101 if (newquant != oldquant)
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 oldquant = newquant;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1104 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
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
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1111 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1112
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1113 state->overflow = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1114 state->KFoverflow = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1115 state->KFoverflow_partial = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1116 state->KF_idx = 1;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1117
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1118 for (n=0 ; n < 32 ; n++) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1119 state->quant_error[n] = 0.0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1120 state->quant_count[n] = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1121 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1122
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1123 state->curve_comp_error = 0.0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1124 state->last_quant = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1125
7436
ef1daba63c30 Sync with upstream version. According to Edouard Gomez:
kmkaplan
parents: 7331
diff changeset
1126 /*
ef1daba63c30 Sync with upstream version. According to Edouard Gomez:
kmkaplan
parents: 7331
diff changeset
1127 * 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
1128 * This means :
ef1daba63c30 Sync with upstream version. According to Edouard Gomez:
kmkaplan
parents: 7331
diff changeset
1129 * 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
1130 * 2 - Leads to artifacts because of 1
ef1daba63c30 Sync with upstream version. According to Edouard Gomez:
kmkaplan
parents: 7331
diff changeset
1131 */
ef1daba63c30 Sync with upstream version. According to Edouard Gomez:
kmkaplan
parents: 7331
diff changeset
1132 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
1133
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1134 /* 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
1135 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
1136
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1137 /*
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1138 * 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
1139 * getintra/quant calls
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1140 * 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
1141 * 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
1142 * the overflow and so on...
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1143 */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1144 {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1145
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1146 /* Fake vars */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1147 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
1148
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1149 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
1150 &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
1151 &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
1152 &next_ublocks);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1153
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1154 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1155
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1156 /* Initialize the frame counter */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1157 state->cur_frame = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1158 state->last_keyframe = 0;
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 return(0);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1161
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1162 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1163
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1164 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
1165 {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1166
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1167 int quant;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1168 int intra;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1169 int bytes1, bytes2;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1170 int overflow;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1171 int capped_to_max_framesize = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1172 int KFdistance, KF_min_size;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1173 vbr_control_t *state = sstate;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1174
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1175 bytes1 = state->pass1_bytes;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1176 overflow = state->overflow / 8;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1177 /* To shut up gcc warning */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1178 bytes2 = bytes1;
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
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1181 if (state->pass1_intra)
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 overflow = 0;
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 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
1187
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1188
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1189 switch (state->credits_mode) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1190 case VBR_CREDITS_MODE_QUANT :
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1191 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
1192 quant = state->pass1_intra ?
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1193 state->credits_quant_i:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1194 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 else {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1197 quant = state->credits_quant_p;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1198 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1199
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1200 state->bytes1 = bytes1;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1201 state->bytes2 = bytes1;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1202 state->desired_bytes2 = bytes1;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1203 return(quant);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1204 default:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1205 case VBR_CREDITS_MODE_RATE :
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1206 case VBR_CREDITS_MODE_SIZE :
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1207 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
1208 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
1209 else
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1210 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
1211 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1212 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1213 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1214 else {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1215 /* Foxer: apply curve compression outside credits */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1216 double dbytes, curve_temp;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1217
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1218 bytes2 = bytes1;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1219
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1220 if (state->pass1_intra)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1221 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
1222 state->movie_curve;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1223 else
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1224 dbytes = bytes2 / state->movie_curve;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1225
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1226 /* 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
1227 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
1228 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
1229 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1230 else {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1231 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
1232 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
1233
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1234 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
1235 bytes2 = (int)state->curve_comp_error;
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
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1238 state->curve_comp_error -= bytes2;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1239
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1240 if (state->use_alt_curve) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1241
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1242 if (!state->pass1_intra) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1243
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1244 if (dbytes > state->average_frame) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1245 if (dbytes >= state->alt_curve_high)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1246 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
1247 else {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1248 switch(state->alt_curve_type) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1249 case VBR_ALT_CURVE_AGGRESIVE:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1250 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
1251 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
1252 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1253 default:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1254 case VBR_ALT_CURVE_LINEAR:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1255 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
1256 (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
1257 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1258 case VBR_ALT_CURVE_SOFT:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1259 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
1260 (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
1261 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1262 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1263 }
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 if (dbytes <= state->alt_curve_low)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1266 curve_temp = dbytes;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1267 else {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1268 switch(state->alt_curve_type) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1269 case VBR_ALT_CURVE_AGGRESIVE:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1270 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
1271 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
1272 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1273 default:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1274 case VBR_ALT_CURVE_LINEAR:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1275 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
1276 (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
1277 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1278 case VBR_ALT_CURVE_SOFT:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1279 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
1280 (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
1281 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1282 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1283 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1284
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1285 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
1286
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1287 bytes2 += ((int)curve_temp);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1288 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
1289
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1290 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1291 else {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1292 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
1293 bytes2 += ((int)dbytes);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1294 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1295 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1296 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
1297 !state->pass1_intra) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1298
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1299 if (dbytes > state->average_frame) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1300 curve_temp = state->curve_comp_scale *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1301 ((double)dbytes + (state->average_frame - dbytes) *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1302 state->curve_compression_high / 100.0);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1303 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1304 else {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1305 curve_temp = state->curve_comp_scale *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1306 ((double)dbytes + (state->average_frame - dbytes) *
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1307 state->curve_compression_low / 100.0);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1308 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1309
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1310 bytes2 += ((int)curve_temp);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1311 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
1312 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1313 else {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1314 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
1315 bytes2 += ((int)dbytes);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1316 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1317
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1318 /* 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
1319 if (bytes2 > bytes1) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1320 state->curve_comp_error += bytes2 - bytes1;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1321 bytes2 = bytes1;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1322 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1323 else if (bytes2 < 1) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1324 state->curve_comp_error += --bytes2;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1325 bytes2 = 1;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1326 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1327 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1328
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1329 state->desired_bytes2 = bytes2;
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 /* Ugly dependance between getquant and getintra */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1332 intra = state->getintra(state);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1333
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1334 if(intra) {
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 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
1337 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
1338
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1339 if (KFdistance < state->kftreshold) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1340 KFdistance = KFdistance - state->min_key_interval;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1341
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1342 if (KFdistance >= 0) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1343
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1344 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
1345 if (KF_min_size < 1)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1346 KF_min_size = 1;
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 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
1349 (state->kftreshold - state->min_key_interval);
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 if (bytes2 < 1)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1352 bytes2 = 1;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1353 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1354 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1355 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1356
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1357 /*
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1358 * 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
1359 * too much/little bitrate
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1360 */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1361 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
1362
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1363 /* 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
1364 if (labs(overflow) > labs(state->overflow)) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1365 overflow = state->overflow;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1366 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1367
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1368 /* 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
1369 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
1370 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
1371 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
1372 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1373 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
1374 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
1375 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1376 else {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1377 bytes2 += overflow;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1378 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1379
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1380 if(bytes2 > state->max_framesize) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1381 capped_to_max_framesize = 1;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1382 bytes2 = state->max_framesize;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1383 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1384
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1385 if(bytes2 < 1) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1386 bytes2 = 1;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1387 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1388
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1389 state->bytes1 = bytes1;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1390 state->bytes2 = 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 /* very 'simple' quant<->filesize relationship */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1393 quant = state->pass1_quant * bytes1 / bytes2;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1394
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1395 if(quant < 1)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1396 quant = 1;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1397 else if(quant > 31)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1398 quant = 31;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1399 else if(!state->pass1_intra) {
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 /* 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
1402 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
1403
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1404 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
1405 state->quant_error[quant] -= 1.0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1406 quant++;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1407 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1408 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1409
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1410 /* we're done with credits */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1411 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
1412 return(quant);
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
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1415 if(intra) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1416
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1417 if (quant < state->min_iquant)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1418 quant = state->min_iquant;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1419 if (quant > state->max_iquant)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1420 quant = state->max_iquant;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1421 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1422 else {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1423
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1424 if(quant > state->max_pquant)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1425 quant = state->max_pquant;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1426 if(quant < state->min_pquant)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1427 quant = state->min_pquant;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1428
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1429 /* 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
1430 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
1431 if (quant > state->last_quant + 2)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1432 quant = state->last_quant + 2;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1433 if (quant < state->last_quant - 2)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1434 quant = state->last_quant - 2;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1435 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1436 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1437
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1438 return(quant);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1439
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1440 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1441
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1442 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
1443 {
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 int intra;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1446 vbr_control_t *state = sstate;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1447
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1448
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1449 /* 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
1450 intra = state->pass1_intra;
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 /* During credits, XviD will decide itself */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1453 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
1454
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1455
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1456 switch(state->credits_mode) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1457 default:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1458 case VBR_CREDITS_MODE_RATE :
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1459 case VBR_CREDITS_MODE_SIZE :
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1460 intra = -1;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1461 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1462 case VBR_CREDITS_MODE_QUANT :
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1463 /* Except in this case */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1464 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
1465 intra = -1;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1466 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1467 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1468
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1469 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1470
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1471 /* 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
1472 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
1473 intra = 1;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1474
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1475 /*
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1476 * 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
1477 * requested minimum
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 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
1480 intra = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1481
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1482
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1483 /* 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
1484 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
1485
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1486 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1487
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1488 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
1489 int quant,
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1490 int intra,
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1491 int header_bytes,
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1492 int total_bytes,
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1493 int kblocks,
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1494 int mblocks,
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1495 int ublocks)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1496
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1497
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1498 {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1499
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1500
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1501 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
1502 int tempdiv;
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 vbr_control_t *state = sstate;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1505
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1506 /*
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1507 * 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
1508 * from the xvid core
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
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1511 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
1512
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1513 state->quant_count[quant]++;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1514
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1515 if (state->pass1_intra) {
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 state->overflow += state->KFoverflow;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1518 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
1519
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1520 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
1521 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
1522
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1523 /* redistribute correctly (by koepi) */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1524 if (tempdiv > 1) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1525 /* non-consecutive keyframes */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1526 state->KFoverflow_partial = state->KFoverflow /
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1527 (tempdiv - 1);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1528 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1529 else {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1530 state->overflow += state->KFoverflow;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1531 state->KFoverflow = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1532 state->KFoverflow_partial = 0;
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 state->KF_idx++;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1535
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1536 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1537 else {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1538 state->overflow += state->desired_bytes2 - total_bytes +
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1539 state->KFoverflow_partial;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1540 state->KFoverflow -= state->KFoverflow_partial;
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 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1543 else {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1544
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1545 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
1546 state->overflow += state->KFoverflow;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1547 state->KFoverflow = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1548 state->KFoverflow_partial = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1549 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1550
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1551 /* Save old quant */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1552 state->last_quant = quant;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1553
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1554 /* Update next frame data */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1555 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
1556 &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
1557 &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
1558 &next_ublocks);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1559
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1560 /* Save the last Keyframe pos */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1561 if(intra)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1562 state->last_keyframe = 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 /* Ok next frame */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1565 state->cur_frame++;
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 return(0);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1568
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1569 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1570
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1571 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
1572 {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1573
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1574 vbr_control_t *state = sstate;
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 if(state->pass1_file == NULL)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1577 return(-1);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1578
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1579 /* Close the file */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1580 if(fclose(state->pass1_file) != 0)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1581 return(-1);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1582
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1583 /* Free the memory */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1584 if(state->keyframe_locations)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1585 free(state->keyframe_locations);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1586
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1587 return(0);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1588
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1589 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1590
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1591
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1592 /******************************************************************************
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1593 * Fixed quant mode - Most of the functions will be dummy functions
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1594 *****************************************************************************/
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1595
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1596 static int vbr_init_fixedquant(void *sstate)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1597 {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1598
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1599 vbr_control_t *state = sstate;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1600
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1601 if(state->fixed_quant < 1)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1602 state->fixed_quant = 1;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1603
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1604 if(state->fixed_quant > 31)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1605 state->fixed_quant = 31;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1606
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1607 state->cur_frame = 0;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1608
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1609 return(0);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1610
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1611 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1612
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1613 static int vbr_getquant_fixedquant(void *sstate)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1614 {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1615
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1616 vbr_control_t *state = sstate;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1617
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1618 /* Credits' frame ? */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1619 if(util_frametype(state) != FRAME_TYPE_NORMAL_MOVIE) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1620
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1621 int quant;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1622
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1623 switch(state->credits_mode) {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1624 case VBR_CREDITS_MODE_RATE:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1625 quant = state->fixed_quant * state->credits_quant_ratio;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1626 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1627 case VBR_CREDITS_MODE_QUANT:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1628 quant = state->credits_fixed_quant;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1629 break;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1630 default:
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1631 quant = state->fixed_quant;
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1632
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1633 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1634
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1635 return(quant);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1636
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1637 }
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 /* No credit frame - return fixed quant */
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1640 return(state->fixed_quant);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1641
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1642 }
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1643
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1644 static int vbr_getintra_fixedquant(void *state)
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1645 {
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1646
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1647 return(-1);
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1648
7ec253a97341 Import transcode-0.6.1.20020829 XviD VBR Library into mencoder DivX4 encoder
kmkaplan
parents:
diff changeset
1649 }