Mercurial > mplayer.hg
annotate libmpcodecs/ve_lavc.c @ 7430:4304d0980a62
Moved all the cdinfo specific from cddb to a standalone file, so
if no network, cdda can still be compiled.
author | bertrand |
---|---|
date | Tue, 17 Sep 2002 19:49:57 +0000 |
parents | 6f3dd9df2cc2 |
children | 56a16bd12b79 |
rev | line source |
---|---|
5550 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 | |
5 #include "../config.h" | |
6 | |
7 #ifdef USE_LIBAVCODEC | |
8 | |
9 #include "../mp_msg.h" | |
10 #include "../help_mp.h" | |
11 | |
12 #include "codec-cfg.h" | |
13 #include "stream.h" | |
14 #include "demuxer.h" | |
15 #include "stheader.h" | |
16 | |
17 #include "aviwrite.h" | |
18 | |
5607 | 19 #include "img_format.h" |
20 #include "mp_image.h" | |
5550 | 21 #include "vf.h" |
22 | |
6673 | 23 #ifdef HAVE_DIVX4ENCORE |
5550 | 24 #include "divx4_vbr.h" |
6673 | 25 #endif |
5550 | 26 |
7090
43d7b60bd7f4
fixing compilation without divx4 patch by (Rmi Guyomarch <rguyom at pobox dot com>)
michael
parents:
7089
diff
changeset
|
27 extern char* passtmpfile; |
5550 | 28 extern int pass; |
7127 | 29 extern void mencoder_write_chunk(aviwrite_stream_t *s,int len,unsigned int flags); |
5550 | 30 |
31 //===========================================================================// | |
32 | |
33 #ifdef USE_LIBAVCODEC_SO | |
7004 | 34 #include <ffmpeg/avcodec.h> |
5550 | 35 #else |
36 #include "libavcodec/avcodec.h" | |
37 #endif | |
38 | |
5778 | 39 #if LIBAVCODEC_BUILD < 4601 |
40 #error your version of libavcodec is too old, get a newer one, and dont send a bugreport, THIS IS NO BUG | |
41 #endif | |
42 | |
7088 | 43 #if LIBAVCODEC_BUILD < 4620 |
44 #warning your version of libavcodec is old, u might want to get a newer one | |
45 #endif | |
46 | |
5550 | 47 extern int avcodec_inited; |
48 | |
49 /* video options */ | |
50 static char *lavc_param_vcodec = NULL; | |
51 static int lavc_param_vbitrate = -1; | |
7088 | 52 static int lavc_param_vrate_tolerance = 1000*8; |
5550 | 53 static int lavc_param_vhq = 0; /* default is realtime encoding */ |
54 static int lavc_param_v4mv = 0; | |
5556 | 55 static int lavc_param_vme = 4; |
5550 | 56 static int lavc_param_vqscale = 0; |
7088 | 57 static int lavc_param_vqmin = 2; |
58 static int lavc_param_vqmax = 31; | |
5550 | 59 static int lavc_param_vqdiff = 3; |
60 static float lavc_param_vqcompress = 0.5; | |
61 static float lavc_param_vqblur = 0.5; | |
7088 | 62 static float lavc_param_vb_qfactor = 1.25; |
63 static float lavc_param_vb_qoffset = 1.25; | |
64 static float lavc_param_vi_qfactor = 0.8; | |
65 static float lavc_param_vi_qoffset = 0.0; | |
5657
ee2efbf3dc9d
Preliminary support for lavcs b-frame encoding, disabled by default.
atmos4
parents:
5646
diff
changeset
|
66 static int lavc_param_vmax_b_frames = 0; |
5550 | 67 static int lavc_param_keyint = -1; |
5778 | 68 static int lavc_param_vpass = 0; |
69 static int lavc_param_vrc_strategy = 2; | |
70 static int lavc_param_vb_strategy = 0; | |
6255
140e94c4c89b
single coefficient elimination disabled by default
michael
parents:
6228
diff
changeset
|
71 static int lavc_param_luma_elim_threshold = 0; |
140e94c4c89b
single coefficient elimination disabled by default
michael
parents:
6228
diff
changeset
|
72 static int lavc_param_chroma_elim_threshold = 0; |
6228
ea6b20e70ac5
new options to support Michael's libavcodec patch, #ifdefed
arpi
parents:
5977
diff
changeset
|
73 static int lavc_param_packet_size= 0; |
ea6b20e70ac5
new options to support Michael's libavcodec patch, #ifdefed
arpi
parents:
5977
diff
changeset
|
74 static int lavc_param_strict= 0; |
ea6b20e70ac5
new options to support Michael's libavcodec patch, #ifdefed
arpi
parents:
5977
diff
changeset
|
75 static int lavc_param_data_partitioning= 0; |
6461 | 76 static int lavc_param_gray=0; |
7088 | 77 static float lavc_param_rc_qsquish=1.0; |
78 static float lavc_param_rc_qmod_amp=0; | |
79 static int lavc_param_rc_qmod_freq=0; | |
80 static char *lavc_param_rc_override_string=NULL; | |
81 static char *lavc_param_rc_eq="tex^qComp"; | |
82 static int lavc_param_rc_buffer_size=0; | |
83 static float lavc_param_rc_buffer_aggressivity=1.0; | |
84 static int lavc_param_rc_max_rate=0; | |
85 static int lavc_param_rc_min_rate=0; | |
86 static float lavc_param_rc_initial_cplx=0; | |
6944 | 87 static int lavc_param_mpeg_quant=0; |
7152 | 88 static int lavc_param_fdct=0; |
7389
6f3dd9df2cc2
aspect ratio support by encoding (currently only with mpeg4 and h263p)
alex
parents:
7368
diff
changeset
|
89 #if LIBAVCODEC_BUILD >= 4623 |
6f3dd9df2cc2
aspect ratio support by encoding (currently only with mpeg4 and h263p)
alex
parents:
7368
diff
changeset
|
90 static float lavc_param_aspect=0.0; |
6f3dd9df2cc2
aspect ratio support by encoding (currently only with mpeg4 and h263p)
alex
parents:
7368
diff
changeset
|
91 #endif |
5550 | 92 |
93 #include "cfgparser.h" | |
94 | |
95 #ifdef USE_LIBAVCODEC | |
96 struct config lavcopts_conf[]={ | |
97 {"vcodec", &lavc_param_vcodec, CONF_TYPE_STRING, 0, 0, 0, NULL}, | |
98 {"vbitrate", &lavc_param_vbitrate, CONF_TYPE_INT, CONF_RANGE, 4, 24000000, NULL}, | |
99 {"vratetol", &lavc_param_vrate_tolerance, CONF_TYPE_INT, CONF_RANGE, 4, 24000000, NULL}, | |
100 {"vhq", &lavc_param_vhq, CONF_TYPE_FLAG, 0, 0, 1, NULL}, | |
101 {"v4mv", &lavc_param_v4mv, CONF_TYPE_FLAG, 0, 0, 1, NULL}, | |
102 {"vme", &lavc_param_vme, CONF_TYPE_INT, CONF_RANGE, 0, 5, NULL}, | |
103 {"vqscale", &lavc_param_vqscale, CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL}, | |
104 {"vqmin", &lavc_param_vqmin, CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL}, | |
105 {"vqmax", &lavc_param_vqmax, CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL}, | |
106 {"vqdiff", &lavc_param_vqdiff, CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL}, | |
107 {"vqcomp", &lavc_param_vqcompress, CONF_TYPE_FLOAT, CONF_RANGE, 0.0, 1.0, NULL}, | |
108 {"vqblur", &lavc_param_vqblur, CONF_TYPE_FLOAT, CONF_RANGE, 0.0, 1.0, NULL}, | |
7088 | 109 {"vb_qfactor", &lavc_param_vb_qfactor, CONF_TYPE_FLOAT, CONF_RANGE, -31.0, 31.0, NULL}, |
5657
ee2efbf3dc9d
Preliminary support for lavcs b-frame encoding, disabled by default.
atmos4
parents:
5646
diff
changeset
|
110 {"vmax_b_frames", &lavc_param_vmax_b_frames, CONF_TYPE_INT, CONF_RANGE, 0, FF_MAX_B_FRAMES, NULL}, |
5778 | 111 {"vpass", &lavc_param_vpass, CONF_TYPE_INT, CONF_RANGE, 0, 2, NULL}, |
7088 | 112 #if LIBAVCODEC_BUILD < 4620 |
5778 | 113 {"vrc_strategy", &lavc_param_vrc_strategy, CONF_TYPE_INT, CONF_RANGE, 0, 2, NULL}, |
7088 | 114 #endif |
5778 | 115 {"vb_strategy", &lavc_param_vb_strategy, CONF_TYPE_INT, CONF_RANGE, 0, 1, NULL}, |
6228
ea6b20e70ac5
new options to support Michael's libavcodec patch, #ifdefed
arpi
parents:
5977
diff
changeset
|
116 #ifdef CODEC_FLAG_PART |
ea6b20e70ac5
new options to support Michael's libavcodec patch, #ifdefed
arpi
parents:
5977
diff
changeset
|
117 {"vb_qoffset", &lavc_param_vb_qoffset, CONF_TYPE_FLOAT, CONF_RANGE, 0.0, 31.0, NULL}, |
7039
2eae7ac0fa8b
same behavior for luma & chroma single coeff elimination
michael
parents:
7038
diff
changeset
|
118 {"vlelim", &lavc_param_luma_elim_threshold, CONF_TYPE_INT, CONF_RANGE, -99, 99, NULL}, |
7038 | 119 {"vcelim", &lavc_param_chroma_elim_threshold, CONF_TYPE_INT, CONF_RANGE, -99, 99, NULL}, |
6228
ea6b20e70ac5
new options to support Michael's libavcodec patch, #ifdefed
arpi
parents:
5977
diff
changeset
|
120 {"vpsize", &lavc_param_packet_size, CONF_TYPE_INT, CONF_RANGE, 0, 100000000, NULL}, |
ea6b20e70ac5
new options to support Michael's libavcodec patch, #ifdefed
arpi
parents:
5977
diff
changeset
|
121 {"vstrict", &lavc_param_strict, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
ea6b20e70ac5
new options to support Michael's libavcodec patch, #ifdefed
arpi
parents:
5977
diff
changeset
|
122 {"vdpart", &lavc_param_data_partitioning, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_PART, NULL}, |
ea6b20e70ac5
new options to support Michael's libavcodec patch, #ifdefed
arpi
parents:
5977
diff
changeset
|
123 #endif |
5550 | 124 {"keyint", &lavc_param_keyint, CONF_TYPE_INT, 0, 0, 0, NULL}, |
6461 | 125 #if LIBAVCODEC_BUILD >= 4614 |
126 {"gray", &lavc_param_gray, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_PART, NULL}, | |
127 #endif | |
6944 | 128 #if LIBAVCODEC_BUILD >= 4619 |
129 {"mpeg_quant", &lavc_param_mpeg_quant, CONF_TYPE_FLAG, 0, 0, 1, NULL}, | |
130 #endif | |
7088 | 131 #if LIBAVCODEC_BUILD >= 4620 |
132 {"vi_qfactor", &lavc_param_vi_qfactor, CONF_TYPE_FLOAT, CONF_RANGE, -31.0, 31.0, NULL}, | |
133 {"vi_qoffset", &lavc_param_vi_qoffset, CONF_TYPE_FLOAT, CONF_RANGE, 0.0, 31.0, NULL}, | |
134 {"vqsquish", &lavc_param_rc_qsquish, CONF_TYPE_FLOAT, CONF_RANGE, 0.0, 99.0, NULL}, | |
135 {"vqmod_amp", &lavc_param_rc_qmod_amp, CONF_TYPE_FLOAT, CONF_RANGE, 0.0, 99.0, NULL}, | |
136 {"vqmod_freq", &lavc_param_rc_qmod_freq, CONF_TYPE_INT, 0, 0, 0, NULL}, | |
137 {"vrc_eq", &lavc_param_rc_eq, CONF_TYPE_STRING, 0, 0, 0, NULL}, | |
138 {"vrc_override", &lavc_param_rc_override_string, CONF_TYPE_STRING, 0, 0, 0, NULL}, | |
139 {"vrc_maxrate", &lavc_param_rc_max_rate, CONF_TYPE_INT, CONF_RANGE, 4, 24000000, NULL}, | |
140 {"vrc_minrate", &lavc_param_rc_min_rate, CONF_TYPE_INT, CONF_RANGE, 4, 24000000, NULL}, | |
141 {"vrc_buf_size", &lavc_param_rc_min_rate, CONF_TYPE_INT, CONF_RANGE, 4, 24000000, NULL}, | |
142 {"vrc_buf_aggressivity", &lavc_param_rc_buffer_aggressivity, CONF_TYPE_FLOAT, CONF_RANGE, 0.0, 99.0, NULL}, | |
143 {"vrc_init_cplx", &lavc_param_rc_initial_cplx, CONF_TYPE_FLOAT, CONF_RANGE, 0.0, 9999999.0, NULL}, | |
144 #endif | |
7152 | 145 #if LIBAVCODEC_BUILD >= 4621 |
146 {"vfdct", &lavc_param_fdct, CONF_TYPE_INT, CONF_RANGE, 0, 10, NULL}, | |
147 #endif | |
7389
6f3dd9df2cc2
aspect ratio support by encoding (currently only with mpeg4 and h263p)
alex
parents:
7368
diff
changeset
|
148 #if LIBAVCODEC_BUILD >= 4623 |
6f3dd9df2cc2
aspect ratio support by encoding (currently only with mpeg4 and h263p)
alex
parents:
7368
diff
changeset
|
149 {"aspect", &lavc_param_aspect, CONF_TYPE_FLOAT, CONF_RANGE, 0.2, 3.0, NULL}, |
6f3dd9df2cc2
aspect ratio support by encoding (currently only with mpeg4 and h263p)
alex
parents:
7368
diff
changeset
|
150 #endif |
5550 | 151 {NULL, NULL, 0, 0, 0, 0, NULL} |
152 }; | |
153 #endif | |
154 | |
155 struct vf_priv_s { | |
156 aviwrite_stream_t* mux; | |
157 AVCodecContext context; | |
158 AVCodec *codec; | |
7088 | 159 FILE *stats_file; |
5550 | 160 }; |
161 | |
7088 | 162 #define stats_file (vf->priv->stats_file) |
5550 | 163 #define mux_v (vf->priv->mux) |
164 #define lavc_venc_context (vf->priv->context) | |
165 | |
166 static int config(struct vf_instance_s* vf, | |
167 int width, int height, int d_width, int d_height, | |
168 unsigned int flags, unsigned int outfmt){ | |
7088 | 169 int size, i; |
170 void *p; | |
171 | |
5550 | 172 mux_v->bih->biWidth=width; |
173 mux_v->bih->biHeight=height; | |
174 mux_v->bih->biSizeImage=mux_v->bih->biWidth*mux_v->bih->biHeight*(mux_v->bih->biBitCount/8); | |
175 | |
176 memset(&lavc_venc_context, 0, sizeof(lavc_venc_context)); | |
177 | |
178 printf("videocodec: libavcodec (%dx%d fourcc=%x [%.4s])\n", | |
179 mux_v->bih->biWidth, mux_v->bih->biHeight, mux_v->bih->biCompression, | |
180 (char *)&mux_v->bih->biCompression); | |
181 | |
182 lavc_venc_context.width = width; | |
183 lavc_venc_context.height = height; | |
5677
a21cab74cde8
bitrate>16000 means bits not kbits - noticed by George Hawkins <george_hawkins@yahoo.com>
arpi
parents:
5657
diff
changeset
|
184 if (lavc_param_vbitrate > 16000) /* != -1 */ |
a21cab74cde8
bitrate>16000 means bits not kbits - noticed by George Hawkins <george_hawkins@yahoo.com>
arpi
parents:
5657
diff
changeset
|
185 lavc_venc_context.bit_rate = lavc_param_vbitrate; |
a21cab74cde8
bitrate>16000 means bits not kbits - noticed by George Hawkins <george_hawkins@yahoo.com>
arpi
parents:
5657
diff
changeset
|
186 else if (lavc_param_vbitrate >= 0) /* != -1 */ |
5550 | 187 lavc_venc_context.bit_rate = lavc_param_vbitrate*1000; |
188 else | |
189 lavc_venc_context.bit_rate = 800000; /* default */ | |
190 lavc_venc_context.bit_rate_tolerance= lavc_param_vrate_tolerance*1000; | |
191 lavc_venc_context.frame_rate = (float)mux_v->h.dwRate/mux_v->h.dwScale * FRAME_RATE_BASE; | |
192 lavc_venc_context.qmin= lavc_param_vqmin; | |
193 lavc_venc_context.qmax= lavc_param_vqmax; | |
194 lavc_venc_context.max_qdiff= lavc_param_vqdiff; | |
195 lavc_venc_context.qcompress= lavc_param_vqcompress; | |
196 lavc_venc_context.qblur= lavc_param_vqblur; | |
5657
ee2efbf3dc9d
Preliminary support for lavcs b-frame encoding, disabled by default.
atmos4
parents:
5646
diff
changeset
|
197 lavc_venc_context.max_b_frames= lavc_param_vmax_b_frames; |
5778 | 198 lavc_venc_context.b_quant_factor= lavc_param_vb_qfactor; |
199 lavc_venc_context.rc_strategy= lavc_param_vrc_strategy; | |
200 lavc_venc_context.b_frame_strategy= lavc_param_vb_strategy; | |
6228
ea6b20e70ac5
new options to support Michael's libavcodec patch, #ifdefed
arpi
parents:
5977
diff
changeset
|
201 #ifdef CODEC_FLAG_PART |
ea6b20e70ac5
new options to support Michael's libavcodec patch, #ifdefed
arpi
parents:
5977
diff
changeset
|
202 lavc_venc_context.b_quant_offset= lavc_param_vb_qoffset; |
ea6b20e70ac5
new options to support Michael's libavcodec patch, #ifdefed
arpi
parents:
5977
diff
changeset
|
203 lavc_venc_context.luma_elim_threshold= lavc_param_luma_elim_threshold; |
ea6b20e70ac5
new options to support Michael's libavcodec patch, #ifdefed
arpi
parents:
5977
diff
changeset
|
204 lavc_venc_context.chroma_elim_threshold= lavc_param_chroma_elim_threshold; |
ea6b20e70ac5
new options to support Michael's libavcodec patch, #ifdefed
arpi
parents:
5977
diff
changeset
|
205 lavc_venc_context.rtp_payload_size= lavc_param_packet_size; |
ea6b20e70ac5
new options to support Michael's libavcodec patch, #ifdefed
arpi
parents:
5977
diff
changeset
|
206 if(lavc_param_packet_size )lavc_venc_context.rtp_mode=1; |
ea6b20e70ac5
new options to support Michael's libavcodec patch, #ifdefed
arpi
parents:
5977
diff
changeset
|
207 lavc_venc_context.strict_std_compliance= lavc_param_strict; |
ea6b20e70ac5
new options to support Michael's libavcodec patch, #ifdefed
arpi
parents:
5977
diff
changeset
|
208 #endif |
7088 | 209 #if LIBAVCODEC_BUILD >= 4620 |
210 lavc_venc_context.i_quant_factor= lavc_param_vi_qfactor; | |
211 lavc_venc_context.i_quant_offset= lavc_param_vi_qoffset; | |
212 lavc_venc_context.rc_qsquish= lavc_param_rc_qsquish; | |
213 lavc_venc_context.rc_qmod_amp= lavc_param_rc_qmod_amp; | |
214 lavc_venc_context.rc_qmod_freq= lavc_param_rc_qmod_freq; | |
215 lavc_venc_context.rc_eq= lavc_param_rc_eq; | |
216 lavc_venc_context.rc_max_rate= lavc_param_rc_max_rate*1000; | |
217 lavc_venc_context.rc_min_rate= lavc_param_rc_min_rate*1000; | |
218 lavc_venc_context.rc_buffer_size= lavc_param_rc_buffer_size*1000; | |
219 lavc_venc_context.rc_buffer_aggressivity= lavc_param_rc_buffer_aggressivity; | |
220 lavc_venc_context.rc_initial_cplx= lavc_param_rc_initial_cplx; | |
7152 | 221 |
7088 | 222 p= lavc_param_rc_override_string; |
223 for(i=0; p; i++){ | |
224 int start, end, q; | |
225 int e=sscanf(p, "%d,%d,%d", &start, &end, &q); | |
226 if(e!=3){ | |
227 mp_msg(MSGT_MENCODER,MSGL_ERR,"error parsing vrc_q\n"); | |
228 return 0; | |
229 } | |
230 lavc_venc_context.rc_override= | |
231 realloc(lavc_venc_context.rc_override, sizeof(RcOverride)*(i+1)); | |
232 lavc_venc_context.rc_override[i].start_frame= start; | |
233 lavc_venc_context.rc_override[i].end_frame = end; | |
234 if(q>0){ | |
235 lavc_venc_context.rc_override[i].qscale= q; | |
236 lavc_venc_context.rc_override[i].quality_factor= 1.0; | |
237 } | |
238 else{ | |
239 lavc_venc_context.rc_override[i].qscale= 0; | |
240 lavc_venc_context.rc_override[i].quality_factor= -q/100.0; | |
241 } | |
242 p= strchr(p, '/'); | |
243 if(p) p++; | |
244 } | |
245 lavc_venc_context.rc_override_count=i; | |
246 #endif | |
247 | |
6944 | 248 #if LIBAVCODEC_BUILD >= 4619 |
249 lavc_venc_context.mpeg_quant=lavc_param_mpeg_quant; | |
250 #endif | |
7152 | 251 |
252 #if LIBAVCODEC_BUILD >= 4621 | |
253 lavc_venc_context.dct_algo= lavc_param_fdct; | |
254 #endif | |
255 | |
7389
6f3dd9df2cc2
aspect ratio support by encoding (currently only with mpeg4 and h263p)
alex
parents:
7368
diff
changeset
|
256 #if LIBAVCODEC_BUILD >= 4623 |
6f3dd9df2cc2
aspect ratio support by encoding (currently only with mpeg4 and h263p)
alex
parents:
7368
diff
changeset
|
257 if (lavc_param_aspect != 0.0) |
6f3dd9df2cc2
aspect ratio support by encoding (currently only with mpeg4 and h263p)
alex
parents:
7368
diff
changeset
|
258 { |
6f3dd9df2cc2
aspect ratio support by encoding (currently only with mpeg4 and h263p)
alex
parents:
7368
diff
changeset
|
259 /* 625 means CIF */ |
6f3dd9df2cc2
aspect ratio support by encoding (currently only with mpeg4 and h263p)
alex
parents:
7368
diff
changeset
|
260 if (lavc_param_aspect == (float)(4.0/3.0)) |
6f3dd9df2cc2
aspect ratio support by encoding (currently only with mpeg4 and h263p)
alex
parents:
7368
diff
changeset
|
261 lavc_venc_context.aspect_ratio_info = FF_ASPECT_4_3_625; |
6f3dd9df2cc2
aspect ratio support by encoding (currently only with mpeg4 and h263p)
alex
parents:
7368
diff
changeset
|
262 else if (lavc_param_aspect == (float)(16.0/9.0)) |
6f3dd9df2cc2
aspect ratio support by encoding (currently only with mpeg4 and h263p)
alex
parents:
7368
diff
changeset
|
263 lavc_venc_context.aspect_ratio_info = FF_ASPECT_16_9_625; |
6f3dd9df2cc2
aspect ratio support by encoding (currently only with mpeg4 and h263p)
alex
parents:
7368
diff
changeset
|
264 else if (lavc_param_aspect == (float)(221.0/100.0)) |
6f3dd9df2cc2
aspect ratio support by encoding (currently only with mpeg4 and h263p)
alex
parents:
7368
diff
changeset
|
265 { |
6f3dd9df2cc2
aspect ratio support by encoding (currently only with mpeg4 and h263p)
alex
parents:
7368
diff
changeset
|
266 lavc_venc_context.aspect_ratio_info = FF_ASPECT_EXTENDED; |
6f3dd9df2cc2
aspect ratio support by encoding (currently only with mpeg4 and h263p)
alex
parents:
7368
diff
changeset
|
267 lavc_venc_context.aspected_width = 221; |
6f3dd9df2cc2
aspect ratio support by encoding (currently only with mpeg4 and h263p)
alex
parents:
7368
diff
changeset
|
268 lavc_venc_context.aspected_height = 100; |
6f3dd9df2cc2
aspect ratio support by encoding (currently only with mpeg4 and h263p)
alex
parents:
7368
diff
changeset
|
269 } |
6f3dd9df2cc2
aspect ratio support by encoding (currently only with mpeg4 and h263p)
alex
parents:
7368
diff
changeset
|
270 else |
6f3dd9df2cc2
aspect ratio support by encoding (currently only with mpeg4 and h263p)
alex
parents:
7368
diff
changeset
|
271 { |
6f3dd9df2cc2
aspect ratio support by encoding (currently only with mpeg4 and h263p)
alex
parents:
7368
diff
changeset
|
272 printf("Unsupported aspect ratio (%f)\n", lavc_param_aspect); |
6f3dd9df2cc2
aspect ratio support by encoding (currently only with mpeg4 and h263p)
alex
parents:
7368
diff
changeset
|
273 } |
6f3dd9df2cc2
aspect ratio support by encoding (currently only with mpeg4 and h263p)
alex
parents:
7368
diff
changeset
|
274 mp_dbg(MSGT_MENCODER, MSGL_DBG2, "aspect_ratio_info: %d\n", lavc_venc_context.aspect_ratio_info); |
6f3dd9df2cc2
aspect ratio support by encoding (currently only with mpeg4 and h263p)
alex
parents:
7368
diff
changeset
|
275 mp_dbg(MSGT_MENCODER, MSGL_DBG2, "par_width: %d\n", lavc_venc_context.aspected_width); |
6f3dd9df2cc2
aspect ratio support by encoding (currently only with mpeg4 and h263p)
alex
parents:
7368
diff
changeset
|
276 mp_dbg(MSGT_MENCODER, MSGL_DBG2, "par_height: %d\n", lavc_venc_context.aspected_height); |
6f3dd9df2cc2
aspect ratio support by encoding (currently only with mpeg4 and h263p)
alex
parents:
7368
diff
changeset
|
277 } |
6f3dd9df2cc2
aspect ratio support by encoding (currently only with mpeg4 and h263p)
alex
parents:
7368
diff
changeset
|
278 #endif |
6f3dd9df2cc2
aspect ratio support by encoding (currently only with mpeg4 and h263p)
alex
parents:
7368
diff
changeset
|
279 |
5550 | 280 /* keyframe interval */ |
281 if (lavc_param_keyint >= 0) /* != -1 */ | |
282 lavc_venc_context.gop_size = lavc_param_keyint; | |
283 else | |
284 lavc_venc_context.gop_size = 250; /* default */ | |
285 | |
286 if (lavc_param_vhq) | |
287 { | |
288 printf("High quality encoding selected (non real time)!\n"); | |
289 lavc_venc_context.flags = CODEC_FLAG_HQ; | |
290 } | |
291 else | |
292 lavc_venc_context.flags = 0; | |
293 | |
5781
62e9e0c0bd6a
hq mode in first pass should work (as bad, ehh as well as LQ)
michael
parents:
5778
diff
changeset
|
294 /* 4mv is currently buggy with B frames */ |
62e9e0c0bd6a
hq mode in first pass should work (as bad, ehh as well as LQ)
michael
parents:
5778
diff
changeset
|
295 if (lavc_param_vmax_b_frames > 0 && lavc_param_v4mv) { |
62e9e0c0bd6a
hq mode in first pass should work (as bad, ehh as well as LQ)
michael
parents:
5778
diff
changeset
|
296 printf("4MV with B-Frames not yet supported -> 4MV disabled\n"); |
62e9e0c0bd6a
hq mode in first pass should work (as bad, ehh as well as LQ)
michael
parents:
5778
diff
changeset
|
297 lavc_param_v4mv = 0; |
62e9e0c0bd6a
hq mode in first pass should work (as bad, ehh as well as LQ)
michael
parents:
5778
diff
changeset
|
298 } |
62e9e0c0bd6a
hq mode in first pass should work (as bad, ehh as well as LQ)
michael
parents:
5778
diff
changeset
|
299 |
5550 | 300 lavc_venc_context.flags|= lavc_param_v4mv ? CODEC_FLAG_4MV : 0; |
6228
ea6b20e70ac5
new options to support Michael's libavcodec patch, #ifdefed
arpi
parents:
5977
diff
changeset
|
301 #ifdef CODEC_FLAG_PART |
ea6b20e70ac5
new options to support Michael's libavcodec patch, #ifdefed
arpi
parents:
5977
diff
changeset
|
302 lavc_venc_context.flags|= lavc_param_data_partitioning; |
ea6b20e70ac5
new options to support Michael's libavcodec patch, #ifdefed
arpi
parents:
5977
diff
changeset
|
303 #endif |
6461 | 304 #if LIBAVCODEC_BUILD >= 4614 |
305 if(lavc_param_gray) lavc_venc_context.flags|= CODEC_FLAG_GRAY; | |
306 #endif | |
307 | |
5550 | 308 |
5778 | 309 /* lavc internal 2pass bitrate control */ |
6673 | 310 #ifdef HAVE_DIVX4ENCORE |
311 switch(lavc_param_vpass){ | |
312 #else | |
313 switch(lavc_param_vpass?lavc_param_vpass:pass){ | |
314 #endif | |
7088 | 315 case 1: |
316 lavc_venc_context.flags|= CODEC_FLAG_PASS1; | |
7089 | 317 #if LIBAVCODEC_BUILD >= 4620 |
7088 | 318 stats_file= fopen(passtmpfile, "w"); |
319 if(stats_file==NULL){ | |
320 mp_msg(MSGT_MENCODER,MSGL_ERR,"2pass failed: filename=%s\n", passtmpfile); | |
321 return 0; | |
322 } | |
7089 | 323 #endif |
7088 | 324 break; |
325 case 2: | |
326 lavc_venc_context.flags|= CODEC_FLAG_PASS2; | |
7089 | 327 #if LIBAVCODEC_BUILD >= 4620 |
7088 | 328 stats_file= fopen(passtmpfile, "r"); |
329 if(stats_file==NULL){ | |
330 mp_msg(MSGT_MENCODER,MSGL_ERR,"2pass failed: filename=%s\n", passtmpfile); | |
331 return 0; | |
332 } | |
333 fseek(stats_file, 0, SEEK_END); | |
334 size= ftell(stats_file); | |
335 fseek(stats_file, 0, SEEK_SET); | |
336 | |
337 lavc_venc_context.stats_in= malloc(size + 1); | |
338 lavc_venc_context.stats_in[size]=0; | |
339 | |
340 if(fread(lavc_venc_context.stats_in, size, 1, stats_file)<1){ | |
341 mp_msg(MSGT_MENCODER,MSGL_ERR,"2pass failed: reading from filename=%s\n", passtmpfile); | |
342 return 0; | |
7089 | 343 } |
344 #endif | |
7088 | 345 break; |
6673 | 346 } |
5778 | 347 |
5624 | 348 #ifdef ME_ZERO |
349 // workaround Juanjo's stupid incompatible change: | |
5550 | 350 motion_estimation_method = lavc_param_vme; |
5624 | 351 #else |
352 lavc_venc_context.me_method = ME_ZERO+lavc_param_vme; | |
353 #endif | |
5550 | 354 |
355 /* fixed qscale :p */ | |
356 if (lavc_param_vqscale) | |
357 { | |
358 printf("Using constant qscale = %d (VBR)\n", lavc_param_vqscale); | |
359 lavc_venc_context.flags |= CODEC_FLAG_QSCALE; | |
360 lavc_venc_context.quality = lavc_param_vqscale; | |
361 } | |
362 | |
6673 | 363 #ifdef HAVE_DIVX4ENCORE |
5550 | 364 switch(pass){ |
365 case 1: | |
366 if (VbrControl_init_2pass_vbr_analysis(passtmpfile, 5) == -1){ | |
367 mp_msg(MSGT_MENCODER,MSGL_ERR,"2pass failed: filename=%s\n", passtmpfile); | |
368 pass=0; | |
5781
62e9e0c0bd6a
hq mode in first pass should work (as bad, ehh as well as LQ)
michael
parents:
5778
diff
changeset
|
369 } |
5550 | 370 break; |
371 case 2: | |
372 if (VbrControl_init_2pass_vbr_encoding(passtmpfile, | |
373 lavc_venc_context.bit_rate, | |
374 (float)mux_v->h.dwRate/mux_v->h.dwScale, | |
375 100, /* crispness */ | |
376 5) == -1){ | |
377 mp_msg(MSGT_MENCODER,MSGL_ERR,"2pass failed: filename=%s\n", passtmpfile); | |
378 pass=0; | |
5632 | 379 } else |
380 lavc_venc_context.flags|=CODEC_FLAG_QSCALE|CODEC_FLAG_TYPE; // VBR | |
5550 | 381 break; |
382 } | |
6673 | 383 #endif |
5550 | 384 |
385 if (avcodec_open(&lavc_venc_context, vf->priv->codec) != 0) { | |
386 mp_msg(MSGT_MENCODER,MSGL_ERR,MSGTR_CantOpenCodec); | |
387 return 0; | |
388 } | |
389 | |
390 if (lavc_venc_context.codec->encode == NULL) { | |
391 mp_msg(MSGT_MENCODER,MSGL_ERR,"avcodec init failed (ctx->codec->encode == NULL)!\n"); | |
392 return 0; | |
393 } | |
7088 | 394 |
395 #if LIBAVCODEC_BUILD >= 4620 | |
396 /* free second pass buffer, its not needed anymore */ | |
397 if(lavc_venc_context.stats_in) free(lavc_venc_context.stats_in); | |
398 lavc_venc_context.stats_in= NULL; | |
399 #endif | |
400 | |
5550 | 401 return 1; |
402 } | |
403 | |
404 static int control(struct vf_instance_s* vf, int request, void* data){ | |
405 | |
406 return CONTROL_UNKNOWN; | |
407 } | |
408 | |
409 static int query_format(struct vf_instance_s* vf, unsigned int fmt){ | |
410 switch(fmt){ | |
411 case IMGFMT_YV12: | |
412 case IMGFMT_IYUV: | |
413 case IMGFMT_I420: | |
7389
6f3dd9df2cc2
aspect ratio support by encoding (currently only with mpeg4 and h263p)
alex
parents:
7368
diff
changeset
|
414 return VFCAP_CSP_SUPPORTED | VFCAP_ACCEPT_STRIDE; |
5550 | 415 } |
416 return 0; | |
417 } | |
418 | |
7368 | 419 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){ |
5550 | 420 int out_size; |
421 AVPicture lavc_venc_picture; | |
422 | |
423 lavc_venc_picture.data[0]=mpi->planes[0]; | |
424 lavc_venc_picture.data[1]=mpi->planes[1]; | |
425 lavc_venc_picture.data[2]=mpi->planes[2]; | |
426 lavc_venc_picture.linesize[0]=mpi->stride[0]; | |
427 lavc_venc_picture.linesize[1]=mpi->stride[1]; | |
428 lavc_venc_picture.linesize[2]=mpi->stride[2]; | |
429 | |
6673 | 430 #ifdef HAVE_DIVX4ENCORE |
5550 | 431 if(pass==2){ // handle 2-pass: |
432 lavc_venc_context.flags|=CODEC_FLAG_QSCALE; // enable VBR | |
433 lavc_venc_context.quality=VbrControl_get_quant(); | |
434 lavc_venc_context.key_frame=VbrControl_get_intra(); | |
435 lavc_venc_context.gop_size=0x3fffffff; | |
436 out_size = avcodec_encode_video(&lavc_venc_context, mux_v->buffer, mux_v->buffer_size, | |
437 &lavc_venc_picture); | |
438 VbrControl_update_2pass_vbr_encoding(lavc_venc_context.mv_bits, | |
439 lavc_venc_context.i_tex_bits+lavc_venc_context.p_tex_bits, | |
440 8*out_size); | |
6673 | 441 } else |
442 #endif | |
443 { | |
5550 | 444 out_size = avcodec_encode_video(&lavc_venc_context, mux_v->buffer, mux_v->buffer_size, |
445 &lavc_venc_picture); | |
6673 | 446 #ifdef HAVE_DIVX4ENCORE |
5550 | 447 if(pass==1){ |
448 VbrControl_update_2pass_vbr_analysis(lavc_venc_context.key_frame, | |
449 lavc_venc_context.mv_bits, | |
450 lavc_venc_context.i_tex_bits+lavc_venc_context.p_tex_bits, | |
451 8*out_size, lavc_venc_context.quality); | |
452 } | |
6673 | 453 #endif |
5550 | 454 } |
455 | |
456 mencoder_write_chunk(mux_v,out_size,lavc_venc_context.key_frame?0x10:0); | |
7088 | 457 |
458 #if LIBAVCODEC_BUILD >= 4620 | |
459 /* store stats if there are any */ | |
460 if(lavc_venc_context.stats_out && stats_file) | |
461 fprintf(stats_file, "%s", lavc_venc_context.stats_out); | |
462 #endif | |
7368 | 463 return 1; |
5550 | 464 } |
465 | |
5551 | 466 static void uninit(struct vf_instance_s* vf){ |
467 avcodec_close(&lavc_venc_context); | |
7088 | 468 |
7089 | 469 #if LIBAVCODEC_BUILD >= 4620 |
7088 | 470 if(stats_file) fclose(stats_file); |
7089 | 471 |
7088 | 472 /* free rc_override */ |
473 if(lavc_venc_context.rc_override) free(lavc_venc_context.rc_override); | |
474 lavc_venc_context.rc_override= NULL; | |
475 #endif | |
5551 | 476 } |
477 | |
5550 | 478 //===========================================================================// |
479 | |
480 static int vf_open(vf_instance_t *vf, char* args){ | |
5551 | 481 vf->uninit=uninit; |
5550 | 482 vf->config=config; |
483 vf->control=control; | |
484 vf->query_format=query_format; | |
485 vf->put_image=put_image; | |
486 vf->priv=malloc(sizeof(struct vf_priv_s)); | |
487 memset(vf->priv,0,sizeof(struct vf_priv_s)); | |
7127 | 488 vf->priv->mux=(aviwrite_stream_t*)args; |
5550 | 489 |
5977
e8f6f477aad0
a hack to make ffmjpeg created files viewable with windows dlls too
alex
parents:
5972
diff
changeset
|
490 /* XXX: hack: some of the MJPEG decoder DLL's needs exported huffman |
e8f6f477aad0
a hack to make ffmjpeg created files viewable with windows dlls too
alex
parents:
5972
diff
changeset
|
491 table, so we define a zero-table, also lavc mjpeg encoder is putting |
e8f6f477aad0
a hack to make ffmjpeg created files viewable with windows dlls too
alex
parents:
5972
diff
changeset
|
492 huffman tables into the stream, so no problem */ |
e8f6f477aad0
a hack to make ffmjpeg created files viewable with windows dlls too
alex
parents:
5972
diff
changeset
|
493 if (lavc_param_vcodec && !strcasecmp(lavc_param_vcodec, "mjpeg")) |
e8f6f477aad0
a hack to make ffmjpeg created files viewable with windows dlls too
alex
parents:
5972
diff
changeset
|
494 { |
e8f6f477aad0
a hack to make ffmjpeg created files viewable with windows dlls too
alex
parents:
5972
diff
changeset
|
495 mux_v->bih=malloc(sizeof(BITMAPINFOHEADER)+28); |
e8f6f477aad0
a hack to make ffmjpeg created files viewable with windows dlls too
alex
parents:
5972
diff
changeset
|
496 memset(mux_v->bih, 0, sizeof(BITMAPINFOHEADER)+28); |
e8f6f477aad0
a hack to make ffmjpeg created files viewable with windows dlls too
alex
parents:
5972
diff
changeset
|
497 mux_v->bih->biSize=sizeof(BITMAPINFOHEADER)+28; |
e8f6f477aad0
a hack to make ffmjpeg created files viewable with windows dlls too
alex
parents:
5972
diff
changeset
|
498 } |
e8f6f477aad0
a hack to make ffmjpeg created files viewable with windows dlls too
alex
parents:
5972
diff
changeset
|
499 else |
e8f6f477aad0
a hack to make ffmjpeg created files viewable with windows dlls too
alex
parents:
5972
diff
changeset
|
500 { |
e8f6f477aad0
a hack to make ffmjpeg created files viewable with windows dlls too
alex
parents:
5972
diff
changeset
|
501 mux_v->bih=malloc(sizeof(BITMAPINFOHEADER)); |
e8f6f477aad0
a hack to make ffmjpeg created files viewable with windows dlls too
alex
parents:
5972
diff
changeset
|
502 memset(mux_v->bih, 0, sizeof(BITMAPINFOHEADER)); |
e8f6f477aad0
a hack to make ffmjpeg created files viewable with windows dlls too
alex
parents:
5972
diff
changeset
|
503 mux_v->bih->biSize=sizeof(BITMAPINFOHEADER); |
e8f6f477aad0
a hack to make ffmjpeg created files viewable with windows dlls too
alex
parents:
5972
diff
changeset
|
504 } |
5550 | 505 mux_v->bih->biWidth=0; |
506 mux_v->bih->biHeight=0; | |
507 mux_v->bih->biPlanes=1; | |
508 mux_v->bih->biBitCount=24; | |
509 if (!lavc_param_vcodec) | |
510 { | |
5977
e8f6f477aad0
a hack to make ffmjpeg created files viewable with windows dlls too
alex
parents:
5972
diff
changeset
|
511 printf("No libavcodec codec specified! It's required!\n"); |
5550 | 512 return 0; |
513 } | |
514 | |
515 if (!strcasecmp(lavc_param_vcodec, "mpeg1") || !strcasecmp(lavc_param_vcodec, "mpeg1video")) | |
516 mux_v->bih->biCompression = mmioFOURCC('m', 'p', 'g', '1'); | |
517 else if (!strcasecmp(lavc_param_vcodec, "h263") || !strcasecmp(lavc_param_vcodec, "h263p")) | |
518 mux_v->bih->biCompression = mmioFOURCC('h', '2', '6', '3'); | |
519 else if (!strcasecmp(lavc_param_vcodec, "rv10")) | |
520 mux_v->bih->biCompression = mmioFOURCC('R', 'V', '1', '0'); | |
521 else if (!strcasecmp(lavc_param_vcodec, "mjpeg")) | |
522 mux_v->bih->biCompression = mmioFOURCC('M', 'J', 'P', 'G'); | |
523 else if (!strcasecmp(lavc_param_vcodec, "mpeg4")) | |
524 mux_v->bih->biCompression = mmioFOURCC('D', 'I', 'V', 'X'); | |
525 else if (!strcasecmp(lavc_param_vcodec, "msmpeg4")) | |
526 mux_v->bih->biCompression = mmioFOURCC('d', 'i', 'v', '3'); | |
5972 | 527 else if (!strcasecmp(lavc_param_vcodec, "msmpeg4v2")) |
528 mux_v->bih->biCompression = mmioFOURCC('M', 'P', '4', '2'); | |
6461 | 529 else if (!strcasecmp(lavc_param_vcodec, "wmv1")) |
530 mux_v->bih->biCompression = mmioFOURCC('W', 'M', 'V', '1'); | |
5550 | 531 else |
532 mux_v->bih->biCompression = mmioFOURCC(lavc_param_vcodec[0], | |
533 lavc_param_vcodec[1], lavc_param_vcodec[2], lavc_param_vcodec[3]); /* FIXME!!! */ | |
534 | |
535 if (!avcodec_inited){ | |
536 avcodec_init(); | |
537 avcodec_register_all(); | |
538 avcodec_inited=1; | |
539 } | |
540 | |
541 vf->priv->codec = (AVCodec *)avcodec_find_encoder_by_name(lavc_param_vcodec); | |
542 if (!vf->priv->codec) { | |
543 mp_msg(MSGT_MENCODER,MSGL_ERR,MSGTR_MissingLAVCcodec, lavc_param_vcodec); | |
544 return 0; | |
545 } | |
546 | |
547 return 1; | |
548 } | |
549 | |
550 vf_info_t ve_info_lavc = { | |
551 "libavcodec encoder", | |
552 "lavc", | |
6673 | 553 "A'rpi, Alex, Michael", |
5550 | 554 "for internal use by mencoder", |
555 vf_open | |
556 }; | |
557 | |
558 //===========================================================================// | |
559 #endif |