annotate libmpcodecs/ve_divx4.c @ 8102:2759150cc687

qt swot support
author alex
date Mon, 04 Nov 2002 20:28:21 +0000
parents 136e7e515764
children 27da710563c2
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
8032
136e7e515764 removed -pass nonsense from mencoder! it's now a suboption to -divx4opts
rfelker
parents: 7368
diff changeset
45 static int pass;
5550
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[]={
8032
136e7e515764 removed -pass nonsense from mencoder! it's now a suboption to -divx4opts
rfelker
parents: 7368
diff changeset
65 {"pass", &pass, CONF_TYPE_INT, CONF_RANGE,0,2, NULL},
5550
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
66 {"br", &divx4_param.bitrate, CONF_TYPE_INT, CONF_RANGE, 4, 24000000, NULL},
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
67 {"rc_period", &divx4_param.rc_period, CONF_TYPE_INT, 0,0,0, NULL},
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
68 {"rc_reaction_period", &divx4_param.rc_reaction_period, CONF_TYPE_INT, 0,0,0, NULL},
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
69 {"rc_reaction_ratio", &divx4_param.rc_reaction_ratio, CONF_TYPE_INT, 0,0,0, NULL},
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
70 {"min_quant", &divx4_param.min_quantizer, CONF_TYPE_INT, CONF_RANGE,0,32, NULL},
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
71 {"max_quant", &divx4_param.max_quantizer, CONF_TYPE_INT, CONF_RANGE,0,32, NULL},
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
72 {"key", &divx4_param.max_key_interval, CONF_TYPE_INT, CONF_MIN,0,0, NULL},
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
73 {"deinterlace", &divx4_param.deinterlace, CONF_TYPE_FLAG, 0,0,1, NULL},
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
74 {"q", &divx4_param.quality, CONF_TYPE_INT, CONF_RANGE, 1, 5, NULL},
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
75 {"crispness", &divx4_crispness, CONF_TYPE_INT, CONF_RANGE,0,100, NULL},
5854
3a961eaf45b9 divx5.1 features added
arpi
parents: 5706
diff changeset
76 #if ENCORE_MAJOR_VERSION >= 5010
3a961eaf45b9 divx5.1 features added
arpi
parents: 5706
diff changeset
77 {"bidirect", &divx4_param.extensions.use_bidirect, CONF_TYPE_FLAG, 0,0,1, NULL},
3a961eaf45b9 divx5.1 features added
arpi
parents: 5706
diff changeset
78 {"obmc", &divx4_param.extensions.obmc, CONF_TYPE_FLAG, 0,0,1, NULL},
3a961eaf45b9 divx5.1 features added
arpi
parents: 5706
diff changeset
79 {"data_partitioning", &divx4_param.extensions.data_partitioning, CONF_TYPE_FLAG, 0,0,1, NULL},
3a961eaf45b9 divx5.1 features added
arpi
parents: 5706
diff changeset
80 {"qpel", &divx4_param.extensions.quarter_pel, CONF_TYPE_FLAG, 0,0,1, NULL},
3a961eaf45b9 divx5.1 features added
arpi
parents: 5706
diff changeset
81 {"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
82 {"psychovisual", &divx4_param.extensions.psychovisual, CONF_TYPE_FLAG, 0,0,1, NULL},
3a961eaf45b9 divx5.1 features added
arpi
parents: 5706
diff changeset
83 {"testing_param", &divx4_param.extensions.testing_param, CONF_TYPE_FLAG, 0,0,1, NULL},
3a961eaf45b9 divx5.1 features added
arpi
parents: 5706
diff changeset
84 {"gmc", &divx4_param.extensions.use_gmc, CONF_TYPE_FLAG, 0,0,1, NULL},
3a961eaf45b9 divx5.1 features added
arpi
parents: 5706
diff changeset
85 {"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
86 {"temporal", &divx4_param.extensions.temporal_enable, CONF_TYPE_FLAG, 0,0,1, NULL},
3a961eaf45b9 divx5.1 features added
arpi
parents: 5706
diff changeset
87 {"spatial", &divx4_param.extensions.spatial_passes, CONF_TYPE_INT, 0,0,1, NULL},
3a961eaf45b9 divx5.1 features added
arpi
parents: 5706
diff changeset
88 {"mv_file", &divx4_param.extensions.mv_file, CONF_TYPE_STRING, 0,0,1, NULL},
3a961eaf45b9 divx5.1 features added
arpi
parents: 5706
diff changeset
89 #endif
7332
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
90 #ifdef HAVE_XVID_VBR
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
91 {"vbrpass", &vbrpass, CONF_TYPE_INT, CONF_RANGE, 0, 2, NULL},
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
92 {"vbrdebug", &vbrdebug, CONF_TYPE_INT, CONF_RANGE, 0, 1, NULL},
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
93 #endif
5550
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
94 {"help", "TODO: divx4opts help!\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
95 {NULL, NULL, 0, 0, 0, 0, NULL}
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
96 };
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
97
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
98 struct vf_priv_s {
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
99 aviwrite_stream_t* mux;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
100 ENC_RESULT enc_result;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
101 ENC_FRAME enc_frame;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
102 void* enc_handle;
7332
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
103 #ifdef HAVE_XVID_VBR
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
104 vbr_control_t vbr_state;
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
105 #endif
5550
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
106 };
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
107
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
108 #define mux_v (vf->priv->mux)
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
109
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
110 static int config(struct vf_instance_s* vf,
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
111 int width, int height, int d_width, int d_height,
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
112 unsigned int flags, unsigned int outfmt){
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
113
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
114 mux_v->bih->biWidth=width;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
115 mux_v->bih->biHeight=height;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
116
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
117 divx4_param.x_dim=width;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
118 divx4_param.y_dim=height;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
119 divx4_param.framerate=(float)mux_v->h.dwRate/mux_v->h.dwScale;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
120 mux_v->bih->biSizeImage=mux_v->bih->biWidth*mux_v->bih->biHeight*3;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
121
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
122 if(!divx4_param.bitrate) divx4_param.bitrate=800000;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
123 else if(divx4_param.bitrate<=16000) divx4_param.bitrate*=1000;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
124 if(!divx4_param.quality) divx4_param.quality=5; // the quality of compression ( 1 - fastest, 5 - best )
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
125
5551
73978162b6a1 soem fixes
arpi
parents: 5550
diff changeset
126 // set some usefull defaults:
73978162b6a1 soem fixes
arpi
parents: 5550
diff changeset
127 if(!divx4_param.min_quantizer) divx4_param.min_quantizer=2;
73978162b6a1 soem fixes
arpi
parents: 5550
diff changeset
128 if(!divx4_param.max_quantizer) divx4_param.max_quantizer=31;
73978162b6a1 soem fixes
arpi
parents: 5550
diff changeset
129 if(!divx4_param.rc_period) divx4_param.rc_period=2000;
73978162b6a1 soem fixes
arpi
parents: 5550
diff changeset
130 if(!divx4_param.rc_reaction_period) divx4_param.rc_reaction_period=10;
73978162b6a1 soem fixes
arpi
parents: 5550
diff changeset
131 if(!divx4_param.rc_reaction_ratio) divx4_param.rc_reaction_ratio=20;
73978162b6a1 soem fixes
arpi
parents: 5550
diff changeset
132
7332
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
133 #ifdef HAVE_XVID_VBR
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
134 if (vbrpass >= 0) {
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
135 vbrSetDefaults(&vf->priv->vbr_state);
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
136 vf->priv->vbr_state.desired_bitrate = divx4_param.bitrate;
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
137 switch (vbrpass) {
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
138 case 0:
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
139 vf->priv->vbr_state.mode = VBR_MODE_1PASS;
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
140 break;
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
141 case 1:
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
142 vf->priv->vbr_state.mode = VBR_MODE_2PASS_1;
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
143 break;
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
144 case 2:
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
145 vf->priv->vbr_state.mode = VBR_MODE_2PASS_2;
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
146 break;
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
147 default:
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
148 abort();
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
149 }
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
150 vf->priv->vbr_state.debug = vbrdebug;
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
151 if (vbrInit(&vf->priv->vbr_state) == -1)
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
152 abort();
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
153 /* XXX - kludge to workaround some DivX encoder limitations */
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
154 if (vf->priv->vbr_state.mode != VBR_MODE_2PASS_2)
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
155 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
156 }
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
157 #endif
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
158
5550
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
159 divx4_param.handle=NULL;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
160 encore(NULL,ENC_OPT_INIT,&divx4_param,NULL);
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
161 vf->priv->enc_handle=divx4_param.handle;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
162 switch(outfmt){
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
163 case IMGFMT_YV12: vf->priv->enc_frame.colorspace=ENC_CSP_YV12; break;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
164 case IMGFMT_IYUV:
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
165 case IMGFMT_I420: vf->priv->enc_frame.colorspace=ENC_CSP_I420; break;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
166 case IMGFMT_YUY2: vf->priv->enc_frame.colorspace=ENC_CSP_YUY2; break;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
167 case IMGFMT_UYVY: vf->priv->enc_frame.colorspace=ENC_CSP_UYVY; break;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
168 case IMGFMT_RGB24:
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
169 case IMGFMT_BGR24:
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
170 vf->priv->enc_frame.colorspace=ENC_CSP_RGB24; break;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
171 default:
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
172 mp_msg(MSGT_MENCODER,MSGL_ERR,"divx4: unsupported picture format (%s)!\n",
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
173 vo_format_name(outfmt));
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
174 return 0;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
175 }
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
176
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
177 switch(pass){
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
178 case 1:
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
179 if (VbrControl_init_2pass_vbr_analysis(passtmpfile, divx4_param.quality) == -1){
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
180 mp_msg(MSGT_MENCODER,MSGL_ERR,"2pass failed: filename=%s\n", passtmpfile);
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
181 pass=0;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
182 }
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
183 break;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
184 case 2:
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
185 if (VbrControl_init_2pass_vbr_encoding(passtmpfile,
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
186 divx4_param.bitrate,
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
187 divx4_param.framerate,
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
188 divx4_crispness,
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
189 divx4_param.quality) == -1){
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
190 mp_msg(MSGT_MENCODER,MSGL_ERR,"2pass failed: filename=%s\n", passtmpfile);
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
191 pass=0;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
192 }
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
193 break;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
194 }
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
195
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
196 return 1;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
197 }
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
198
7332
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
199 #ifdef HAVE_XVID_VBR
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
200 static void uninit(struct vf_instance_s* vf){
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
201 if (vbrpass >= 0 && vbrFinish(&vf->priv->vbr_state) == -1)
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
202 abort();
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
203 }
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
204 #endif
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
205
5550
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
206 static int control(struct vf_instance_s* vf, int request, void* data){
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
207
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
208 return CONTROL_UNKNOWN;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
209 }
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
210
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
211 static int query_format(struct vf_instance_s* vf, unsigned int fmt){
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
212 switch(fmt){
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
213 case IMGFMT_YV12:
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
214 case IMGFMT_IYUV:
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
215 case IMGFMT_I420:
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
216 return 3; // no conversion
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
217 case IMGFMT_YUY2:
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
218 case IMGFMT_UYVY:
5706
26c89aadf6f8 flipped rgb fixed
arpi
parents: 5607
diff changeset
219 return 1; // conversion
5550
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
220 case IMGFMT_RGB24:
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
221 case IMGFMT_BGR24:
5706
26c89aadf6f8 flipped rgb fixed
arpi
parents: 5607
diff changeset
222 return 1 | VFCAP_FLIPPED; // conversion+flipped
5550
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
223 }
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
224 return 0;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
225 }
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
226
7368
a894e99c1e51 changing return type of put_image void->int
arpi
parents: 7332
diff changeset
227 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){
5550
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
228 ENC_RESULT enc_result;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
229 vf->priv->enc_frame.image=mpi->planes[0];
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
230 vf->priv->enc_frame.bitstream=mux_v->buffer;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
231 vf->priv->enc_frame.length=mux_v->buffer_size;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
232 vf->priv->enc_frame.mvs=NULL;
7332
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
233 #ifdef HAVE_XVID_VBR
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
234 if (vbrpass >= 0) {
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
235 int quant = vbrGetQuant(&vf->priv->vbr_state);
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
236 int intra = vbrGetIntra(&vf->priv->vbr_state);
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
237 vf->priv->enc_frame.quant = quant ? quant : 1;
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
238 vf->priv->enc_frame.intra = intra;
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
239 /* XXX - kludge to workaround some DivX encoder limitations:
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
240 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
241 not report quantizer and intra*/
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
242 if (vf->priv->vbr_state.mode != VBR_MODE_2PASS_2)
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
243 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
244 else {
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
245 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
246 enc_result.quantizer = quant;
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
247 if (intra >= 0)
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
248 enc_result.is_key_frame = intra;
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
249 }
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
250 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
251 (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
252 0, 0, 0) == -1)
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
253 abort();
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
254 }
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
255 else
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
256 #endif
5550
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
257 if(pass==2){ // handle 2-pass:
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
258 vf->priv->enc_frame.quant = VbrControl_get_quant();
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
259 vf->priv->enc_frame.intra = VbrControl_get_intra();
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
260 encore(vf->priv->enc_handle,ENC_OPT_ENCODE_VBR,&vf->priv->enc_frame,&enc_result);
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
261 VbrControl_update_2pass_vbr_encoding(enc_result.motion_bits,
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
262 enc_result.texture_bits,
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
263 enc_result.total_bits);
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
264 } else {
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
265 vf->priv->enc_frame.quant=0;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
266 vf->priv->enc_frame.intra=0;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
267 encore(vf->priv->enc_handle,ENC_OPT_ENCODE,&vf->priv->enc_frame,&enc_result);
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
268 if(pass==1){
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
269 VbrControl_update_2pass_vbr_analysis(enc_result.is_key_frame,
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
270 enc_result.motion_bits,
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
271 enc_result.texture_bits,
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
272 enc_result.total_bits,
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
273 enc_result.quantizer);
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
274 }
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
275 }
5551
73978162b6a1 soem fixes
arpi
parents: 5550
diff changeset
276 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
277 return 1;
5550
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
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
282 static int vf_open(vf_instance_t *vf, char* args){
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
283 vf->config=config;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
284 vf->control=control;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
285 vf->query_format=query_format;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
286 vf->put_image=put_image;
7332
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
287 #ifdef HAVE_XVID_VBR
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
288 vf->uninit = uninit;
dd32b0c95c95 Code to XviD VBR Library from transcode.
kmkaplan
parents: 7127
diff changeset
289 #endif
5550
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
290 vf->priv=malloc(sizeof(struct vf_priv_s));
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
291 memset(vf->priv,0,sizeof(struct vf_priv_s));
7127
1e47c2e7aa8e mostly compiler warning fixes, some small bugfix
arpi
parents: 5854
diff changeset
292 vf->priv->mux=(aviwrite_stream_t*)args;
5550
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
293
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
294 mux_v->bih=malloc(sizeof(BITMAPINFOHEADER));
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
295 mux_v->bih->biSize=sizeof(BITMAPINFOHEADER);
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
296 mux_v->bih->biWidth=0;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
297 mux_v->bih->biHeight=0;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
298 mux_v->bih->biPlanes=1;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
299 mux_v->bih->biBitCount=24;
5854
3a961eaf45b9 divx5.1 features added
arpi
parents: 5706
diff changeset
300 #if ENCORE_MAJOR_VERSION >= 5010
3a961eaf45b9 divx5.1 features added
arpi
parents: 5706
diff changeset
301 mux_v->bih->biCompression=mmioFOURCC('D','X','5','0');
3a961eaf45b9 divx5.1 features added
arpi
parents: 5706
diff changeset
302 #else
5550
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
303 mux_v->bih->biCompression=mmioFOURCC('d','i','v','x');
5854
3a961eaf45b9 divx5.1 features added
arpi
parents: 5706
diff changeset
304 #endif
5550
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
305
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
306 return 1;
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
307 }
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
308
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
309 vf_info_t ve_info_divx4 = {
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
310 "divx4 encoder",
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
311 "divx4",
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
312 "A'rpi",
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
313 "for internal use by mencoder",
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
314 vf_open
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
315 };
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
316
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
317 //===========================================================================//
7d1dfb59c6c0 encoders
arpi
parents:
diff changeset
318 #endif