annotate libmpcodecs/ve_divx4.c @ 9864:b65bcfaedbe5

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