annotate libmpcodecs/ve_divx4.c @ 7533:abc3b12165b7

another dga v1 fix by Fredrik Noring <noring@nocrew.org>
author arpi
date Sat, 28 Sep 2002 18:50:45 +0000
parents a894e99c1e51
children 136e7e515764
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7332
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
1 #define HAVE_XVID_VBR
5550
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
2 #include <stdio.h>
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
3 #include <stdlib.h>
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
4 #include <string.h>
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
5
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
6 #include "../config.h"
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
7 #include "../mp_msg.h"
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
8
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
9 #ifdef HAVE_DIVX4ENCORE
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
10
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
11 #include "codec-cfg.h"
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
12 #include "stream.h"
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
13 #include "demuxer.h"
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
14 #include "stheader.h"
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
15
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
16 #include "aviwrite.h"
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
17
5607
1972c3475d93 mp_image.h and img_format.h moved to libmpcodecs
arpi
parents: 5551
diff changeset
18 #include "img_format.h"
1972c3475d93 mp_image.h and img_format.h moved to libmpcodecs
arpi
parents: 5551
diff changeset
19 #include "mp_image.h"
5550
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
20 #include "vf.h"
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
21
7332
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
22 /* About XviD VBR Library, Edouard Gomez (GomGom) said:
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
23 <GomGom> header bytes == frame header bytes :-)
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
24 <GomGom> total bytes = frame bytes == texture + header
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
25 <GomGom> quant = quant returned by xvidcore
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
26 <GomGom> it's possible that xvid lowers or increases the passed quant because of lumimasking
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
27 <GomGom> kblks = blocks coded as intra blocks
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
28 <GomGom> mblks = blocks coded as predicted blocks
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
29 <GomGom> ublks = skipped blocks
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
30 <GomGom> at the moemnt le vbr lib uses total bytes, and quant
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
31 <GomGom> so it's easy to use it with divx5 (wo bframes)
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
32 <klOUg> bframes breaks what assumptions?
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
33 <GomGom> quant estimation for next frame
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
34 <GomGom> because of the bframe quant multiplier given to divx5
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
35 <GomGom> that the vbr lib does not "know"
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
36 */
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
37
5550
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
38 //===========================================================================//
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
39
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
40 #include "divx4_vbr.h"
7332
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
41 #ifdef HAVE_XVID_VBR
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
42 #include "xvid_vbr.h"
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
43 #endif
5550
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
44
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
45 extern int pass;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
46 extern char* passtmpfile;
7127
1e47c2e7aa8e mostly compiler warning fixes, some small bugfix
arpi
parents: 5854
diff changeset
47 extern void mencoder_write_chunk(aviwrite_stream_t *s,int len,unsigned int flags);
5550
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
48
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
49 #include <encore2.h>
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
50
5854
3a961eaf45b9 divx5.1 features added
arpi
parents: 5706
diff changeset
51 #ifndef ENCORE_MAJOR_VERSION
3a961eaf45b9 divx5.1 features added
arpi
parents: 5706
diff changeset
52 #define ENCORE_MAJOR_VERSION 4000
3a961eaf45b9 divx5.1 features added
arpi
parents: 5706
diff changeset
53 #endif
3a961eaf45b9 divx5.1 features added
arpi
parents: 5706
diff changeset
54
5550
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
55 ENC_PARAM divx4_param;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
56 int divx4_crispness;
7332
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
57 #ifdef HAVE_XVID_VBR
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
58 static int vbrpass = -1;
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
59 static int vbrdebug = 0;
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
60 #endif
5550
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
61
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
62 #include "cfgparser.h"
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
63
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
64 struct config divx4opts_conf[]={
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
65 {"br", &divx4_param.bitrate, CONF_TYPE_INT, CONF_RANGE, 4, 24000000, NULL},
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
66 {"rc_period", &divx4_param.rc_period, CONF_TYPE_INT, 0,0,0, NULL},
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
67 {"rc_reaction_period", &divx4_param.rc_reaction_period, CONF_TYPE_INT, 0,0,0, NULL},
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
68 {"rc_reaction_ratio", &divx4_param.rc_reaction_ratio, CONF_TYPE_INT, 0,0,0, NULL},
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
69 {"min_quant", &divx4_param.min_quantizer, CONF_TYPE_INT, CONF_RANGE,0,32, NULL},
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
70 {"max_quant", &divx4_param.max_quantizer, CONF_TYPE_INT, CONF_RANGE,0,32, NULL},
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
71 {"key", &divx4_param.max_key_interval, CONF_TYPE_INT, CONF_MIN,0,0, NULL},
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
72 {"deinterlace", &divx4_param.deinterlace, CONF_TYPE_FLAG, 0,0,1, NULL},
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
73 {"q", &divx4_param.quality, CONF_TYPE_INT, CONF_RANGE, 1, 5, NULL},
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
74 {"crispness", &divx4_crispness, CONF_TYPE_INT, CONF_RANGE,0,100, NULL},
5854
3a961eaf45b9 divx5.1 features added
arpi
parents: 5706
diff changeset
75 #if ENCORE_MAJOR_VERSION >= 5010
3a961eaf45b9 divx5.1 features added
arpi
parents: 5706
diff changeset
76 {"bidirect", &divx4_param.extensions.use_bidirect, CONF_TYPE_FLAG, 0,0,1, NULL},
3a961eaf45b9 divx5.1 features added
arpi
parents: 5706
diff changeset
77 {"obmc", &divx4_param.extensions.obmc, CONF_TYPE_FLAG, 0,0,1, NULL},
3a961eaf45b9 divx5.1 features added
arpi
parents: 5706
diff changeset
78 {"data_partitioning", &divx4_param.extensions.data_partitioning, CONF_TYPE_FLAG, 0,0,1, NULL},
3a961eaf45b9 divx5.1 features added
arpi
parents: 5706
diff changeset
79 {"qpel", &divx4_param.extensions.quarter_pel, CONF_TYPE_FLAG, 0,0,1, NULL},
3a961eaf45b9 divx5.1 features added
arpi
parents: 5706
diff changeset
80 {"intra_frame_threshold", &divx4_param.extensions.intra_frame_threshold, CONF_TYPE_INT, CONF_RANGE,1,100, NULL},
3a961eaf45b9 divx5.1 features added
arpi
parents: 5706
diff changeset
81 {"psychovisual", &divx4_param.extensions.psychovisual, CONF_TYPE_FLAG, 0,0,1, NULL},
3a961eaf45b9 divx5.1 features added
arpi
parents: 5706
diff changeset
82 {"testing_param", &divx4_param.extensions.testing_param, CONF_TYPE_FLAG, 0,0,1, NULL},
3a961eaf45b9 divx5.1 features added
arpi
parents: 5706
diff changeset
83 {"gmc", &divx4_param.extensions.use_gmc, CONF_TYPE_FLAG, 0,0,1, NULL},
3a961eaf45b9 divx5.1 features added
arpi
parents: 5706
diff changeset
84 {"interlace_mode", &divx4_param.extensions.interlace_mode, CONF_TYPE_INT, CONF_RANGE,0,2, NULL},
3a961eaf45b9 divx5.1 features added
arpi
parents: 5706
diff changeset
85 {"temporal", &divx4_param.extensions.temporal_enable, CONF_TYPE_FLAG, 0,0,1, NULL},
3a961eaf45b9 divx5.1 features added
arpi
parents: 5706
diff changeset
86 {"spatial", &divx4_param.extensions.spatial_passes, CONF_TYPE_INT, 0,0,1, NULL},
3a961eaf45b9 divx5.1 features added
arpi
parents: 5706
diff changeset
87 {"mv_file", &divx4_param.extensions.mv_file, CONF_TYPE_STRING, 0,0,1, NULL},
3a961eaf45b9 divx5.1 features added
arpi
parents: 5706
diff changeset
88 #endif
7332
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
89 #ifdef HAVE_XVID_VBR
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
90 {"vbrpass", &vbrpass, CONF_TYPE_INT, CONF_RANGE, 0, 2, NULL},
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
91 {"vbrdebug", &vbrdebug, CONF_TYPE_INT, CONF_RANGE, 0, 1, NULL},
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
92 #endif
5550
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
93 {"help", "TODO: divx4opts help!\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
94 {NULL, NULL, 0, 0, 0, 0, NULL}
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
95 };
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
96
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
97 struct vf_priv_s {
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
98 aviwrite_stream_t* mux;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
99 ENC_RESULT enc_result;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
100 ENC_FRAME enc_frame;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
101 void* enc_handle;
7332
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
102 #ifdef HAVE_XVID_VBR
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
103 vbr_control_t vbr_state;
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
104 #endif
5550
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
105 };
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
106
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
107 #define mux_v (vf->priv->mux)
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
108
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
109 static int config(struct vf_instance_s* vf,
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
110 int width, int height, int d_width, int d_height,
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
111 unsigned int flags, unsigned int outfmt){
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
112
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
113 mux_v->bih->biWidth=width;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
114 mux_v->bih->biHeight=height;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
115
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
116 divx4_param.x_dim=width;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
117 divx4_param.y_dim=height;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
118 divx4_param.framerate=(float)mux_v->h.dwRate/mux_v->h.dwScale;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
119 mux_v->bih->biSizeImage=mux_v->bih->biWidth*mux_v->bih->biHeight*3;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
120
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
121 if(!divx4_param.bitrate) divx4_param.bitrate=800000;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
122 else if(divx4_param.bitrate<=16000) divx4_param.bitrate*=1000;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
123 if(!divx4_param.quality) divx4_param.quality=5; // the quality of compression ( 1 - fastest, 5 - best )
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
124
5551
73978162b6a1 soem fixes
arpi
parents: 5550
diff changeset
125 // set some usefull defaults:
73978162b6a1 soem fixes
arpi
parents: 5550
diff changeset
126 if(!divx4_param.min_quantizer) divx4_param.min_quantizer=2;
73978162b6a1 soem fixes
arpi
parents: 5550
diff changeset
127 if(!divx4_param.max_quantizer) divx4_param.max_quantizer=31;
73978162b6a1 soem fixes
arpi
parents: 5550
diff changeset
128 if(!divx4_param.rc_period) divx4_param.rc_period=2000;
73978162b6a1 soem fixes
arpi
parents: 5550
diff changeset
129 if(!divx4_param.rc_reaction_period) divx4_param.rc_reaction_period=10;
73978162b6a1 soem fixes
arpi
parents: 5550
diff changeset
130 if(!divx4_param.rc_reaction_ratio) divx4_param.rc_reaction_ratio=20;
73978162b6a1 soem fixes
arpi
parents: 5550
diff changeset
131
7332
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
132 #ifdef HAVE_XVID_VBR
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
133 if (vbrpass >= 0) {
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
134 vbrSetDefaults(&vf->priv->vbr_state);
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
135 vf->priv->vbr_state.desired_bitrate = divx4_param.bitrate;
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
136 switch (vbrpass) {
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
137 case 0:
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
138 vf->priv->vbr_state.mode = VBR_MODE_1PASS;
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
139 break;
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
140 case 1:
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
141 vf->priv->vbr_state.mode = VBR_MODE_2PASS_1;
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
142 break;
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
143 case 2:
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
144 vf->priv->vbr_state.mode = VBR_MODE_2PASS_2;
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
145 break;
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
146 default:
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
147 abort();
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
148 }
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
149 vf->priv->vbr_state.debug = vbrdebug;
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
150 if (vbrInit(&vf->priv->vbr_state) == -1)
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
151 abort();
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
152 /* XXX - kludge to workaround some DivX encoder limitations */
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
153 if (vf->priv->vbr_state.mode != VBR_MODE_2PASS_2)
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
154 divx4_param.min_quantizer = divx4_param.max_quantizer = vbrGetQuant(&vf->priv->vbr_state);
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
155 }
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
156 #endif
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
157
5550
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
158 divx4_param.handle=NULL;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
159 encore(NULL,ENC_OPT_INIT,&divx4_param,NULL);
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
160 vf->priv->enc_handle=divx4_param.handle;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
161 switch(outfmt){
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
162 case IMGFMT_YV12: vf->priv->enc_frame.colorspace=ENC_CSP_YV12; break;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
163 case IMGFMT_IYUV:
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
164 case IMGFMT_I420: vf->priv->enc_frame.colorspace=ENC_CSP_I420; break;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
165 case IMGFMT_YUY2: vf->priv->enc_frame.colorspace=ENC_CSP_YUY2; break;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
166 case IMGFMT_UYVY: vf->priv->enc_frame.colorspace=ENC_CSP_UYVY; break;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
167 case IMGFMT_RGB24:
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
168 case IMGFMT_BGR24:
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
169 vf->priv->enc_frame.colorspace=ENC_CSP_RGB24; break;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
170 default:
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
171 mp_msg(MSGT_MENCODER,MSGL_ERR,"divx4: unsupported picture format (%s)!\n",
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
172 vo_format_name(outfmt));
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
173 return 0;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
174 }
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
175
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
176 switch(pass){
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
177 case 1:
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
178 if (VbrControl_init_2pass_vbr_analysis(passtmpfile, divx4_param.quality) == -1){
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
179 mp_msg(MSGT_MENCODER,MSGL_ERR,"2pass failed: filename=%s\n", passtmpfile);
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
180 pass=0;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
181 }
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
182 break;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
183 case 2:
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
184 if (VbrControl_init_2pass_vbr_encoding(passtmpfile,
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
185 divx4_param.bitrate,
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
186 divx4_param.framerate,
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
187 divx4_crispness,
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
188 divx4_param.quality) == -1){
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
189 mp_msg(MSGT_MENCODER,MSGL_ERR,"2pass failed: filename=%s\n", passtmpfile);
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
190 pass=0;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
191 }
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
192 break;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
193 }
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
194
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
195 return 1;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
196 }
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
197
7332
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
198 #ifdef HAVE_XVID_VBR
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
199 static void uninit(struct vf_instance_s* vf){
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
200 if (vbrpass >= 0 && vbrFinish(&vf->priv->vbr_state) == -1)
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
201 abort();
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
202 }
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
203 #endif
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
204
5550
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
205 static int control(struct vf_instance_s* vf, int request, void* data){
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
206
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
207 return CONTROL_UNKNOWN;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
208 }
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
209
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
210 static int query_format(struct vf_instance_s* vf, unsigned int fmt){
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
211 switch(fmt){
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
212 case IMGFMT_YV12:
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
213 case IMGFMT_IYUV:
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
214 case IMGFMT_I420:
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
215 return 3; // no conversion
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
216 case IMGFMT_YUY2:
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
217 case IMGFMT_UYVY:
5706
26c89aadf6f8 flipped rgb fixed
arpi
parents: 5607
diff changeset
218 return 1; // conversion
5550
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
219 case IMGFMT_RGB24:
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
220 case IMGFMT_BGR24:
5706
26c89aadf6f8 flipped rgb fixed
arpi
parents: 5607
diff changeset
221 return 1 | VFCAP_FLIPPED; // conversion+flipped
5550
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
222 }
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
223 return 0;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
224 }
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
225
7368
a894e99c1e51 changing return type of put_image void->int
arpi
parents: 7332
diff changeset
226 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){
5550
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
227 ENC_RESULT enc_result;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
228 vf->priv->enc_frame.image=mpi->planes[0];
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
229 vf->priv->enc_frame.bitstream=mux_v->buffer;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
230 vf->priv->enc_frame.length=mux_v->buffer_size;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
231 vf->priv->enc_frame.mvs=NULL;
7332
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
232 #ifdef HAVE_XVID_VBR
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
233 if (vbrpass >= 0) {
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
234 int quant = vbrGetQuant(&vf->priv->vbr_state);
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
235 int intra = vbrGetIntra(&vf->priv->vbr_state);
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
236 vf->priv->enc_frame.quant = quant ? quant : 1;
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
237 vf->priv->enc_frame.intra = intra;
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
238 /* XXX - kludge to workaround some DivX encoder limitations:
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
239 only pass 2 needs to call encore with VBR, and then it does
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
240 not report quantizer and intra*/
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
241 if (vf->priv->vbr_state.mode != VBR_MODE_2PASS_2)
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
242 encore(vf->priv->enc_handle, ENC_OPT_ENCODE, &vf->priv->enc_frame, &enc_result);
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
243 else {
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
244 encore(vf->priv->enc_handle, ENC_OPT_ENCODE_VBR, &vf->priv->enc_frame, &enc_result);
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
245 enc_result.quantizer = quant;
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
246 if (intra >= 0)
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
247 enc_result.is_key_frame = intra;
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
248 }
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
249 if (vbrUpdate(&vf->priv->vbr_state, enc_result.quantizer, enc_result.is_key_frame,
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
250 (enc_result.total_bits - enc_result.texture_bits) / 8, enc_result.total_bits / 8,
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
251 0, 0, 0) == -1)
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
252 abort();
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
253 }
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
254 else
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
255 #endif
5550
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
256 if(pass==2){ // handle 2-pass:
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
257 vf->priv->enc_frame.quant = VbrControl_get_quant();
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
258 vf->priv->enc_frame.intra = VbrControl_get_intra();
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
259 encore(vf->priv->enc_handle,ENC_OPT_ENCODE_VBR,&vf->priv->enc_frame,&enc_result);
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
260 VbrControl_update_2pass_vbr_encoding(enc_result.motion_bits,
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
261 enc_result.texture_bits,
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
262 enc_result.total_bits);
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
263 } else {
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
264 vf->priv->enc_frame.quant=0;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
265 vf->priv->enc_frame.intra=0;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
266 encore(vf->priv->enc_handle,ENC_OPT_ENCODE,&vf->priv->enc_frame,&enc_result);
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
267 if(pass==1){
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
268 VbrControl_update_2pass_vbr_analysis(enc_result.is_key_frame,
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
269 enc_result.motion_bits,
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
270 enc_result.texture_bits,
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
271 enc_result.total_bits,
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
272 enc_result.quantizer);
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
273 }
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
274 }
5551
73978162b6a1 soem fixes
arpi
parents: 5550
diff changeset
275 mencoder_write_chunk(mux_v,vf->priv->enc_frame.length,enc_result.is_key_frame?0x10:0);
7368
a894e99c1e51 changing return type of put_image void->int
arpi
parents: 7332
diff changeset
276 return 1;
5550
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
277 }
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
278
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
279 //===========================================================================//
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
280
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
281 static int vf_open(vf_instance_t *vf, char* args){
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
282 vf->config=config;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
283 vf->control=control;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
284 vf->query_format=query_format;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
285 vf->put_image=put_image;
7332
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
286 #ifdef HAVE_XVID_VBR
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
287 vf->uninit = uninit;
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
288 #endif
5550
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
289 vf->priv=malloc(sizeof(struct vf_priv_s));
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
290 memset(vf->priv,0,sizeof(struct vf_priv_s));
7127
1e47c2e7aa8e mostly compiler warning fixes, some small bugfix
arpi
parents: 5854
diff changeset
291 vf->priv->mux=(aviwrite_stream_t*)args;
5550
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
292
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
293 mux_v->bih=malloc(sizeof(BITMAPINFOHEADER));
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
294 mux_v->bih->biSize=sizeof(BITMAPINFOHEADER);
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
295 mux_v->bih->biWidth=0;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
296 mux_v->bih->biHeight=0;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
297 mux_v->bih->biPlanes=1;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
298 mux_v->bih->biBitCount=24;
5854
3a961eaf45b9 divx5.1 features added
arpi
parents: 5706
diff changeset
299 #if ENCORE_MAJOR_VERSION >= 5010
3a961eaf45b9 divx5.1 features added
arpi
parents: 5706
diff changeset
300 mux_v->bih->biCompression=mmioFOURCC('D','X','5','0');
3a961eaf45b9 divx5.1 features added
arpi
parents: 5706
diff changeset
301 #else
5550
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
302 mux_v->bih->biCompression=mmioFOURCC('d','i','v','x');
5854
3a961eaf45b9 divx5.1 features added
arpi
parents: 5706
diff changeset
303 #endif
5550
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
304
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
305 return 1;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
306 }
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
307
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
308 vf_info_t ve_info_divx4 = {
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
309 "divx4 encoder",
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
310 "divx4",
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
311 "A'rpi",
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
312 "for internal use by mencoder",
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
313 vf_open
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
314 };
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
315
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
316 //===========================================================================//
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
317 #endif