Mercurial > mplayer.hg
annotate libmpcodecs/ve_lavc.c @ 10512:e488c51b5a3a
10l
author | alex |
---|---|
date | Sun, 03 Aug 2003 17:26:25 +0000 |
parents | 17391ba6c53b |
children | 57bdcdb061d7 |
rev | line source |
---|---|
5550 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <string.h> | |
8237 | 4 #include <math.h> |
8347 | 5 #include <time.h> |
5550 | 6 |
8371
345a539683da
infinity fix by ("Steven M. Schultz" <sms at 2BSD dot COM>)
michael
parents:
8347
diff
changeset
|
7 #if !defined(INFINITY) && defined(HUGE_VAL) |
345a539683da
infinity fix by ("Steven M. Schultz" <sms at 2BSD dot COM>)
michael
parents:
8347
diff
changeset
|
8 #define INFINITY HUGE_VAL |
345a539683da
infinity fix by ("Steven M. Schultz" <sms at 2BSD dot COM>)
michael
parents:
8347
diff
changeset
|
9 #endif |
345a539683da
infinity fix by ("Steven M. Schultz" <sms at 2BSD dot COM>)
michael
parents:
8347
diff
changeset
|
10 |
5550 | 11 #include "../config.h" |
12 | |
13 #ifdef USE_LIBAVCODEC | |
14 | |
15 #include "../mp_msg.h" | |
16 #include "../help_mp.h" | |
17 | |
18 #include "codec-cfg.h" | |
19 #include "stream.h" | |
20 #include "demuxer.h" | |
21 #include "stheader.h" | |
22 | |
8585 | 23 #include "muxer.h" |
5550 | 24 |
5607 | 25 #include "img_format.h" |
26 #include "mp_image.h" | |
5550 | 27 #include "vf.h" |
28 | |
7090
43d7b60bd7f4
fixing compilation without divx4 patch by (Rmi Guyomarch <rguyom at pobox dot com>)
michael
parents:
7089
diff
changeset
|
29 extern char* passtmpfile; |
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 | |
8339 | 39 #if LIBAVCODEC_BUILD < 4641 |
8340 | 40 #error we dont support libavcodec prior to build 4641, get the latest libavcodec CVS |
5778 | 41 #endif |
42 | |
9508 | 43 #if LIBAVCODEC_BUILD < 4659 |
7088 | 44 #warning your version of libavcodec is old, u might want to get a newer one |
45 #endif | |
46 | |
8413 | 47 #if LIBAVCODEC_BUILD < 4645 |
48 #define AVFrame AVVideoFrame | |
49 #define coded_frame coded_picture | |
50 #endif | |
51 | |
5550 | 52 extern int avcodec_inited; |
53 | |
54 /* video options */ | |
7555 | 55 static char *lavc_param_vcodec = "mpeg4"; |
5550 | 56 static int lavc_param_vbitrate = -1; |
7088 | 57 static int lavc_param_vrate_tolerance = 1000*8; |
10498 | 58 static int lavc_param_mb_decision = 0; /* default is realtime encoding */ |
5550 | 59 static int lavc_param_v4mv = 0; |
5556 | 60 static int lavc_param_vme = 4; |
5550 | 61 static int lavc_param_vqscale = 0; |
7088 | 62 static int lavc_param_vqmin = 2; |
63 static int lavc_param_vqmax = 31; | |
8492 | 64 static int lavc_param_mb_qmin = 2; |
65 static int lavc_param_mb_qmax = 31; | |
5550 | 66 static int lavc_param_vqdiff = 3; |
67 static float lavc_param_vqcompress = 0.5; | |
68 static float lavc_param_vqblur = 0.5; | |
7088 | 69 static float lavc_param_vb_qfactor = 1.25; |
70 static float lavc_param_vb_qoffset = 1.25; | |
71 static float lavc_param_vi_qfactor = 0.8; | |
72 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
|
73 static int lavc_param_vmax_b_frames = 0; |
5550 | 74 static int lavc_param_keyint = -1; |
5778 | 75 static int lavc_param_vpass = 0; |
76 static int lavc_param_vrc_strategy = 2; | |
77 static int lavc_param_vb_strategy = 0; | |
6255
140e94c4c89b
single coefficient elimination disabled by default
michael
parents:
6228
diff
changeset
|
78 static int lavc_param_luma_elim_threshold = 0; |
140e94c4c89b
single coefficient elimination disabled by default
michael
parents:
6228
diff
changeset
|
79 static int lavc_param_chroma_elim_threshold = 0; |
6228
ea6b20e70ac5
new options to support Michael's libavcodec patch, #ifdefed
arpi
parents:
5977
diff
changeset
|
80 static int lavc_param_packet_size= 0; |
ea6b20e70ac5
new options to support Michael's libavcodec patch, #ifdefed
arpi
parents:
5977
diff
changeset
|
81 static int lavc_param_strict= 0; |
ea6b20e70ac5
new options to support Michael's libavcodec patch, #ifdefed
arpi
parents:
5977
diff
changeset
|
82 static int lavc_param_data_partitioning= 0; |
6461 | 83 static int lavc_param_gray=0; |
7088 | 84 static float lavc_param_rc_qsquish=1.0; |
85 static float lavc_param_rc_qmod_amp=0; | |
86 static int lavc_param_rc_qmod_freq=0; | |
87 static char *lavc_param_rc_override_string=NULL; | |
88 static char *lavc_param_rc_eq="tex^qComp"; | |
89 static int lavc_param_rc_buffer_size=0; | |
90 static float lavc_param_rc_buffer_aggressivity=1.0; | |
91 static int lavc_param_rc_max_rate=0; | |
92 static int lavc_param_rc_min_rate=0; | |
93 static float lavc_param_rc_initial_cplx=0; | |
6944 | 94 static int lavc_param_mpeg_quant=0; |
7152 | 95 static int lavc_param_fdct=0; |
7564 | 96 static int lavc_param_idct=0; |
8237 | 97 static char* lavc_param_aspect = NULL; |
9993
6e7f3643bee6
optional automatic aspect encoding based on d_width and d_height
rfelker
parents:
9868
diff
changeset
|
98 static int lavc_param_autoaspect = 0; |
7490 | 99 static float lavc_param_lumi_masking= 0.0; |
7496 | 100 static float lavc_param_dark_masking= 0.0; |
7490 | 101 static float lavc_param_temporal_cplx_masking= 0.0; |
102 static float lavc_param_spatial_cplx_masking= 0.0; | |
103 static float lavc_param_p_masking= 0.0; | |
104 static int lavc_param_normalize_aqp= 0; | |
7504 | 105 static int lavc_param_interlaced_dct= 0; |
8190 | 106 static int lavc_param_prediction_method= FF_PRED_LEFT; |
107 static char *lavc_param_format="YV12"; | |
8341 | 108 static int lavc_param_debug= 0; |
8347 | 109 static int lavc_param_psnr= 0; |
8803 | 110 static int lavc_param_me_pre_cmp= 0; |
8587 | 111 static int lavc_param_me_cmp= 0; |
112 static int lavc_param_me_sub_cmp= 0; | |
113 static int lavc_param_mb_cmp= 0; | |
8803 | 114 static int lavc_param_pre_dia_size= 0; |
8587 | 115 static int lavc_param_dia_size= 0; |
116 static int lavc_param_qpel= 0; | |
8684 | 117 static int lavc_param_trell= 0; |
9536 | 118 static int lavc_param_aic= 0; |
119 static int lavc_param_umv= 0; | |
8695 | 120 static int lavc_param_last_pred= 0; |
8709 | 121 static int lavc_param_pre_me= 1; |
8803 | 122 static int lavc_param_me_subpel_quality= 8; |
9508 | 123 static int lavc_param_me_range= 0; |
9645 | 124 #if LIBAVCODEC_BUILD >= 4663 |
125 static int lavc_param_ibias= FF_DEFAULT_QUANT_BIAS; | |
126 static int lavc_param_pbias= FF_DEFAULT_QUANT_BIAS; | |
127 #endif | |
10291 | 128 static int lavc_param_coder= 0; |
129 static int lavc_param_context= 0; | |
5550 | 130 |
131 #include "cfgparser.h" | |
132 | |
133 #ifdef USE_LIBAVCODEC | |
134 struct config lavcopts_conf[]={ | |
135 {"vcodec", &lavc_param_vcodec, CONF_TYPE_STRING, 0, 0, 0, NULL}, | |
136 {"vbitrate", &lavc_param_vbitrate, CONF_TYPE_INT, CONF_RANGE, 4, 24000000, NULL}, | |
137 {"vratetol", &lavc_param_vrate_tolerance, CONF_TYPE_INT, CONF_RANGE, 4, 24000000, NULL}, | |
10498 | 138 {"vhq", &lavc_param_mb_decision, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
139 {"mbd", &lavc_param_mb_decision, CONF_TYPE_INT, CONF_RANGE, 0, 9, NULL}, | |
5550 | 140 {"v4mv", &lavc_param_v4mv, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
141 {"vme", &lavc_param_vme, CONF_TYPE_INT, CONF_RANGE, 0, 5, NULL}, | |
142 {"vqscale", &lavc_param_vqscale, CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL}, | |
143 {"vqmin", &lavc_param_vqmin, CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL}, | |
144 {"vqmax", &lavc_param_vqmax, CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL}, | |
8492 | 145 {"mbqmin", &lavc_param_mb_qmin, CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL}, |
146 {"mbqmax", &lavc_param_mb_qmax, CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL}, | |
5550 | 147 {"vqdiff", &lavc_param_vqdiff, CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL}, |
148 {"vqcomp", &lavc_param_vqcompress, CONF_TYPE_FLOAT, CONF_RANGE, 0.0, 1.0, NULL}, | |
149 {"vqblur", &lavc_param_vqblur, CONF_TYPE_FLOAT, CONF_RANGE, 0.0, 1.0, NULL}, | |
7088 | 150 {"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
|
151 {"vmax_b_frames", &lavc_param_vmax_b_frames, CONF_TYPE_INT, CONF_RANGE, 0, FF_MAX_B_FRAMES, NULL}, |
5778 | 152 {"vpass", &lavc_param_vpass, CONF_TYPE_INT, CONF_RANGE, 0, 2, NULL}, |
153 {"vrc_strategy", &lavc_param_vrc_strategy, CONF_TYPE_INT, CONF_RANGE, 0, 2, NULL}, | |
8413 | 154 {"vb_strategy", &lavc_param_vb_strategy, CONF_TYPE_INT, CONF_RANGE, 0, 10, NULL}, |
6228
ea6b20e70ac5
new options to support Michael's libavcodec patch, #ifdefed
arpi
parents:
5977
diff
changeset
|
155 {"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
|
156 {"vlelim", &lavc_param_luma_elim_threshold, CONF_TYPE_INT, CONF_RANGE, -99, 99, NULL}, |
7038 | 157 {"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
|
158 {"vpsize", &lavc_param_packet_size, CONF_TYPE_INT, CONF_RANGE, 0, 100000000, NULL}, |
8195 | 159 {"vstrict", &lavc_param_strict, CONF_TYPE_INT, CONF_RANGE, -99, 99, NULL}, |
6228
ea6b20e70ac5
new options to support Michael's libavcodec patch, #ifdefed
arpi
parents:
5977
diff
changeset
|
160 {"vdpart", &lavc_param_data_partitioning, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_PART, NULL}, |
5550 | 161 {"keyint", &lavc_param_keyint, CONF_TYPE_INT, 0, 0, 0, NULL}, |
6461 | 162 {"gray", &lavc_param_gray, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_PART, NULL}, |
6944 | 163 {"mpeg_quant", &lavc_param_mpeg_quant, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
7088 | 164 {"vi_qfactor", &lavc_param_vi_qfactor, CONF_TYPE_FLOAT, CONF_RANGE, -31.0, 31.0, NULL}, |
165 {"vi_qoffset", &lavc_param_vi_qoffset, CONF_TYPE_FLOAT, CONF_RANGE, 0.0, 31.0, NULL}, | |
166 {"vqsquish", &lavc_param_rc_qsquish, CONF_TYPE_FLOAT, CONF_RANGE, 0.0, 99.0, NULL}, | |
167 {"vqmod_amp", &lavc_param_rc_qmod_amp, CONF_TYPE_FLOAT, CONF_RANGE, 0.0, 99.0, NULL}, | |
168 {"vqmod_freq", &lavc_param_rc_qmod_freq, CONF_TYPE_INT, 0, 0, 0, NULL}, | |
169 {"vrc_eq", &lavc_param_rc_eq, CONF_TYPE_STRING, 0, 0, 0, NULL}, | |
170 {"vrc_override", &lavc_param_rc_override_string, CONF_TYPE_STRING, 0, 0, 0, NULL}, | |
171 {"vrc_maxrate", &lavc_param_rc_max_rate, CONF_TYPE_INT, CONF_RANGE, 4, 24000000, NULL}, | |
172 {"vrc_minrate", &lavc_param_rc_min_rate, CONF_TYPE_INT, CONF_RANGE, 4, 24000000, NULL}, | |
173 {"vrc_buf_size", &lavc_param_rc_min_rate, CONF_TYPE_INT, CONF_RANGE, 4, 24000000, NULL}, | |
174 {"vrc_buf_aggressivity", &lavc_param_rc_buffer_aggressivity, CONF_TYPE_FLOAT, CONF_RANGE, 0.0, 99.0, NULL}, | |
175 {"vrc_init_cplx", &lavc_param_rc_initial_cplx, CONF_TYPE_FLOAT, CONF_RANGE, 0.0, 9999999.0, NULL}, | |
7152 | 176 {"vfdct", &lavc_param_fdct, CONF_TYPE_INT, CONF_RANGE, 0, 10, NULL}, |
8237 | 177 {"aspect", &lavc_param_aspect, CONF_TYPE_STRING, 0, 0, 0, NULL}, |
9993
6e7f3643bee6
optional automatic aspect encoding based on d_width and d_height
rfelker
parents:
9868
diff
changeset
|
178 {"autoaspect", &lavc_param_autoaspect, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
7490 | 179 {"lumi_mask", &lavc_param_lumi_masking, CONF_TYPE_FLOAT, CONF_RANGE, -1.0, 1.0, NULL}, |
180 {"tcplx_mask", &lavc_param_temporal_cplx_masking, CONF_TYPE_FLOAT, CONF_RANGE, -1.0, 1.0, NULL}, | |
181 {"scplx_mask", &lavc_param_spatial_cplx_masking, CONF_TYPE_FLOAT, CONF_RANGE, -1.0, 1.0, NULL}, | |
182 {"p_mask", &lavc_param_p_masking, CONF_TYPE_FLOAT, CONF_RANGE, -1.0, 1.0, NULL}, | |
183 {"naq", &lavc_param_normalize_aqp, CONF_TYPE_FLAG, 0, 0, 1, NULL}, | |
7496 | 184 {"dark_mask", &lavc_param_dark_masking, CONF_TYPE_FLOAT, CONF_RANGE, -1.0, 1.0, NULL}, |
7504 | 185 {"ildct", &lavc_param_interlaced_dct, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
7564 | 186 {"idct", &lavc_param_idct, CONF_TYPE_INT, CONF_RANGE, 0, 20, NULL}, |
8190 | 187 {"pred", &lavc_param_prediction_method, CONF_TYPE_INT, CONF_RANGE, 0, 20, NULL}, |
188 {"format", &lavc_param_format, CONF_TYPE_STRING, 0, 0, 0, NULL}, | |
8341 | 189 #if LIBAVCODEC_BUILD >= 4642 |
190 {"debug", &lavc_param_debug, CONF_TYPE_INT, CONF_RANGE, 0, 100000000, NULL}, | |
191 #endif | |
8347 | 192 #if LIBAVCODEC_BUILD >= 4643 |
193 {"psnr", &lavc_param_psnr, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_PSNR, NULL}, | |
194 #endif | |
8803 | 195 {"precmp", &lavc_param_me_pre_cmp, CONF_TYPE_INT, CONF_RANGE, 0, 2000, NULL}, |
8587 | 196 {"cmp", &lavc_param_me_cmp, CONF_TYPE_INT, CONF_RANGE, 0, 2000, NULL}, |
197 {"subcmp", &lavc_param_me_sub_cmp, CONF_TYPE_INT, CONF_RANGE, 0, 2000, NULL}, | |
198 {"mbcmp", &lavc_param_mb_cmp, CONF_TYPE_INT, CONF_RANGE, 0, 2000, NULL}, | |
8803 | 199 {"predia", &lavc_param_pre_dia_size, CONF_TYPE_INT, CONF_RANGE, -2000, 2000, NULL}, |
8684 | 200 {"dia", &lavc_param_dia_size, CONF_TYPE_INT, CONF_RANGE, -2000, 2000, NULL}, |
8587 | 201 {"qpel", &lavc_param_qpel, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_QPEL, NULL}, |
8684 | 202 #if LIBAVCODEC_BUILD >= 4648 |
203 {"trell", &lavc_param_trell, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_TRELLIS_QUANT, NULL}, | |
204 #endif | |
8695 | 205 {"last_pred", &lavc_param_last_pred, CONF_TYPE_INT, CONF_RANGE, 0, 2000, NULL}, |
8709 | 206 {"preme", &lavc_param_pre_me, CONF_TYPE_INT, CONF_RANGE, 0, 2000, NULL}, |
8803 | 207 {"subq", &lavc_param_me_subpel_quality, CONF_TYPE_INT, CONF_RANGE, 0, 8, NULL}, |
9508 | 208 {"me_range", &lavc_param_me_range, CONF_TYPE_INT, CONF_RANGE, 0, 16000, NULL}, |
9536 | 209 #ifdef CODEC_FLAG_H263P_AIC |
210 {"aic", &lavc_param_aic, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_H263P_AIC, NULL}, | |
211 {"umv", &lavc_param_umv, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_H263P_UMV, NULL}, | |
212 #endif | |
9645 | 213 #if LIBAVCODEC_BUILD >= 4663 |
214 {"ibias", &lavc_param_ibias, CONF_TYPE_INT, CONF_RANGE, -512, 512, NULL}, | |
215 {"pbias", &lavc_param_pbias, CONF_TYPE_INT, CONF_RANGE, -512, 512, NULL}, | |
216 #endif | |
10291 | 217 #if LIBAVCODEC_BUILD >= 4669 |
218 {"coder", &lavc_param_coder, CONF_TYPE_INT, CONF_RANGE, 0, 10, NULL}, | |
219 {"context", &lavc_param_context, CONF_TYPE_INT, CONF_RANGE, 0, 10, NULL}, | |
220 #endif | |
5550 | 221 {NULL, NULL, 0, 0, 0, 0, NULL} |
222 }; | |
223 #endif | |
224 | |
225 struct vf_priv_s { | |
8585 | 226 muxer_stream_t* mux; |
7444 | 227 AVCodecContext *context; |
8413 | 228 AVFrame *pic; |
5550 | 229 AVCodec *codec; |
7088 | 230 FILE *stats_file; |
5550 | 231 }; |
232 | |
7088 | 233 #define stats_file (vf->priv->stats_file) |
5550 | 234 #define mux_v (vf->priv->mux) |
235 #define lavc_venc_context (vf->priv->context) | |
236 | |
237 static int config(struct vf_instance_s* vf, | |
238 int width, int height, int d_width, int d_height, | |
239 unsigned int flags, unsigned int outfmt){ | |
7088 | 240 int size, i; |
241 void *p; | |
242 | |
5550 | 243 mux_v->bih->biWidth=width; |
244 mux_v->bih->biHeight=height; | |
245 mux_v->bih->biSizeImage=mux_v->bih->biWidth*mux_v->bih->biHeight*(mux_v->bih->biBitCount/8); | |
246 | |
247 printf("videocodec: libavcodec (%dx%d fourcc=%x [%.4s])\n", | |
248 mux_v->bih->biWidth, mux_v->bih->biHeight, mux_v->bih->biCompression, | |
249 (char *)&mux_v->bih->biCompression); | |
250 | |
7444 | 251 lavc_venc_context->width = width; |
252 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
|
253 if (lavc_param_vbitrate > 16000) /* != -1 */ |
7444 | 254 lavc_venc_context->bit_rate = lavc_param_vbitrate; |
5677
a21cab74cde8
bitrate>16000 means bits not kbits - noticed by George Hawkins <george_hawkins@yahoo.com>
arpi
parents:
5657
diff
changeset
|
255 else if (lavc_param_vbitrate >= 0) /* != -1 */ |
7444 | 256 lavc_venc_context->bit_rate = lavc_param_vbitrate*1000; |
5550 | 257 else |
7444 | 258 lavc_venc_context->bit_rate = 800000; /* default */ |
259 lavc_venc_context->bit_rate_tolerance= lavc_param_vrate_tolerance*1000; | |
9571 | 260 #if LIBAVCODEC_BUILD >= 4662 |
261 lavc_venc_context->frame_rate = mux_v->h.dwRate; | |
262 lavc_venc_context->frame_rate_base = mux_v->h.dwScale; | |
263 #else | |
264 lavc_venc_context->frame_rate = mux_v->h.dwRate*FRAME_RATE_BASE/mux_v->h.dwScale; | |
265 #endif | |
7444 | 266 lavc_venc_context->qmin= lavc_param_vqmin; |
267 lavc_venc_context->qmax= lavc_param_vqmax; | |
8492 | 268 #if LIBAVCODEC_BUILD >= 4646 |
269 lavc_venc_context->mb_qmin= lavc_param_mb_qmin; | |
270 lavc_venc_context->mb_qmax= lavc_param_mb_qmax; | |
271 #endif | |
7444 | 272 lavc_venc_context->max_qdiff= lavc_param_vqdiff; |
273 lavc_venc_context->qcompress= lavc_param_vqcompress; | |
274 lavc_venc_context->qblur= lavc_param_vqblur; | |
275 lavc_venc_context->max_b_frames= lavc_param_vmax_b_frames; | |
276 lavc_venc_context->b_quant_factor= lavc_param_vb_qfactor; | |
277 lavc_venc_context->rc_strategy= lavc_param_vrc_strategy; | |
278 lavc_venc_context->b_frame_strategy= lavc_param_vb_strategy; | |
279 lavc_venc_context->b_quant_offset= lavc_param_vb_qoffset; | |
280 lavc_venc_context->luma_elim_threshold= lavc_param_luma_elim_threshold; | |
281 lavc_venc_context->chroma_elim_threshold= lavc_param_chroma_elim_threshold; | |
282 lavc_venc_context->rtp_payload_size= lavc_param_packet_size; | |
283 if(lavc_param_packet_size )lavc_venc_context->rtp_mode=1; | |
284 lavc_venc_context->strict_std_compliance= lavc_param_strict; | |
285 lavc_venc_context->i_quant_factor= lavc_param_vi_qfactor; | |
286 lavc_venc_context->i_quant_offset= lavc_param_vi_qoffset; | |
287 lavc_venc_context->rc_qsquish= lavc_param_rc_qsquish; | |
288 lavc_venc_context->rc_qmod_amp= lavc_param_rc_qmod_amp; | |
289 lavc_venc_context->rc_qmod_freq= lavc_param_rc_qmod_freq; | |
290 lavc_venc_context->rc_eq= lavc_param_rc_eq; | |
291 lavc_venc_context->rc_max_rate= lavc_param_rc_max_rate*1000; | |
292 lavc_venc_context->rc_min_rate= lavc_param_rc_min_rate*1000; | |
293 lavc_venc_context->rc_buffer_size= lavc_param_rc_buffer_size*1000; | |
294 lavc_venc_context->rc_buffer_aggressivity= lavc_param_rc_buffer_aggressivity; | |
295 lavc_venc_context->rc_initial_cplx= lavc_param_rc_initial_cplx; | |
8341 | 296 #if LIBAVCODEC_BUILD >= 4642 |
297 lavc_venc_context->debug= lavc_param_debug; | |
298 #endif | |
8695 | 299 #if LIBAVCODEC_BUILD >= 4649 |
300 lavc_venc_context->last_predictor_count= lavc_param_last_pred; | |
301 #endif | |
8709 | 302 #if LIBAVCODEC_BUILD >= 4650 |
303 lavc_venc_context->pre_me= lavc_param_pre_me; | |
304 #endif | |
8803 | 305 #if LIBAVCODEC_BUILD >= 4651 |
306 lavc_venc_context->me_pre_cmp= lavc_param_me_pre_cmp; | |
307 lavc_venc_context->pre_dia_size= lavc_param_pre_dia_size; | |
308 #endif | |
309 #if LIBAVCODEC_BUILD >= 4652 | |
310 lavc_venc_context->me_subpel_quality= lavc_param_me_subpel_quality; | |
311 #endif | |
9508 | 312 #if LIBAVCODEC_BUILD >= 4659 |
313 lavc_venc_context->me_range= lavc_param_me_range; | |
314 #endif | |
9645 | 315 #if LIBAVCODEC_BUILD >= 4663 |
316 lavc_venc_context->intra_quant_bias= lavc_param_ibias; | |
317 lavc_venc_context->inter_quant_bias= lavc_param_pbias; | |
318 #endif | |
10291 | 319 #if LIBAVCODEC_BUILD >= 4669 |
320 lavc_venc_context->coder_type= lavc_param_coder; | |
321 lavc_venc_context->context_model= lavc_param_context; | |
322 #endif | |
9508 | 323 |
7088 | 324 p= lavc_param_rc_override_string; |
325 for(i=0; p; i++){ | |
326 int start, end, q; | |
327 int e=sscanf(p, "%d,%d,%d", &start, &end, &q); | |
328 if(e!=3){ | |
329 mp_msg(MSGT_MENCODER,MSGL_ERR,"error parsing vrc_q\n"); | |
330 return 0; | |
331 } | |
7444 | 332 lavc_venc_context->rc_override= |
333 realloc(lavc_venc_context->rc_override, sizeof(RcOverride)*(i+1)); | |
334 lavc_venc_context->rc_override[i].start_frame= start; | |
335 lavc_venc_context->rc_override[i].end_frame = end; | |
7088 | 336 if(q>0){ |
7444 | 337 lavc_venc_context->rc_override[i].qscale= q; |
338 lavc_venc_context->rc_override[i].quality_factor= 1.0; | |
7088 | 339 } |
340 else{ | |
7444 | 341 lavc_venc_context->rc_override[i].qscale= 0; |
342 lavc_venc_context->rc_override[i].quality_factor= -q/100.0; | |
7088 | 343 } |
344 p= strchr(p, '/'); | |
345 if(p) p++; | |
346 } | |
7444 | 347 lavc_venc_context->rc_override_count=i; |
7088 | 348 |
7444 | 349 lavc_venc_context->mpeg_quant=lavc_param_mpeg_quant; |
7152 | 350 |
7444 | 351 lavc_venc_context->dct_algo= lavc_param_fdct; |
7564 | 352 lavc_venc_context->idct_algo= lavc_param_idct; |
7152 | 353 |
7490 | 354 lavc_venc_context->lumi_masking= lavc_param_lumi_masking; |
355 lavc_venc_context->temporal_cplx_masking= lavc_param_temporal_cplx_masking; | |
356 lavc_venc_context->spatial_cplx_masking= lavc_param_spatial_cplx_masking; | |
357 lavc_venc_context->p_masking= lavc_param_p_masking; | |
7496 | 358 lavc_venc_context->dark_masking= lavc_param_dark_masking; |
7490 | 359 |
8237 | 360 if (lavc_param_aspect != NULL) |
7389
6f3dd9df2cc2
aspect ratio support by encoding (currently only with mpeg4 and h263p)
alex
parents:
7368
diff
changeset
|
361 { |
8237 | 362 int par_width, par_height, e; |
363 float ratio=0; | |
364 | |
365 e= sscanf (lavc_param_aspect, "%d/%d", &par_width, &par_height); | |
366 if(e==2){ | |
367 if(par_height) | |
368 ratio= (float)par_width / (float)par_height; | |
369 }else{ | |
370 e= sscanf (lavc_param_aspect, "%f", &ratio); | |
7389
6f3dd9df2cc2
aspect ratio support by encoding (currently only with mpeg4 and h263p)
alex
parents:
7368
diff
changeset
|
371 } |
8237 | 372 |
373 if (e && ratio > 0.1 && ratio < 10.0) { | |
374 lavc_venc_context->aspect_ratio= ratio; | |
375 mp_dbg(MSGT_MENCODER, MSGL_DBG2, "aspect_ratio: %f\n", ratio); | |
376 } else { | |
377 mp_dbg(MSGT_MENCODER, MSGL_ERR, "aspect ratio: cannot parse \"%s\"\n", lavc_param_aspect); | |
378 return 0; | |
7389
6f3dd9df2cc2
aspect ratio support by encoding (currently only with mpeg4 and h263p)
alex
parents:
7368
diff
changeset
|
379 } |
6f3dd9df2cc2
aspect ratio support by encoding (currently only with mpeg4 and h263p)
alex
parents:
7368
diff
changeset
|
380 } |
9993
6e7f3643bee6
optional automatic aspect encoding based on d_width and d_height
rfelker
parents:
9868
diff
changeset
|
381 else if (lavc_param_autoaspect) |
6e7f3643bee6
optional automatic aspect encoding based on d_width and d_height
rfelker
parents:
9868
diff
changeset
|
382 lavc_venc_context->aspect_ratio = (float)d_width/d_height; |
7389
6f3dd9df2cc2
aspect ratio support by encoding (currently only with mpeg4 and h263p)
alex
parents:
7368
diff
changeset
|
383 |
5550 | 384 /* keyframe interval */ |
385 if (lavc_param_keyint >= 0) /* != -1 */ | |
7444 | 386 lavc_venc_context->gop_size = lavc_param_keyint; |
5550 | 387 else |
7444 | 388 lavc_venc_context->gop_size = 250; /* default */ |
5550 | 389 |
10498 | 390 lavc_venc_context->flags = 0; |
391 if (lavc_param_mb_decision) | |
5550 | 392 { |
393 printf("High quality encoding selected (non real time)!\n"); | |
10498 | 394 #if LIBAVCODEC_BUILD < 4673 |
395 lavc_venc_context->flags = CODEC_FLAG_HQ; | |
396 #else | |
397 lavc_venc_context->mb_decision= lavc_param_mb_decision; | |
398 #endif | |
5550 | 399 } |
400 | |
8587 | 401 #if LIBAVCODEC_BUILD >= 4647 |
402 lavc_venc_context->me_cmp= lavc_param_me_cmp; | |
403 lavc_venc_context->me_sub_cmp= lavc_param_me_sub_cmp; | |
404 lavc_venc_context->mb_cmp= lavc_param_mb_cmp; | |
405 lavc_venc_context->dia_size= lavc_param_dia_size; | |
406 lavc_venc_context->flags|= lavc_param_qpel; | |
407 #endif | |
8684 | 408 #if LIBAVCODEC_BUILD >= 4648 |
409 lavc_venc_context->flags|= lavc_param_trell; | |
410 #endif | |
9536 | 411 lavc_venc_context->flags|= lavc_param_aic; |
412 lavc_venc_context->flags|= lavc_param_umv; | |
7444 | 413 lavc_venc_context->flags|= lavc_param_v4mv ? CODEC_FLAG_4MV : 0; |
414 lavc_venc_context->flags|= lavc_param_data_partitioning; | |
415 if(lavc_param_gray) lavc_venc_context->flags|= CODEC_FLAG_GRAY; | |
6461 | 416 |
7490 | 417 if(lavc_param_normalize_aqp) lavc_venc_context->flags|= CODEC_FLAG_NORMALIZE_AQP; |
7504 | 418 if(lavc_param_interlaced_dct) lavc_venc_context->flags|= CODEC_FLAG_INTERLACED_DCT; |
8347 | 419 #if LIBAVCODEC_BUILD >= 4643 |
420 lavc_venc_context->flags|= lavc_param_psnr; | |
421 #endif | |
8190 | 422 lavc_venc_context->prediction_method= lavc_param_prediction_method; |
423 if(!strcasecmp(lavc_param_format, "YV12")) | |
424 lavc_venc_context->pix_fmt= PIX_FMT_YUV420P; | |
425 else if(!strcasecmp(lavc_param_format, "422P")) | |
426 lavc_venc_context->pix_fmt= PIX_FMT_YUV422P; | |
10293 | 427 else if(!strcasecmp(lavc_param_format, "444P")) |
428 lavc_venc_context->pix_fmt= PIX_FMT_YUV444P; | |
429 else if(!strcasecmp(lavc_param_format, "411P")) | |
430 lavc_venc_context->pix_fmt= PIX_FMT_YUV411P; | |
431 else if(!strcasecmp(lavc_param_format, "YVU9")) | |
432 lavc_venc_context->pix_fmt= PIX_FMT_YUV410P; | |
10302 | 433 else if(!strcasecmp(lavc_param_format, "BGR32")) |
434 lavc_venc_context->pix_fmt= PIX_FMT_RGBA32; | |
8190 | 435 else{ |
436 mp_msg(MSGT_MENCODER,MSGL_ERR,"%s is not a supported format\n", lavc_param_format); | |
437 return 0; | |
438 } | |
10302 | 439 |
5778 | 440 /* lavc internal 2pass bitrate control */ |
6673 | 441 switch(lavc_param_vpass){ |
7088 | 442 case 1: |
7444 | 443 lavc_venc_context->flags|= CODEC_FLAG_PASS1; |
7088 | 444 stats_file= fopen(passtmpfile, "w"); |
445 if(stats_file==NULL){ | |
446 mp_msg(MSGT_MENCODER,MSGL_ERR,"2pass failed: filename=%s\n", passtmpfile); | |
447 return 0; | |
448 } | |
449 break; | |
450 case 2: | |
7444 | 451 lavc_venc_context->flags|= CODEC_FLAG_PASS2; |
7088 | 452 stats_file= fopen(passtmpfile, "r"); |
453 if(stats_file==NULL){ | |
454 mp_msg(MSGT_MENCODER,MSGL_ERR,"2pass failed: filename=%s\n", passtmpfile); | |
455 return 0; | |
456 } | |
457 fseek(stats_file, 0, SEEK_END); | |
458 size= ftell(stats_file); | |
459 fseek(stats_file, 0, SEEK_SET); | |
460 | |
7444 | 461 lavc_venc_context->stats_in= malloc(size + 1); |
462 lavc_venc_context->stats_in[size]=0; | |
7088 | 463 |
7444 | 464 if(fread(lavc_venc_context->stats_in, size, 1, stats_file)<1){ |
7088 | 465 mp_msg(MSGT_MENCODER,MSGL_ERR,"2pass failed: reading from filename=%s\n", passtmpfile); |
466 return 0; | |
7089 | 467 } |
7088 | 468 break; |
6673 | 469 } |
5778 | 470 |
7444 | 471 lavc_venc_context->me_method = ME_ZERO+lavc_param_vme; |
5550 | 472 |
473 /* fixed qscale :p */ | |
474 if (lavc_param_vqscale) | |
475 { | |
476 printf("Using constant qscale = %d (VBR)\n", lavc_param_vqscale); | |
7444 | 477 lavc_venc_context->flags |= CODEC_FLAG_QSCALE; |
10131 | 478 #if LIBAVCODEC_BUILD >= 4668 |
479 lavc_venc_context->global_quality= FF_QUALITY_SCALE * lavc_param_vqscale; | |
480 #endif | |
8339 | 481 vf->priv->pic->quality = lavc_param_vqscale; |
5550 | 482 } |
483 | |
7444 | 484 if (avcodec_open(lavc_venc_context, vf->priv->codec) != 0) { |
5550 | 485 mp_msg(MSGT_MENCODER,MSGL_ERR,MSGTR_CantOpenCodec); |
486 return 0; | |
487 } | |
488 | |
7444 | 489 if (lavc_venc_context->codec->encode == NULL) { |
5550 | 490 mp_msg(MSGT_MENCODER,MSGL_ERR,"avcodec init failed (ctx->codec->encode == NULL)!\n"); |
491 return 0; | |
492 } | |
7088 | 493 |
494 /* free second pass buffer, its not needed anymore */ | |
7444 | 495 if(lavc_venc_context->stats_in) free(lavc_venc_context->stats_in); |
496 lavc_venc_context->stats_in= NULL; | |
8190 | 497 if(lavc_venc_context->bits_per_sample) |
498 mux_v->bih->biBitCount= lavc_venc_context->bits_per_sample; | |
499 if(lavc_venc_context->extradata_size){ | |
500 memcpy(mux_v->bih + 1, lavc_venc_context->extradata, lavc_venc_context->extradata_size); | |
501 mux_v->bih->biSize= sizeof(BITMAPINFOHEADER) + lavc_venc_context->extradata_size; | |
502 } | |
7088 | 503 |
5550 | 504 return 1; |
505 } | |
506 | |
507 static int control(struct vf_instance_s* vf, int request, void* data){ | |
508 | |
509 return CONTROL_UNKNOWN; | |
510 } | |
511 | |
512 static int query_format(struct vf_instance_s* vf, unsigned int fmt){ | |
513 switch(fmt){ | |
514 case IMGFMT_YV12: | |
515 case IMGFMT_IYUV: | |
516 case IMGFMT_I420: | |
8190 | 517 if(!strcasecmp(lavc_param_format, "YV12")) |
518 return VFCAP_CSP_SUPPORTED | VFCAP_ACCEPT_STRIDE; | |
519 break; | |
10293 | 520 case IMGFMT_411P: |
521 if(!strcasecmp(lavc_param_format, "411P")) | |
522 return VFCAP_CSP_SUPPORTED | VFCAP_ACCEPT_STRIDE; | |
523 break; | |
8190 | 524 case IMGFMT_422P: |
525 if(!strcasecmp(lavc_param_format, "422P")) | |
526 return VFCAP_CSP_SUPPORTED | VFCAP_ACCEPT_STRIDE; | |
527 break; | |
10293 | 528 case IMGFMT_444P: |
529 if(!strcasecmp(lavc_param_format, "444P")) | |
530 return VFCAP_CSP_SUPPORTED | VFCAP_ACCEPT_STRIDE; | |
531 break; | |
532 case IMGFMT_YVU9: | |
533 if(!strcasecmp(lavc_param_format, "YVU9")) | |
534 return VFCAP_CSP_SUPPORTED | VFCAP_ACCEPT_STRIDE; | |
535 break; | |
10302 | 536 case IMGFMT_BGR32: |
537 if(!strcasecmp(lavc_param_format, "BGR32")) | |
538 return VFCAP_CSP_SUPPORTED | VFCAP_ACCEPT_STRIDE; | |
539 break; | |
5550 | 540 } |
541 return 0; | |
542 } | |
543 | |
8347 | 544 static double psnr(double d){ |
545 if(d==0) return INFINITY; | |
546 return -10.0*log(d)/log(10); | |
547 } | |
548 | |
7368 | 549 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){ |
8347 | 550 const char pict_type_char[5]= {'?', 'I', 'P', 'B', 'S'}; |
5550 | 551 int out_size; |
8413 | 552 AVFrame *pic= vf->priv->pic; |
5550 | 553 |
8339 | 554 pic->data[0]=mpi->planes[0]; |
555 pic->data[1]=mpi->planes[1]; | |
556 pic->data[2]=mpi->planes[2]; | |
557 pic->linesize[0]=mpi->stride[0]; | |
558 pic->linesize[1]=mpi->stride[1]; | |
559 pic->linesize[2]=mpi->stride[2]; | |
5550 | 560 |
7444 | 561 out_size = avcodec_encode_video(lavc_venc_context, mux_v->buffer, mux_v->buffer_size, |
8339 | 562 pic); |
5550 | 563 |
9536 | 564 |
9014
c671e9adbe22
Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents:
8803
diff
changeset
|
565 muxer_write_chunk(mux_v,out_size,lavc_venc_context->coded_frame->key_frame?0x10:0); |
8413 | 566 |
8347 | 567 #if LIBAVCODEC_BUILD >= 4643 |
568 /* store psnr / pict size / type / qscale */ | |
569 if(lavc_param_psnr){ | |
570 static FILE *fvstats=NULL; | |
571 char filename[20]; | |
572 static long long int all_len=0; | |
573 static int frame_number=0; | |
574 static double all_frametime=0.0; | |
8413 | 575 AVFrame *pic= lavc_venc_context->coded_frame; |
8347 | 576 double f= lavc_venc_context->width*lavc_venc_context->height*255.0*255.0; |
9865
30893b593947
Adaptive quantization support for "-lavcopts psnr" and "-lavdopts vstats".
rguyom
parents:
9645
diff
changeset
|
577 double quality=0.0; |
9868 | 578 int8_t *q; |
8347 | 579 |
580 if(!fvstats) { | |
581 time_t today2; | |
582 struct tm *today; | |
583 today2 = time(NULL); | |
584 today = localtime(&today2); | |
585 sprintf(filename, "psnr_%02d%02d%02d.log", today->tm_hour, | |
586 today->tm_min, today->tm_sec); | |
587 fvstats = fopen(filename,"w"); | |
588 if(!fvstats) { | |
589 perror("fopen"); | |
590 lavc_param_psnr=0; // disable block | |
591 /*exit(1);*/ | |
592 } | |
593 } | |
9865
30893b593947
Adaptive quantization support for "-lavcopts psnr" and "-lavdopts vstats".
rguyom
parents:
9645
diff
changeset
|
594 |
30893b593947
Adaptive quantization support for "-lavcopts psnr" and "-lavdopts vstats".
rguyom
parents:
9645
diff
changeset
|
595 // average MB quantizer |
9868 | 596 q = lavc_venc_context->coded_frame->qscale_table; |
597 if(q) { | |
9865
30893b593947
Adaptive quantization support for "-lavcopts psnr" and "-lavdopts vstats".
rguyom
parents:
9645
diff
changeset
|
598 int x, y; |
30893b593947
Adaptive quantization support for "-lavcopts psnr" and "-lavdopts vstats".
rguyom
parents:
9645
diff
changeset
|
599 int w = (lavc_venc_context->width+15) >> 4; |
30893b593947
Adaptive quantization support for "-lavcopts psnr" and "-lavdopts vstats".
rguyom
parents:
9645
diff
changeset
|
600 int h = (lavc_venc_context->height+15) >> 4; |
30893b593947
Adaptive quantization support for "-lavcopts psnr" and "-lavdopts vstats".
rguyom
parents:
9645
diff
changeset
|
601 for( y = 0; y < h; y++ ) { |
30893b593947
Adaptive quantization support for "-lavcopts psnr" and "-lavdopts vstats".
rguyom
parents:
9645
diff
changeset
|
602 for( x = 0; x < w; x++ ) |
30893b593947
Adaptive quantization support for "-lavcopts psnr" and "-lavdopts vstats".
rguyom
parents:
9645
diff
changeset
|
603 quality += (double)*(q+x); |
30893b593947
Adaptive quantization support for "-lavcopts psnr" and "-lavdopts vstats".
rguyom
parents:
9645
diff
changeset
|
604 q += lavc_venc_context->coded_frame->qstride; |
30893b593947
Adaptive quantization support for "-lavcopts psnr" and "-lavdopts vstats".
rguyom
parents:
9645
diff
changeset
|
605 } |
30893b593947
Adaptive quantization support for "-lavcopts psnr" and "-lavdopts vstats".
rguyom
parents:
9645
diff
changeset
|
606 quality /= w * h; |
9868 | 607 } else |
608 quality = lavc_venc_context->coded_frame->quality; | |
8347 | 609 |
610 fprintf(fvstats, "%6d, %2.2f, %6d, %2.2f, %2.2f, %2.2f, %2.2f %c\n", | |
8413 | 611 lavc_venc_context->coded_frame->coded_picture_number, |
9865
30893b593947
Adaptive quantization support for "-lavcopts psnr" and "-lavdopts vstats".
rguyom
parents:
9645
diff
changeset
|
612 quality, |
8347 | 613 out_size, |
8413 | 614 psnr(lavc_venc_context->coded_frame->error[0]/f), |
615 psnr(lavc_venc_context->coded_frame->error[1]*4/f), | |
616 psnr(lavc_venc_context->coded_frame->error[2]*4/f), | |
617 psnr((lavc_venc_context->coded_frame->error[0]+lavc_venc_context->coded_frame->error[1]+lavc_venc_context->coded_frame->error[2])/(f*1.5)), | |
618 pict_type_char[lavc_venc_context->coded_frame->pict_type] | |
8347 | 619 ); |
620 } | |
621 #endif | |
7088 | 622 /* store stats if there are any */ |
7444 | 623 if(lavc_venc_context->stats_out && stats_file) |
624 fprintf(stats_file, "%s", lavc_venc_context->stats_out); | |
7368 | 625 return 1; |
5550 | 626 } |
627 | |
5551 | 628 static void uninit(struct vf_instance_s* vf){ |
8347 | 629 const char pict_type_char[5]= {'?', 'I', 'P', 'B', 'S'}; |
630 | |
631 #if LIBAVCODEC_BUILD >= 4643 | |
632 if(lavc_param_psnr){ | |
633 double f= lavc_venc_context->width*lavc_venc_context->height*255.0*255.0; | |
8413 | 634 f*= lavc_venc_context->coded_frame->coded_picture_number; |
8347 | 635 |
636 printf("PSNR: Y:%2.2f, Cb:%2.2f, Cr:%2.2f, All:%2.2f\n", | |
637 psnr(lavc_venc_context->error[0]/f), | |
638 psnr(lavc_venc_context->error[1]*4/f), | |
639 psnr(lavc_venc_context->error[2]*4/f), | |
640 psnr((lavc_venc_context->error[0]+lavc_venc_context->error[1]+lavc_venc_context->error[2])/(f*1.5)) | |
641 ); | |
642 } | |
643 #endif | |
644 | |
7444 | 645 avcodec_close(lavc_venc_context); |
7088 | 646 |
647 if(stats_file) fclose(stats_file); | |
7089 | 648 |
7088 | 649 /* free rc_override */ |
7444 | 650 if(lavc_venc_context->rc_override) free(lavc_venc_context->rc_override); |
651 lavc_venc_context->rc_override= NULL; | |
652 | |
653 if(vf->priv->context) free(vf->priv->context); | |
654 vf->priv->context= NULL; | |
5551 | 655 } |
656 | |
5550 | 657 //===========================================================================// |
658 | |
659 static int vf_open(vf_instance_t *vf, char* args){ | |
5551 | 660 vf->uninit=uninit; |
5550 | 661 vf->config=config; |
662 vf->control=control; | |
663 vf->query_format=query_format; | |
664 vf->put_image=put_image; | |
665 vf->priv=malloc(sizeof(struct vf_priv_s)); | |
666 memset(vf->priv,0,sizeof(struct vf_priv_s)); | |
8585 | 667 vf->priv->mux=(muxer_stream_t*)args; |
5550 | 668 |
5977
e8f6f477aad0
a hack to make ffmjpeg created files viewable with windows dlls too
alex
parents:
5972
diff
changeset
|
669 /* 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
|
670 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
|
671 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
|
672 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
|
673 { |
e8f6f477aad0
a hack to make ffmjpeg created files viewable with windows dlls too
alex
parents:
5972
diff
changeset
|
674 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
|
675 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
|
676 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
|
677 } |
8190 | 678 else if (lavc_param_vcodec && !strcasecmp(lavc_param_vcodec, "huffyuv")) |
679 { | |
680 /* XXX: hack: huffyuv needs to store huffman tables (allthough we dunno the size yet ...) */ | |
681 mux_v->bih=malloc(sizeof(BITMAPINFOHEADER)+1000); | |
682 memset(mux_v->bih, 0, sizeof(BITMAPINFOHEADER)+1000); | |
683 mux_v->bih->biSize=sizeof(BITMAPINFOHEADER)+1000; | |
684 } | |
10131 | 685 else if (lavc_param_vcodec && !strcasecmp(lavc_param_vcodec, "asv1")) |
686 { | |
687 mux_v->bih=malloc(sizeof(BITMAPINFOHEADER)+8); | |
688 memset(mux_v->bih, 0, sizeof(BITMAPINFOHEADER)+8); | |
689 mux_v->bih->biSize=sizeof(BITMAPINFOHEADER)+8; | |
690 } | |
8587 | 691 else if (lavc_param_vcodec && !strcasecmp(lavc_param_vcodec, "wmv2")) |
692 { | |
693 mux_v->bih=malloc(sizeof(BITMAPINFOHEADER)+4); | |
694 memset(mux_v->bih, 0, sizeof(BITMAPINFOHEADER)+4); | |
695 mux_v->bih->biSize=sizeof(BITMAPINFOHEADER)+4; | |
696 } | |
5977
e8f6f477aad0
a hack to make ffmjpeg created files viewable with windows dlls too
alex
parents:
5972
diff
changeset
|
697 else |
e8f6f477aad0
a hack to make ffmjpeg created files viewable with windows dlls too
alex
parents:
5972
diff
changeset
|
698 { |
e8f6f477aad0
a hack to make ffmjpeg created files viewable with windows dlls too
alex
parents:
5972
diff
changeset
|
699 mux_v->bih=malloc(sizeof(BITMAPINFOHEADER)); |
e8f6f477aad0
a hack to make ffmjpeg created files viewable with windows dlls too
alex
parents:
5972
diff
changeset
|
700 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
|
701 mux_v->bih->biSize=sizeof(BITMAPINFOHEADER); |
e8f6f477aad0
a hack to make ffmjpeg created files viewable with windows dlls too
alex
parents:
5972
diff
changeset
|
702 } |
5550 | 703 mux_v->bih->biWidth=0; |
704 mux_v->bih->biHeight=0; | |
705 mux_v->bih->biPlanes=1; | |
706 mux_v->bih->biBitCount=24; | |
707 if (!lavc_param_vcodec) | |
708 { | |
5977
e8f6f477aad0
a hack to make ffmjpeg created files viewable with windows dlls too
alex
parents:
5972
diff
changeset
|
709 printf("No libavcodec codec specified! It's required!\n"); |
5550 | 710 return 0; |
711 } | |
712 | |
713 if (!strcasecmp(lavc_param_vcodec, "mpeg1") || !strcasecmp(lavc_param_vcodec, "mpeg1video")) | |
714 mux_v->bih->biCompression = mmioFOURCC('m', 'p', 'g', '1'); | |
715 else if (!strcasecmp(lavc_param_vcodec, "h263") || !strcasecmp(lavc_param_vcodec, "h263p")) | |
716 mux_v->bih->biCompression = mmioFOURCC('h', '2', '6', '3'); | |
717 else if (!strcasecmp(lavc_param_vcodec, "rv10")) | |
718 mux_v->bih->biCompression = mmioFOURCC('R', 'V', '1', '0'); | |
719 else if (!strcasecmp(lavc_param_vcodec, "mjpeg")) | |
720 mux_v->bih->biCompression = mmioFOURCC('M', 'J', 'P', 'G'); | |
10302 | 721 else if (!strcasecmp(lavc_param_vcodec, "ljpeg")) |
722 mux_v->bih->biCompression = mmioFOURCC('L', 'J', 'P', 'G'); | |
5550 | 723 else if (!strcasecmp(lavc_param_vcodec, "mpeg4")) |
724 mux_v->bih->biCompression = mmioFOURCC('D', 'I', 'V', 'X'); | |
725 else if (!strcasecmp(lavc_param_vcodec, "msmpeg4")) | |
726 mux_v->bih->biCompression = mmioFOURCC('d', 'i', 'v', '3'); | |
5972 | 727 else if (!strcasecmp(lavc_param_vcodec, "msmpeg4v2")) |
728 mux_v->bih->biCompression = mmioFOURCC('M', 'P', '4', '2'); | |
6461 | 729 else if (!strcasecmp(lavc_param_vcodec, "wmv1")) |
730 mux_v->bih->biCompression = mmioFOURCC('W', 'M', 'V', '1'); | |
8587 | 731 else if (!strcasecmp(lavc_param_vcodec, "wmv2")) |
732 mux_v->bih->biCompression = mmioFOURCC('W', 'M', 'V', '2'); | |
8190 | 733 else if (!strcasecmp(lavc_param_vcodec, "huffyuv")) |
734 mux_v->bih->biCompression = mmioFOURCC('H', 'F', 'Y', 'U'); | |
10131 | 735 else if (!strcasecmp(lavc_param_vcodec, "asv1")) |
736 mux_v->bih->biCompression = mmioFOURCC('A', 'S', 'V', '1'); | |
10264 | 737 else if (!strcasecmp(lavc_param_vcodec, "ffv1")) |
738 mux_v->bih->biCompression = mmioFOURCC('F', 'F', 'V', '1'); | |
5550 | 739 else |
740 mux_v->bih->biCompression = mmioFOURCC(lavc_param_vcodec[0], | |
741 lavc_param_vcodec[1], lavc_param_vcodec[2], lavc_param_vcodec[3]); /* FIXME!!! */ | |
742 | |
743 if (!avcodec_inited){ | |
744 avcodec_init(); | |
745 avcodec_register_all(); | |
746 avcodec_inited=1; | |
747 } | |
748 | |
749 vf->priv->codec = (AVCodec *)avcodec_find_encoder_by_name(lavc_param_vcodec); | |
750 if (!vf->priv->codec) { | |
751 mp_msg(MSGT_MENCODER,MSGL_ERR,MSGTR_MissingLAVCcodec, lavc_param_vcodec); | |
752 return 0; | |
753 } | |
754 | |
8413 | 755 #if LIBAVCODEC_BUILD >= 4645 |
756 vf->priv->pic = avcodec_alloc_frame(); | |
757 #else | |
8339 | 758 vf->priv->pic = avcodec_alloc_picture(); |
8413 | 759 #endif |
7444 | 760 vf->priv->context = avcodec_alloc_context(); |
761 | |
5550 | 762 return 1; |
763 } | |
764 | |
765 vf_info_t ve_info_lavc = { | |
766 "libavcodec encoder", | |
767 "lavc", | |
6673 | 768 "A'rpi, Alex, Michael", |
5550 | 769 "for internal use by mencoder", |
770 vf_open | |
771 }; | |
772 | |
773 //===========================================================================// | |
774 #endif |