Mercurial > mplayer.hg
annotate mencoder.c @ 4039:3949bfd612fd
I was missing it ...
author | jaf |
---|---|
date | Mon, 07 Jan 2002 20:13:20 +0000 |
parents | b28af7b58f4c |
children | 4435dc3b8bef |
rev | line source |
---|---|
3663
9092546e7765
made divx4 optional (also configure checking needed) and added avcodec_close
alex
parents:
3657
diff
changeset
|
1 |
3384 | 2 #define VCODEC_COPY 0 |
3361
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
3 #define VCODEC_FRAMENO 1 |
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
4 #define VCODEC_DIVX4 2 |
3480 | 5 #define VCODEC_RAW 3 |
3504
21fc87d76300
support for RGB/BGR modes (tested with raw and divx4)
alex
parents:
3480
diff
changeset
|
6 #define VCODEC_LIBAVCODEC 4 |
3361
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
7 |
3385 | 8 #define ACODEC_COPY 0 |
2583 | 9 #define ACODEC_PCM 1 |
10 #define ACODEC_VBRMP3 2 | |
2531 | 11 |
12 #include <stdio.h> | |
13 #include <stdlib.h> | |
14 #include <string.h> | |
15 #include <signal.h> | |
16 | |
2591 | 17 #include "config.h" |
2531 | 18 #include "mp_msg.h" |
2978 | 19 #include "version.h" |
2531 | 20 #include "help_mp.h" |
21 | |
2978 | 22 static char* banner_text= |
23 "\n\n" | |
24 "MEncoder " VERSION "(C) 2000-2001 Arpad Gereoffy (see DOCS!)\n" | |
25 "\n"; | |
26 | |
3323 | 27 #include "cpudetect.h" |
28 | |
2531 | 29 #include "codec-cfg.h" |
30 | |
31 #include "stream.h" | |
32 #include "demuxer.h" | |
33 #include "stheader.h" | |
34 | |
35 #include "aviwrite.h" | |
36 | |
2897 | 37 #ifdef USE_LIBVO2 |
38 #include "libvo2/libvo2.h" | |
39 #else | |
2531 | 40 #include "libvo/video_out.h" |
2897 | 41 #endif |
2531 | 42 |
2574 | 43 #include "dec_audio.h" |
44 #include "dec_video.h" | |
45 | |
3663
9092546e7765
made divx4 optional (also configure checking needed) and added avcodec_close
alex
parents:
3657
diff
changeset
|
46 #ifdef HAVE_DIVX4ENCORE |
2531 | 47 #include <encore2.h> |
2643 | 48 #include "divx4_vbr.h" |
3663
9092546e7765
made divx4 optional (also configure checking needed) and added avcodec_close
alex
parents:
3657
diff
changeset
|
49 #endif |
2531 | 50 |
3357 | 51 #ifdef HAVE_MP3LAME |
2591 | 52 #include <lame/lame.h> |
3357 | 53 #endif |
2583 | 54 |
3657
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
55 #ifdef USE_LIBAVCODEC |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
56 #ifdef USE_LIBAVCODEC_SO |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
57 #include <libffmpeg/avcodec.h> |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
58 #else |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
59 #include "libavcodec/avcodec.h" |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
60 #endif |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
61 static AVCodec *lavc_venc_codec=NULL; |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
62 static AVCodecContext lavc_venc_context; |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
63 static AVPicture lavc_venc_picture; |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
64 extern int avcodec_inited; |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
65 |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
66 char *lavc_param_vcodec = NULL; |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
67 int lavc_param_vbitrate = -1; |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
68 int lavc_param_vhq = 0; /* default is realtime encoding */ |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
69 int lavc_param_keyint = -1; |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
70 #endif |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
71 |
3521 | 72 #ifdef HAVE_LIBCSS |
73 #include "libmpdemux/dvdauth.h" | |
74 #endif | |
75 | |
3236 | 76 #include <inttypes.h> |
77 #include "../postproc/swscale.h" | |
78 | |
3385 | 79 #include "fastmemcpy.h" |
80 | |
2583 | 81 //-------------------------- |
82 | |
2531 | 83 // cache2: |
2618 | 84 static int stream_cache_size=0; |
2531 | 85 #ifdef USE_STREAM_CACHE |
86 extern int cache_fill_status; | |
87 #else | |
88 #define cache_fill_status 0 | |
89 #endif | |
90 | |
2618 | 91 int vcd_track=0; |
92 int audio_id=-1; | |
93 int video_id=-1; | |
94 int dvdsub_id=-1; | |
95 | |
2531 | 96 char *audio_codec=NULL; // override audio codec |
97 char *video_codec=NULL; // override video codec | |
98 int audio_family=-1; // override audio codec family | |
99 int video_family=-1; // override video codec family | |
100 | |
3357 | 101 #ifdef HAVE_MP3LAME |
2661 | 102 int out_audio_codec=ACODEC_VBRMP3; |
3357 | 103 #else |
104 int out_audio_codec=ACODEC_PCM; | |
105 #endif | |
106 | |
2661 | 107 int out_video_codec=VCODEC_DIVX4; |
108 | |
2531 | 109 // audio stream skip/resync functions requires only for seeking. |
110 // (they should be implemented in the audio codec layer) | |
111 //void skip_audio_frame(sh_audio_t *sh_audio){} | |
112 //void resync_audio_stream(sh_audio_t *sh_audio){} | |
113 | |
2618 | 114 int verbose=0; // must be global! |
2531 | 115 |
116 double video_time_usage=0; | |
117 double vout_time_usage=0; | |
118 static double audio_time_usage=0; | |
119 static int total_time_usage_start=0; | |
120 static int benchmark=0; | |
121 | |
2605 | 122 // A-V sync: |
123 int delay_corrected=1; | |
124 static float default_max_pts_correction=-1;//0.01f; | |
125 static float max_pts_correction=0;//default_max_pts_correction; | |
126 static float c_total=0; | |
127 | |
2613 | 128 float force_fps=0; |
129 float force_ofps=0; // set to 24 for inverse telecine | |
2531 | 130 |
2618 | 131 int force_srate=0; |
132 | |
2626 | 133 char* out_filename="test.avi"; |
134 char* mp3_filename=NULL; | |
135 char* ac3_filename=NULL; | |
136 | |
3657
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
137 char *force_fourcc=NULL; |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
138 |
3663
9092546e7765
made divx4 optional (also configure checking needed) and added avcodec_close
alex
parents:
3657
diff
changeset
|
139 #ifdef HAVE_DIVX4ENCORE |
2643 | 140 static int pass=0; |
141 static char* passtmpfile="divx2pass.log"; | |
3377
4723f6fd750a
do not fault if 2pass VbrControl can't open the logfile
alex
parents:
3363
diff
changeset
|
142 int pass_working=0; |
3663
9092546e7765
made divx4 optional (also configure checking needed) and added avcodec_close
alex
parents:
3657
diff
changeset
|
143 #endif |
2643 | 144 |
145 static int play_n_frames=-1; | |
146 | |
2661 | 147 //char *out_audio_codec=NULL; // override audio codec |
148 //char *out_video_codec=NULL; // override video codec | |
2626 | 149 |
2591 | 150 //#include "libmpeg2/mpeg2.h" |
151 //#include "libmpeg2/mpeg2_internal.h" | |
152 | |
3663
9092546e7765
made divx4 optional (also configure checking needed) and added avcodec_close
alex
parents:
3657
diff
changeset
|
153 #ifdef HAVE_DIVX4ENCORE |
2626 | 154 ENC_PARAM divx4_param; |
2643 | 155 int divx4_crispness=100; |
3663
9092546e7765
made divx4 optional (also configure checking needed) and added avcodec_close
alex
parents:
3657
diff
changeset
|
156 #endif |
2626 | 157 |
3357 | 158 #ifdef HAVE_MP3LAME |
2626 | 159 int lame_param_quality=0; // best |
160 int lame_param_vbr=vbr_default; | |
161 int lame_param_mode=-1; // unset | |
162 int lame_param_padding=-1; // unset | |
163 int lame_param_br=-1; // unset | |
164 int lame_param_ratio=-1; // unset | |
3357 | 165 #endif |
2626 | 166 |
3236 | 167 static int scale_srcW=0; |
168 static int scale_srcH=0; | |
169 static int vo_w=0, vo_h=0; | |
2618 | 170 //-------------------------- config stuff: |
171 | |
172 #include "cfgparser.h" | |
173 | |
174 static int cfg_inc_verbose(struct config *conf){ ++verbose; return 0;} | |
175 | |
176 static int cfg_include(struct config *conf, char *filename){ | |
177 return parse_config_file(conf, filename); | |
178 } | |
179 | |
180 #include "get_path.c" | |
181 | |
182 #include "cfg-mplayer-def.h" | |
183 #include "cfg-mencoder.h" | |
184 | |
2591 | 185 //--------------------------------------------------------------------------- |
186 | |
2627 | 187 // dummy datas for gui :( |
188 | |
189 #ifdef HAVE_NEW_GUI | |
190 float rel_seek_secs=0; | |
191 int abs_seek_pos=0; | |
192 int use_gui=0; | |
193 | |
194 void exit_player(char* how){ | |
195 } | |
196 void vo_x11_putkey(int key){ | |
197 } | |
198 void vo_setwindow( int w,int g ) { | |
199 } | |
200 void vo_setwindowsize( int w,int h ) { | |
201 } | |
202 | |
203 int vo_resize = 0; | |
204 int vo_expose = 0; | |
205 | |
206 #endif | |
207 // --- | |
208 | |
2591 | 209 // mini dummy libvo: |
2531 | 210 |
211 static unsigned char* vo_image=NULL; | |
212 static unsigned char* vo_image_ptr=NULL; | |
213 | |
214 static uint32_t draw_slice(uint8_t *src[], int stride[], int w,int h, int x0,int y0){ | |
215 int y; | |
3236 | 216 // printf("draw_slice %dx%d %d;%d\n",w,h,x0,y0); |
217 if(scale_srcW) | |
218 { | |
219 uint8_t* dstPtr[3]= { | |
220 vo_image, | |
221 vo_image + vo_w*vo_h*5/4, | |
222 vo_image + vo_w*vo_h}; | |
223 SwScale_YV12slice(src, stride, y0, h, dstPtr, vo_w, 12, scale_srcW, scale_srcH, vo_w, vo_h); | |
224 } | |
225 else | |
226 { | |
2531 | 227 // copy Y: |
228 for(y=0;y<h;y++){ | |
2639 | 229 unsigned char* s=src[0]+stride[0]*y; |
2531 | 230 unsigned char* d=vo_image+vo_w*(y0+y)+x0; |
231 memcpy(d,s,w); | |
232 } | |
233 x0>>=1;y0>>=1; | |
234 w>>=1;h>>=1; | |
235 // copy U: | |
236 for(y=0;y<h;y++){ | |
2639 | 237 unsigned char* s=src[2]+stride[2]*y; |
2531 | 238 unsigned char* d=vo_image+vo_w*vo_h+(vo_w>>1)*(y0+y)+x0; |
239 memcpy(d,s,w); | |
240 } | |
241 // copy V: | |
242 for(y=0;y<h;y++){ | |
2639 | 243 unsigned char* s=src[1]+stride[1]*y; |
2531 | 244 unsigned char* d=vo_image+vo_w*vo_h+vo_w*vo_h/4+(vo_w>>1)*(y0+y)+x0; |
245 memcpy(d,s,w); | |
246 } | |
3236 | 247 } // !swscaler |
2531 | 248 } |
249 | |
250 static uint32_t draw_frame(uint8_t *src[]){ | |
251 // printf("This function shouldn't be called - report bug!\n"); | |
252 // later: add YUY2->YV12 conversion here! | |
253 vo_image_ptr=src[0]; | |
254 } | |
255 | |
256 vo_functions_t video_out; | |
257 | |
2591 | 258 //--------------------------------------------------------------------------- |
259 | |
260 int dec_audio(sh_audio_t *sh_audio,unsigned char* buffer,int total){ | |
261 int size=0; | |
262 int eof=0; | |
263 while(size<total && !eof){ | |
264 int len=total-size; | |
265 if(len>MAX_OUTBURST) len=MAX_OUTBURST; | |
266 if(len>sh_audio->a_buffer_size) len=sh_audio->a_buffer_size; | |
267 if(len>sh_audio->a_buffer_len){ | |
268 int ret=decode_audio(sh_audio, | |
269 &sh_audio->a_buffer[sh_audio->a_buffer_len], | |
270 len-sh_audio->a_buffer_len, | |
271 sh_audio->a_buffer_size-sh_audio->a_buffer_len); | |
272 if(ret>0) sh_audio->a_buffer_len+=ret; else eof=1; | |
273 } | |
274 if(len>sh_audio->a_buffer_len) len=sh_audio->a_buffer_len; | |
275 memcpy(buffer+size,sh_audio->a_buffer,len); | |
276 sh_audio->a_buffer_len-=len; size+=len; | |
277 if(sh_audio->a_buffer_len>0) | |
278 memcpy(sh_audio->a_buffer,&sh_audio->a_buffer[len],sh_audio->a_buffer_len); | |
279 } | |
280 return size; | |
281 } | |
282 | |
283 //--------------------------------------------------------------------------- | |
2531 | 284 |
285 static int eof=0; | |
3320
ac8b70dd5e45
use return 1; if interrupted - patch by Artur Skawina <skawina@geocities.com>
arpi
parents:
3240
diff
changeset
|
286 static int interrupted=0; |
2531 | 287 |
288 static void exit_sighandler(int x){ | |
289 eof=1; | |
3320
ac8b70dd5e45
use return 1; if interrupted - patch by Artur Skawina <skawina@geocities.com>
arpi
parents:
3240
diff
changeset
|
290 interrupted=1; |
2531 | 291 } |
292 | |
2618 | 293 int main(int argc,char* argv[], char *envp[]){ |
2531 | 294 |
295 stream_t* stream=NULL; | |
296 demuxer_t* demuxer=NULL; | |
297 demux_stream_t *d_audio=NULL; | |
298 demux_stream_t *d_video=NULL; | |
299 demux_stream_t *d_dvdsub=NULL; | |
300 sh_audio_t *sh_audio=NULL; | |
301 sh_video_t *sh_video=NULL; | |
302 int file_format=DEMUXER_TYPE_UNKNOWN; | |
303 int i; | |
304 unsigned int out_fmt; | |
305 | |
306 aviwrite_t* muxer=NULL; | |
307 aviwrite_stream_t* mux_a=NULL; | |
308 aviwrite_stream_t* mux_v=NULL; | |
309 FILE* muxer_f=NULL; | |
310 | |
3663
9092546e7765
made divx4 optional (also configure checking needed) and added avcodec_close
alex
parents:
3657
diff
changeset
|
311 #ifdef HAVE_DIVX4ENCORE |
2531 | 312 ENC_FRAME enc_frame; |
313 ENC_RESULT enc_result; | |
314 void* enc_handle=NULL; | |
3663
9092546e7765
made divx4 optional (also configure checking needed) and added avcodec_close
alex
parents:
3657
diff
changeset
|
315 #endif |
2531 | 316 |
3357 | 317 #ifdef HAVE_MP3LAME |
2591 | 318 lame_global_flags *lame; |
3357 | 319 #endif |
2583 | 320 |
2653 | 321 float audio_preload=0.5; |
2581 | 322 |
2613 | 323 double v_pts_corr=0; |
324 double v_timer_corr=0; | |
2605 | 325 |
2618 | 326 char** filenames=NULL; |
327 char* filename=NULL; | |
328 int num_filenames; | |
329 | |
3361
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
330 int decoded_frameno=0; |
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
331 |
2531 | 332 //int out_buffer_size=0x200000; |
333 //unsigned char* out_buffer=malloc(out_buffer_size); | |
334 | |
2622 | 335 mp_msg_init(MSGL_STATUS); |
2978 | 336 mp_msg(MSGT_CPLAYER,MSGL_INFO,"%s",banner_text); |
2622 | 337 |
338 // check codec.conf | |
339 if(!parse_codec_cfg(get_path("codecs.conf"))){ | |
3748 | 340 if(!parse_codec_cfg(CONFDIR"/codecs.conf")){ |
2622 | 341 mp_msg(MSGT_MENCODER,MSGL_HINT,MSGTR_CopyCodecsConf); |
342 exit(0); | |
343 } | |
344 } | |
2531 | 345 |
3323 | 346 /* Test for cpu capabilities (and corresponding OS support) for optimizing */ |
347 #ifdef ARCH_X86 | |
348 GetCpuCaps(&gCpuCaps); | |
349 mp_msg(MSGT_CPLAYER,MSGL_INFO,"CPUflags: Type: %d MMX: %d MMX2: %d 3DNow: %d 3DNow2: %d SSE: %d SSE2: %d\n", | |
350 gCpuCaps.cpuType,gCpuCaps.hasMMX,gCpuCaps.hasMMX2, | |
351 gCpuCaps.has3DNow, gCpuCaps.has3DNowExt, | |
352 gCpuCaps.hasSSE, gCpuCaps.hasSSE2); | |
353 #endif | |
354 | |
3663
9092546e7765
made divx4 optional (also configure checking needed) and added avcodec_close
alex
parents:
3657
diff
changeset
|
355 #ifdef HAVE_DIVX4ENCORE |
2643 | 356 // set some defaults, before parsing configfile/commandline: |
357 divx4_param.min_quantizer = 2; | |
358 divx4_param.max_quantizer = 31; | |
359 divx4_param.rc_period = 2000; | |
360 divx4_param.rc_reaction_period = 10; | |
361 divx4_param.rc_reaction_ratio = 20; | |
3663
9092546e7765
made divx4 optional (also configure checking needed) and added avcodec_close
alex
parents:
3657
diff
changeset
|
362 #endif |
2643 | 363 |
2618 | 364 num_filenames=parse_command_line(conf, argc, argv, envp, &filenames); |
365 if(num_filenames<0) exit(1); // error parsing cmdline | |
3378 | 366 if(!num_filenames && !vcd_track && !dvd_title && !tv_param_on){ |
2618 | 367 printf("\nMissing filename!\n\n"); |
368 exit(1); | |
369 } | |
370 | |
2622 | 371 mp_msg_init(verbose+MSGL_STATUS); |
2600 | 372 |
2618 | 373 filename=(num_filenames>0)?filenames[0]:NULL; |
374 stream=open_stream(filename,vcd_track,&file_format); | |
2531 | 375 |
376 if(!stream){ | |
377 printf("Cannot open file/device\n"); | |
378 exit(1); | |
379 } | |
380 | |
381 printf("success: format: %d data: 0x%X - 0x%X\n",file_format, (int)(stream->start_pos),(int)(stream->end_pos)); | |
382 | |
3563 | 383 if(stream_cache_size) stream_enable_cache(stream,stream_cache_size*1024,0,0); |
2531 | 384 |
3979 | 385 #ifdef HAVE_LIBCSS |
386 // current_module="libcss"; | |
387 if (dvdimportkey) { | |
388 if (dvd_import_key(dvdimportkey)) { | |
389 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_ErrorDVDkey); | |
390 exit(1); | |
391 } | |
392 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CmdlineDVDkey); | |
393 } | |
394 if (dvd_auth_device) { | |
395 // if (dvd_auth(dvd_auth_device,f)) { | |
396 if (dvd_auth(dvd_auth_device,filename)) { | |
397 mp_msg(MSGT_CPLAYER,MSGL_FATAL,"Error in DVD auth...\n"); | |
398 exit(1); | |
399 } | |
400 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_DVDauthOk); | |
401 } | |
402 #endif | |
403 | |
2882 | 404 //demuxer=demux_open(stream,file_format,video_id,audio_id,dvdsub_id); |
405 demuxer=demux_open(stream,file_format,audio_id,video_id,dvdsub_id); | |
2531 | 406 if(!demuxer){ |
407 printf("Cannot open demuxer\n"); | |
408 exit(1); | |
409 } | |
410 | |
411 d_audio=demuxer->audio; | |
412 d_video=demuxer->video; | |
413 d_dvdsub=demuxer->sub; | |
414 sh_audio=d_audio->sh; | |
415 sh_video=d_video->sh; | |
416 | |
417 if(!video_read_properties(sh_video)){ | |
418 printf("Couldn't read video properties\n"); | |
419 exit(1); | |
420 } | |
421 | |
2622 | 422 mp_msg(MSGT_MENCODER,MSGL_INFO,"[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.2f ftime:=%6.4f\n", |
2531 | 423 demuxer->file_format,sh_video->format, sh_video->disp_w,sh_video->disp_h, |
424 sh_video->fps,sh_video->frametime | |
425 ); | |
426 | |
427 | |
428 sh_video->codec=NULL; | |
3361
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
429 if(out_video_codec>1){ |
2884 | 430 |
2622 | 431 if(video_family!=-1) mp_msg(MSGT_MENCODER,MSGL_INFO,MSGTR_TryForceVideoFmt,video_family); |
3712 | 432 { /* local vars */ |
3667
ec943f8ec439
add support for priotity <int> in codecs.conf, higher numbers are better
atmos4
parents:
3663
diff
changeset
|
433 short bestprio=-1; |
ec943f8ec439
add support for priotity <int> in codecs.conf, higher numbers are better
atmos4
parents:
3663
diff
changeset
|
434 struct codecs_st *bestcodec=NULL; |
2531 | 435 while(1){ |
436 sh_video->codec=find_codec(sh_video->format, | |
437 sh_video->bih?((unsigned int*) &sh_video->bih->biCompression):NULL,sh_video->codec,0); | |
438 if(!sh_video->codec){ | |
439 if(video_family!=-1) { | |
3712 | 440 //sh_video->codec=NULL; /* re-search */ |
2622 | 441 mp_msg(MSGT_MENCODER,MSGL_WARN,MSGTR_CantFindVfmtFallback); |
2531 | 442 video_family=-1; |
443 continue; | |
444 } | |
3712 | 445 if(bestprio==-1 || !video_codec) { |
446 mp_msg(MSGT_MENCODER,MSGL_ERR,MSGTR_CantFindVideoCodec,sh_video->format); | |
447 mp_msg(MSGT_MENCODER,MSGL_HINT, MSGTR_TryUpgradeCodecsConfOrRTFM,get_path("codecs.conf")); | |
448 exit(1); | |
449 } | |
450 } else { | |
451 if(video_codec && strcmp(sh_video->codec->name,video_codec)) continue; | |
452 else if(video_family!=-1 && sh_video->codec->driver!=video_family) continue; | |
453 else if(video_family==-1 && !video_codec && sh_video->codec->priority) { | |
454 if(sh_video->codec->priority > bestprio) { | |
455 //printf("\n\n!!! setting bestprio from %d to %d for %s!!!\n\n", bestprio, sh_video->codec->priority, sh_video->codec->name); | |
456 bestprio=sh_video->codec->priority; | |
457 bestcodec=sh_video->codec; | |
458 } | |
459 continue; | |
460 } | |
461 } /* sh_video->codec */ | |
2531 | 462 break; |
463 } | |
3667
ec943f8ec439
add support for priotity <int> in codecs.conf, higher numbers are better
atmos4
parents:
3663
diff
changeset
|
464 if(bestprio!=-1) { |
ec943f8ec439
add support for priotity <int> in codecs.conf, higher numbers are better
atmos4
parents:
3663
diff
changeset
|
465 //printf("chose codec %s by priority.\n", bestcodec->name); |
ec943f8ec439
add support for priotity <int> in codecs.conf, higher numbers are better
atmos4
parents:
3663
diff
changeset
|
466 sh_video->codec=bestcodec; |
ec943f8ec439
add support for priotity <int> in codecs.conf, higher numbers are better
atmos4
parents:
3663
diff
changeset
|
467 } |
2531 | 468 |
3712 | 469 } /* end local vars */ |
3667
ec943f8ec439
add support for priotity <int> in codecs.conf, higher numbers are better
atmos4
parents:
3663
diff
changeset
|
470 |
ec943f8ec439
add support for priotity <int> in codecs.conf, higher numbers are better
atmos4
parents:
3663
diff
changeset
|
471 mp_msg(MSGT_MENCODER,MSGL_INFO,"%s video codec: [%s] drv:%d prio:%d (%s)\n",video_codec?"Forcing":"Detected",sh_video->codec->name,sh_video->codec->driver,sh_video->codec->priority!=-1?sh_video->codec->priority:0,sh_video->codec->info); |
2531 | 472 |
473 for(i=0;i<CODECS_MAX_OUTFMT;i++){ | |
474 out_fmt=sh_video->codec->outfmt[i]; | |
475 if(out_fmt==0xFFFFFFFF) continue; | |
3504
21fc87d76300
support for RGB/BGR modes (tested with raw and divx4)
alex
parents:
3480
diff
changeset
|
476 if(IMGFMT_IS_RGB(out_fmt) || IMGFMT_IS_BGR(out_fmt)) break; |
2531 | 477 if(out_fmt==IMGFMT_YV12) break; |
478 if(out_fmt==IMGFMT_I420) break; | |
479 if(out_fmt==IMGFMT_IYUV) break; | |
480 if(out_fmt==IMGFMT_YUY2) break; | |
2825 | 481 if(out_fmt==IMGFMT_UYVY) break; |
2531 | 482 } |
483 if(i>=CODECS_MAX_OUTFMT){ | |
2622 | 484 mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_VOincompCodec); |
2531 | 485 exit(1); // exit_player(MSGTR_Exit_error); |
486 } | |
487 sh_video->outfmtidx=i; | |
488 | |
3240 | 489 if(out_fmt==IMGFMT_YV12 && (vo_w!=0 || vo_h!=0)) |
3236 | 490 { |
491 scale_srcW= sh_video->disp_w; | |
492 scale_srcH= sh_video->disp_h; | |
3240 | 493 if(!vo_w) vo_w=sh_video->disp_w; |
494 if(!vo_h) vo_h=sh_video->disp_h; | |
3236 | 495 } |
496 else | |
497 { | |
498 vo_w=sh_video->disp_w; | |
499 vo_h=sh_video->disp_h; | |
500 } | |
501 | |
2531 | 502 if(out_fmt==IMGFMT_YV12 || out_fmt==IMGFMT_I420 || out_fmt==IMGFMT_IYUV){ |
503 vo_image=malloc(vo_w*vo_h*3/2); | |
504 vo_image_ptr=vo_image; | |
505 } | |
506 | |
3504
21fc87d76300
support for RGB/BGR modes (tested with raw and divx4)
alex
parents:
3480
diff
changeset
|
507 if (IMGFMT_IS_BGR(out_fmt)) |
21fc87d76300
support for RGB/BGR modes (tested with raw and divx4)
alex
parents:
3480
diff
changeset
|
508 vo_image_ptr = vo_image = malloc(vo_w*vo_h*IMGFMT_BGR_DEPTH(out_fmt)/8); |
21fc87d76300
support for RGB/BGR modes (tested with raw and divx4)
alex
parents:
3480
diff
changeset
|
509 |
21fc87d76300
support for RGB/BGR modes (tested with raw and divx4)
alex
parents:
3480
diff
changeset
|
510 if (IMGFMT_IS_RGB(out_fmt)) |
21fc87d76300
support for RGB/BGR modes (tested with raw and divx4)
alex
parents:
3480
diff
changeset
|
511 vo_image_ptr = vo_image = malloc(vo_w*vo_h*IMGFMT_RGB_DEPTH(out_fmt)/8); |
21fc87d76300
support for RGB/BGR modes (tested with raw and divx4)
alex
parents:
3480
diff
changeset
|
512 |
2531 | 513 if(!init_video(sh_video)){ |
2622 | 514 mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_CouldntInitVideoCodec); |
2531 | 515 exit(1); |
516 } | |
517 | |
2884 | 518 } // if(out_video_codec) |
2581 | 519 |
520 if(sh_audio){ | |
521 // Go through the codec.conf and find the best codec... | |
522 sh_audio->codec=NULL; | |
2622 | 523 if(audio_family!=-1) mp_msg(MSGT_MENCODER,MSGL_INFO,MSGTR_TryForceAudioFmt,audio_family); |
2581 | 524 while(1){ |
525 sh_audio->codec=find_codec(sh_audio->format,NULL,sh_audio->codec,1); | |
526 if(!sh_audio->codec){ | |
527 if(audio_family!=-1) { | |
528 sh_audio->codec=NULL; /* re-search */ | |
2622 | 529 mp_msg(MSGT_MENCODER,MSGL_ERR,MSGTR_CantFindAfmtFallback); |
2581 | 530 audio_family=-1; |
531 continue; | |
532 } | |
2622 | 533 mp_msg(MSGT_MENCODER,MSGL_ERR,MSGTR_CantFindAudioCodec,sh_audio->format); |
534 mp_msg(MSGT_MENCODER,MSGL_HINT, MSGTR_TryUpgradeCodecsConfOrRTFM,get_path("codecs.conf")); | |
2581 | 535 sh_audio=d_audio->sh=NULL; |
536 break; | |
537 } | |
538 if(audio_codec && strcmp(sh_audio->codec->name,audio_codec)) continue; | |
539 else if(audio_family!=-1 && sh_audio->codec->driver!=audio_family) continue; | |
2622 | 540 mp_msg(MSGT_MENCODER,MSGL_INFO,"%s audio codec: [%s] drv:%d (%s)\n",audio_codec?"Forcing":"Detected",sh_audio->codec->name,sh_audio->codec->driver,sh_audio->codec->info); |
2581 | 541 break; |
542 } | |
543 } | |
544 | |
545 if(sh_audio){ | |
2622 | 546 mp_msg(MSGT_MENCODER,MSGL_V,"Initializing audio codec...\n"); |
2581 | 547 if(!init_audio(sh_audio)){ |
2622 | 548 mp_msg(MSGT_MENCODER,MSGL_ERR,MSGTR_CouldntInitAudioCodec); |
2581 | 549 sh_audio=d_audio->sh=NULL; |
550 } else { | |
2622 | 551 mp_msg(MSGT_MENCODER,MSGL_INFO,"AUDIO: srate=%d chans=%d bps=%d sfmt=0x%X ratio: %d->%d\n",sh_audio->samplerate,sh_audio->channels,sh_audio->samplesize, |
2581 | 552 sh_audio->sample_format,sh_audio->i_bps,sh_audio->o_bps); |
553 } | |
554 } | |
555 | |
556 | |
557 | |
2531 | 558 // set up video encoder: |
3236 | 559 SwScale_Init(); |
2531 | 560 video_out.draw_slice=draw_slice; |
561 video_out.draw_frame=draw_frame; | |
562 | |
563 // set up output file: | |
2626 | 564 muxer_f=fopen(out_filename,"wb"); |
2887
bc648c6a464a
fixes a segfault if file specified in -o can't be accessed
pl
parents:
2884
diff
changeset
|
565 if(!muxer_f) { |
bc648c6a464a
fixes a segfault if file specified in -o can't be accessed
pl
parents:
2884
diff
changeset
|
566 printf("Cannot open output file '%s'\n", out_filename); |
bc648c6a464a
fixes a segfault if file specified in -o can't be accessed
pl
parents:
2884
diff
changeset
|
567 exit(1); |
bc648c6a464a
fixes a segfault if file specified in -o can't be accessed
pl
parents:
2884
diff
changeset
|
568 } |
bc648c6a464a
fixes a segfault if file specified in -o can't be accessed
pl
parents:
2884
diff
changeset
|
569 |
2531 | 570 muxer=aviwrite_new_muxer(); |
2581 | 571 |
572 // ============= VIDEO =============== | |
573 | |
2531 | 574 mux_v=aviwrite_new_stream(muxer,AVIWRITE_TYPE_VIDEO); |
575 | |
576 mux_v->buffer_size=0x200000; | |
577 mux_v->buffer=malloc(mux_v->buffer_size); | |
578 | |
579 mux_v->source=sh_video; | |
580 | |
581 mux_v->h.dwSampleSize=0; // VBR | |
582 mux_v->h.dwScale=10000; | |
2613 | 583 mux_v->h.dwRate=mux_v->h.dwScale*(force_ofps?force_ofps:sh_video->fps); |
2531 | 584 |
2661 | 585 mux_v->codec=out_video_codec; |
2574 | 586 |
2531 | 587 switch(mux_v->codec){ |
3384 | 588 case VCODEC_COPY: |
589 printf("sh_video->bih: %x\n", sh_video->bih); | |
590 if (sh_video->bih) | |
591 mux_v->bih=sh_video->bih; | |
592 else | |
593 { | |
594 mux_v->bih=malloc(sizeof(BITMAPINFOHEADER)); | |
595 mux_v->bih->biSize=sizeof(BITMAPINFOHEADER); | |
596 mux_v->bih->biWidth=sh_video->disp_w; | |
597 mux_v->bih->biHeight=sh_video->disp_h; | |
598 mux_v->bih->biCompression=sh_video->format; | |
599 mux_v->bih->biPlanes=1; | |
600 mux_v->bih->biBitCount=24; // FIXME!!! | |
601 mux_v->bih->biSizeImage=mux_v->bih->biWidth*mux_v->bih->biHeight*(mux_v->bih->biBitCount/8); | |
602 } | |
603 printf("videocodec: framecopy (%dx%d %dbpp fourcc=%x)\n", | |
604 mux_v->bih->biWidth, mux_v->bih->biHeight, | |
605 mux_v->bih->biBitCount, mux_v->bih->biCompression); | |
2531 | 606 break; |
3480 | 607 case VCODEC_RAW: |
608 printf("sh_video->bih: %x\n", sh_video->bih); | |
609 if (sh_video->bih) | |
610 mux_v->bih=sh_video->bih; | |
611 else | |
612 { | |
613 mux_v->bih=malloc(sizeof(BITMAPINFOHEADER)); | |
614 mux_v->bih->biSize=sizeof(BITMAPINFOHEADER); | |
615 mux_v->bih->biWidth=sh_video->disp_w; | |
616 mux_v->bih->biHeight=sh_video->disp_h; | |
617 mux_v->bih->biCompression=0; | |
618 mux_v->bih->biPlanes=1; | |
619 mux_v->bih->biBitCount=24; // FIXME!!! | |
620 mux_v->bih->biSizeImage=mux_v->bih->biWidth*mux_v->bih->biHeight*(mux_v->bih->biBitCount/8); | |
621 } | |
622 mux_v->bih->biCompression=0; | |
623 printf("videocodec: raw (%dx%d %dbpp fourcc=%x)\n", | |
624 mux_v->bih->biWidth, mux_v->bih->biHeight, | |
625 mux_v->bih->biBitCount, mux_v->bih->biCompression); | |
626 break; | |
3361
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
627 case VCODEC_FRAMENO: |
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
628 mux_v->bih=malloc(sizeof(BITMAPINFOHEADER)); |
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
629 mux_v->bih->biSize=sizeof(BITMAPINFOHEADER); |
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
630 mux_v->bih->biWidth=vo_w; |
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
631 mux_v->bih->biHeight=vo_h; |
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
632 mux_v->bih->biPlanes=1; |
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
633 mux_v->bih->biBitCount=24; |
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
634 mux_v->bih->biCompression=mmioFOURCC('F','r','N','o'); |
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
635 mux_v->bih->biSizeImage=mux_v->bih->biWidth*mux_v->bih->biHeight*(mux_v->bih->biBitCount/8); |
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
636 break; |
2531 | 637 case VCODEC_DIVX4: |
3663
9092546e7765
made divx4 optional (also configure checking needed) and added avcodec_close
alex
parents:
3657
diff
changeset
|
638 #ifndef HAVE_DIVX4ENCORE |
9092546e7765
made divx4 optional (also configure checking needed) and added avcodec_close
alex
parents:
3657
diff
changeset
|
639 printf("No support for Divx4 encore compiled in\n"); |
9092546e7765
made divx4 optional (also configure checking needed) and added avcodec_close
alex
parents:
3657
diff
changeset
|
640 return 0; /* FIXME */ |
9092546e7765
made divx4 optional (also configure checking needed) and added avcodec_close
alex
parents:
3657
diff
changeset
|
641 #else |
2531 | 642 mux_v->bih=malloc(sizeof(BITMAPINFOHEADER)); |
643 mux_v->bih->biSize=sizeof(BITMAPINFOHEADER); | |
3236 | 644 mux_v->bih->biWidth=vo_w; |
645 mux_v->bih->biHeight=vo_h; | |
2635
c1e24e01601b
fixed AVI header creation - now should be compatible with NaNdub
arpi
parents:
2627
diff
changeset
|
646 mux_v->bih->biPlanes=1; |
2531 | 647 mux_v->bih->biBitCount=24; |
648 mux_v->bih->biCompression=mmioFOURCC('d','i','v','x'); | |
649 mux_v->bih->biSizeImage=mux_v->bih->biWidth*mux_v->bih->biHeight*(mux_v->bih->biBitCount/8); | |
3377
4723f6fd750a
do not fault if 2pass VbrControl can't open the logfile
alex
parents:
3363
diff
changeset
|
650 |
4723f6fd750a
do not fault if 2pass VbrControl can't open the logfile
alex
parents:
3363
diff
changeset
|
651 if (pass) |
4723f6fd750a
do not fault if 2pass VbrControl can't open the logfile
alex
parents:
3363
diff
changeset
|
652 printf("Divx: 2-pass logfile: %s\n", passtmpfile); |
2531 | 653 break; |
3663
9092546e7765
made divx4 optional (also configure checking needed) and added avcodec_close
alex
parents:
3657
diff
changeset
|
654 #endif |
3657
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
655 case VCODEC_LIBAVCODEC: |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
656 #ifndef USE_LIBAVCODEC |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
657 printf("No support for FFmpeg's libavcodec compiled in\n"); |
3663
9092546e7765
made divx4 optional (also configure checking needed) and added avcodec_close
alex
parents:
3657
diff
changeset
|
658 return 0; /* FIXME */ |
3657
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
659 #else |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
660 mux_v->bih=malloc(sizeof(BITMAPINFOHEADER)); |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
661 mux_v->bih->biSize=sizeof(BITMAPINFOHEADER); |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
662 mux_v->bih->biWidth=vo_w; |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
663 mux_v->bih->biHeight=vo_h; |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
664 mux_v->bih->biPlanes=1; |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
665 mux_v->bih->biBitCount=24; |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
666 mux_v->bih->biCompression=mmioFOURCC(lavc_param_vcodec[0], |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
667 lavc_param_vcodec[1], lavc_param_vcodec[2], lavc_param_vcodec[3]); /* FIXME!!! */ |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
668 mux_v->bih->biSizeImage=mux_v->bih->biWidth*mux_v->bih->biHeight*(mux_v->bih->biBitCount/8); |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
669 |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
670 printf("videocodec: libavcodec (%dx%d fourcc=%x [%.4s])\n", |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
671 mux_v->bih->biWidth, mux_v->bih->biHeight, mux_v->bih->biCompression, |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
672 &mux_v->bih->biCompression); |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
673 #endif |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
674 } |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
675 |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
676 /* force output fourcc to .. */ |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
677 if (force_fourcc != NULL) |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
678 { |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
679 mux_v->bih->biCompression = mmioFOURCC(force_fourcc[0], force_fourcc[1], |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
680 force_fourcc[2], force_fourcc[3]); |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
681 printf("Forcing output fourcc to %x [%.4s]\n", |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
682 mux_v->bih->biCompression, &mux_v->bih->biCompression); |
2531 | 683 } |
684 | |
2581 | 685 // ============= AUDIO =============== |
686 if(sh_audio){ | |
687 | |
688 mux_a=aviwrite_new_stream(muxer,AVIWRITE_TYPE_AUDIO); | |
689 | |
690 mux_a->buffer_size=0x100000; //16384; | |
691 mux_a->buffer=malloc(mux_a->buffer_size); | |
692 | |
693 mux_a->source=sh_audio; | |
694 | |
2661 | 695 mux_a->codec=out_audio_codec; |
2581 | 696 |
697 switch(mux_a->codec){ | |
3385 | 698 case ACODEC_COPY: |
699 printf("sh_audio->wf: %x\n", sh_audio->wf); | |
2581 | 700 mux_a->h.dwSampleSize=sh_audio->audio.dwSampleSize; |
701 mux_a->h.dwScale=sh_audio->audio.dwScale; | |
702 mux_a->h.dwRate=sh_audio->audio.dwRate; | |
3385 | 703 if (sh_audio->wf) |
704 mux_a->wf=sh_audio->wf; | |
705 else | |
706 { | |
707 mux_a->wf = malloc(sizeof(WAVEFORMATEX)); | |
708 mux_a->wf->nBlockAlign = mux_a->h.dwSampleSize; | |
709 mux_a->wf->wFormatTag = sh_audio->sample_format; | |
710 mux_a->wf->nChannels = sh_audio->channels; | |
711 mux_a->wf->nSamplesPerSec = sh_audio->samplerate; | |
712 mux_a->wf->nAvgBytesPerSec=mux_a->h.dwSampleSize*mux_a->wf->nSamplesPerSec; | |
3480 | 713 mux_a->wf->wBitsPerSample = 16; // FIXME |
3385 | 714 mux_a->wf->cbSize=0; // FIXME for l3codeca.acm |
715 } | |
716 printf("audiocodec: framecopy (format=%x chans=%d rate=%d bits=%d)\n", | |
717 mux_a->wf->wFormatTag, mux_a->wf->nChannels, mux_a->wf->nSamplesPerSec, | |
718 mux_a->wf->wBitsPerSample); | |
2581 | 719 break; |
2583 | 720 case ACODEC_PCM: |
721 printf("CBR PCM audio selected\n"); | |
722 mux_a->h.dwSampleSize=2*sh_audio->channels; | |
723 mux_a->h.dwScale=1; | |
724 mux_a->h.dwRate=sh_audio->samplerate; | |
725 mux_a->wf=malloc(sizeof(WAVEFORMATEX)); | |
726 mux_a->wf->nBlockAlign=mux_a->h.dwSampleSize; | |
727 mux_a->wf->wFormatTag=0x1; // PCM | |
728 mux_a->wf->nChannels=sh_audio->channels; | |
729 mux_a->wf->nSamplesPerSec=sh_audio->samplerate; | |
730 mux_a->wf->nAvgBytesPerSec=mux_a->h.dwSampleSize*mux_a->wf->nSamplesPerSec; | |
731 mux_a->wf->wBitsPerSample=16; | |
732 mux_a->wf->cbSize=0; // FIXME for l3codeca.acm | |
733 break; | |
2581 | 734 case ACODEC_VBRMP3: |
3385 | 735 printf("MP3 audio selected\n"); |
2581 | 736 mux_a->h.dwSampleSize=0; // VBR |
2653 | 737 mux_a->h.dwScale=1152; // samples/frame |
2581 | 738 mux_a->h.dwRate=sh_audio->samplerate; |
2635
c1e24e01601b
fixed AVI header creation - now should be compatible with NaNdub
arpi
parents:
2627
diff
changeset
|
739 if(sizeof(MPEGLAYER3WAVEFORMAT)!=30) mp_msg(MSGT_MENCODER,MSGL_WARN,"sizeof(MPEGLAYER3WAVEFORMAT)==%d!=30, maybe broken C compiler?\n",sizeof(MPEGLAYER3WAVEFORMAT)); |
c1e24e01601b
fixed AVI header creation - now should be compatible with NaNdub
arpi
parents:
2627
diff
changeset
|
740 mux_a->wf=malloc(sizeof(MPEGLAYER3WAVEFORMAT)); // should be 30 |
2581 | 741 mux_a->wf->wFormatTag=0x55; // MP3 |
742 mux_a->wf->nChannels=sh_audio->channels; | |
2639 | 743 mux_a->wf->nSamplesPerSec=force_srate?force_srate:sh_audio->samplerate; |
2635
c1e24e01601b
fixed AVI header creation - now should be compatible with NaNdub
arpi
parents:
2627
diff
changeset
|
744 mux_a->wf->nAvgBytesPerSec=192000/8; // FIXME! |
2653 | 745 mux_a->wf->nBlockAlign=1152; // requires for l3codeca.acm + WMP 6.4 |
2635
c1e24e01601b
fixed AVI header creation - now should be compatible with NaNdub
arpi
parents:
2627
diff
changeset
|
746 mux_a->wf->wBitsPerSample=0; //16; |
c1e24e01601b
fixed AVI header creation - now should be compatible with NaNdub
arpi
parents:
2627
diff
changeset
|
747 // from NaNdub: (requires for l3codeca.acm) |
c1e24e01601b
fixed AVI header creation - now should be compatible with NaNdub
arpi
parents:
2627
diff
changeset
|
748 mux_a->wf->cbSize=12; |
c1e24e01601b
fixed AVI header creation - now should be compatible with NaNdub
arpi
parents:
2627
diff
changeset
|
749 ((MPEGLAYER3WAVEFORMAT*)(mux_a->wf))->wID=1; |
c1e24e01601b
fixed AVI header creation - now should be compatible with NaNdub
arpi
parents:
2627
diff
changeset
|
750 ((MPEGLAYER3WAVEFORMAT*)(mux_a->wf))->fdwFlags=2; |
2653 | 751 ((MPEGLAYER3WAVEFORMAT*)(mux_a->wf))->nBlockSize=1152; // ??? |
2635
c1e24e01601b
fixed AVI header creation - now should be compatible with NaNdub
arpi
parents:
2627
diff
changeset
|
752 ((MPEGLAYER3WAVEFORMAT*)(mux_a->wf))->nFramesPerBlock=1; |
c1e24e01601b
fixed AVI header creation - now should be compatible with NaNdub
arpi
parents:
2627
diff
changeset
|
753 ((MPEGLAYER3WAVEFORMAT*)(mux_a->wf))->nCodecDelay=0; |
2581 | 754 break; |
755 } | |
756 } | |
757 | |
2840
808fe0767cf8
fix typos - patch by Colin Marquardt <colin@marquardt-home.de>
pl
parents:
2825
diff
changeset
|
758 printf("Writing AVI header...\n"); |
2531 | 759 aviwrite_write_header(muxer,muxer_f); |
760 | |
761 switch(mux_v->codec){ | |
3384 | 762 case VCODEC_COPY: |
3480 | 763 case VCODEC_RAW: |
2531 | 764 break; |
3361
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
765 case VCODEC_FRAMENO: |
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
766 decoded_frameno=0; |
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
767 break; |
2531 | 768 case VCODEC_DIVX4: |
3663
9092546e7765
made divx4 optional (also configure checking needed) and added avcodec_close
alex
parents:
3657
diff
changeset
|
769 #ifndef HAVE_DIVX4ENCORE |
9092546e7765
made divx4 optional (also configure checking needed) and added avcodec_close
alex
parents:
3657
diff
changeset
|
770 printf("No support for Divx4 encore compiled in\n"); |
9092546e7765
made divx4 optional (also configure checking needed) and added avcodec_close
alex
parents:
3657
diff
changeset
|
771 return 0; /* FIXME */ |
9092546e7765
made divx4 optional (also configure checking needed) and added avcodec_close
alex
parents:
3657
diff
changeset
|
772 #else |
2531 | 773 // init divx4linux: |
3236 | 774 divx4_param.x_dim=vo_w; |
775 divx4_param.y_dim=vo_h; | |
2626 | 776 divx4_param.framerate=(float)mux_v->h.dwRate/mux_v->h.dwScale; |
777 if(!divx4_param.bitrate) divx4_param.bitrate=800000; | |
778 else if(divx4_param.bitrate<=16000) divx4_param.bitrate*=1000; | |
779 if(!divx4_param.quality) divx4_param.quality=5; // the quality of compression ( 1 - fastest, 5 - best ) | |
780 divx4_param.handle=NULL; | |
781 encore(NULL,ENC_OPT_INIT,&divx4_param,NULL); | |
782 enc_handle=divx4_param.handle; | |
2643 | 783 switch(out_fmt){ |
784 case IMGFMT_YV12: enc_frame.colorspace=ENC_CSP_YV12; break; | |
785 case IMGFMT_IYUV: | |
786 case IMGFMT_I420: enc_frame.colorspace=ENC_CSP_I420; break; | |
787 case IMGFMT_YUY2: enc_frame.colorspace=ENC_CSP_YUY2; break; | |
788 case IMGFMT_UYVY: enc_frame.colorspace=ENC_CSP_UYVY; break; | |
789 case IMGFMT_RGB24: | |
790 case IMGFMT_BGR24: | |
791 enc_frame.colorspace=ENC_CSP_RGB24; break; | |
792 default: | |
3657
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
793 mp_msg(MSGT_MENCODER,MSGL_ERR,"divx4: unsupported picture format (%s)!\n", |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
794 vo_format_name(out_fmt)); |
2643 | 795 } |
796 switch(pass){ | |
797 case 1: | |
3377
4723f6fd750a
do not fault if 2pass VbrControl can't open the logfile
alex
parents:
3363
diff
changeset
|
798 if (VbrControl_init_2pass_vbr_analysis(passtmpfile, divx4_param.quality) == -1) |
4723f6fd750a
do not fault if 2pass VbrControl can't open the logfile
alex
parents:
3363
diff
changeset
|
799 { |
4723f6fd750a
do not fault if 2pass VbrControl can't open the logfile
alex
parents:
3363
diff
changeset
|
800 printf("2pass failed: filename=%s\n", passtmpfile); |
4723f6fd750a
do not fault if 2pass VbrControl can't open the logfile
alex
parents:
3363
diff
changeset
|
801 pass_working = 0; |
4723f6fd750a
do not fault if 2pass VbrControl can't open the logfile
alex
parents:
3363
diff
changeset
|
802 } |
4723f6fd750a
do not fault if 2pass VbrControl can't open the logfile
alex
parents:
3363
diff
changeset
|
803 else |
4723f6fd750a
do not fault if 2pass VbrControl can't open the logfile
alex
parents:
3363
diff
changeset
|
804 pass_working = 1; |
2643 | 805 break; |
806 case 2: | |
3377
4723f6fd750a
do not fault if 2pass VbrControl can't open the logfile
alex
parents:
3363
diff
changeset
|
807 if (VbrControl_init_2pass_vbr_encoding(passtmpfile, |
2643 | 808 divx4_param.bitrate, |
809 divx4_param.framerate, | |
810 divx4_crispness, | |
3377
4723f6fd750a
do not fault if 2pass VbrControl can't open the logfile
alex
parents:
3363
diff
changeset
|
811 divx4_param.quality) == -1) |
4723f6fd750a
do not fault if 2pass VbrControl can't open the logfile
alex
parents:
3363
diff
changeset
|
812 { |
4723f6fd750a
do not fault if 2pass VbrControl can't open the logfile
alex
parents:
3363
diff
changeset
|
813 printf("2pass failed: filename=%s\n", passtmpfile); |
4723f6fd750a
do not fault if 2pass VbrControl can't open the logfile
alex
parents:
3363
diff
changeset
|
814 pass_working = 0; |
4723f6fd750a
do not fault if 2pass VbrControl can't open the logfile
alex
parents:
3363
diff
changeset
|
815 } |
4723f6fd750a
do not fault if 2pass VbrControl can't open the logfile
alex
parents:
3363
diff
changeset
|
816 else |
4723f6fd750a
do not fault if 2pass VbrControl can't open the logfile
alex
parents:
3363
diff
changeset
|
817 pass_working = 1; |
2643 | 818 break; |
819 } | |
2531 | 820 break; |
3663
9092546e7765
made divx4 optional (also configure checking needed) and added avcodec_close
alex
parents:
3657
diff
changeset
|
821 #endif |
3657
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
822 case VCODEC_LIBAVCODEC: |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
823 #ifndef USE_LIBAVCODEC |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
824 printf("No support for FFmpeg's libavcodec compiled in\n"); |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
825 #else |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
826 if (!avcodec_inited) |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
827 { |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
828 avcodec_init(); |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
829 avcodec_register_all(); |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
830 avcodec_inited=1; |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
831 } |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
832 |
3702
e16996f5497d
supporting -ofps by lavc, using avcodec_find_encoder_by_name (latest libavcodec cvs)
alex
parents:
3693
diff
changeset
|
833 #if 0 |
3657
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
834 { |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
835 extern AVCodec *first_avcodec; |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
836 AVCodec *p = first_avcodec; |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
837 |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
838 lavc_venc_codec = NULL; |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
839 while (p) |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
840 { |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
841 if (p->encode != NULL && strcmp(lavc_param_vcodec, p->name) == 0) |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
842 break; |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
843 p = p->next; |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
844 } |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
845 lavc_venc_codec = p; |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
846 } |
3691
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
847 #else |
3657
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
848 /* XXX: implement this in avcodec (i will send a patch to ffmpeglist) -- alex */ |
3691
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
849 lavc_venc_codec = (AVCodec *)avcodec_find_encoder_by_name(lavc_param_vcodec); |
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
850 #endif |
3657
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
851 |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
852 if (!lavc_venc_codec) |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
853 { |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
854 printf(MSGTR_MissingLAVCcodec, lavc_param_vcodec); |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
855 return 0; /* FIXME */ |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
856 } |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
857 |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
858 memset(&lavc_venc_context, 0, sizeof(lavc_venc_context)); |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
859 |
3691
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
860 // lavc_venc_context.width = mux_v->bih->biWidth; |
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
861 // lavc_venc_context.height = mux_v->bih->biHeight; |
3702
e16996f5497d
supporting -ofps by lavc, using avcodec_find_encoder_by_name (latest libavcodec cvs)
alex
parents:
3693
diff
changeset
|
862 /* scaling only for YV12 (and lavc supports only YV12 ;) */ |
3691
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
863 lavc_venc_context.width = vo_w; |
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
864 lavc_venc_context.height = vo_h; |
3657
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
865 if (lavc_param_vbitrate >= 0) /* != -1 */ |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
866 lavc_venc_context.bit_rate = lavc_param_vbitrate; |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
867 else |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
868 lavc_venc_context.bit_rate = 800000; /* default */ |
3702
e16996f5497d
supporting -ofps by lavc, using avcodec_find_encoder_by_name (latest libavcodec cvs)
alex
parents:
3693
diff
changeset
|
869 lavc_venc_context.frame_rate = (float)(force_ofps?force_ofps:sh_video->fps) * FRAME_RATE_BASE; |
3657
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
870 /* keyframe interval */ |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
871 if (lavc_param_keyint >= 0) /* != -1 */ |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
872 lavc_venc_context.gop_size = lavc_param_keyint; |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
873 else |
3691
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
874 lavc_venc_context.gop_size = 250; /* default */ |
3693 | 875 |
3691
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
876 /* ignored by libavcodec? */ |
3657
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
877 if (lavc_param_vhq) |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
878 { |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
879 printf("High quality encoding selected (non real time)!\n"); |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
880 lavc_venc_context.flags = CODEC_FLAG_HQ; |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
881 } |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
882 else |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
883 lavc_venc_context.flags = 0; |
3691
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
884 |
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
885 #if 0 |
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
886 /* fixed qscale :p */ |
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
887 lavc_venc_context.flags |= CODEC_FLAG_QSCALE; |
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
888 lavc_venc_context.quality = 1; |
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
889 #endif |
3657
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
890 |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
891 if (avcodec_open(&lavc_venc_context, lavc_venc_codec) != 0) |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
892 { |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
893 printf(MSGTR_CantOpenCodec); |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
894 return 0; /* FIXME */ |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
895 } |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
896 |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
897 if (lavc_venc_context.codec->encode == NULL) |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
898 { |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
899 printf("avcodec init failed (ctx->codec->encode == NULL)!\n"); |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
900 return 0; |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
901 } |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
902 |
3691
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
903 #if 1 |
3764
0195894e279f
added support for I420 input (used by TV V4L) in lavc encoder
alex
parents:
3748
diff
changeset
|
904 if (out_fmt != IMGFMT_YV12 && out_fmt != IMGFMT_I420) |
3691
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
905 { |
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
906 printf("Not supported image format! (%s)\n", |
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
907 vo_format_name(out_fmt)); |
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
908 return 0; /* FIXME */ |
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
909 } |
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
910 |
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
911 memset(&lavc_venc_picture, 0, sizeof(lavc_venc_picture)); |
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
912 |
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
913 { |
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
914 int size = lavc_venc_context.width * lavc_venc_context.height; |
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
915 |
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
916 /* Y */ lavc_venc_picture.data[0] = vo_image_ptr; |
3764
0195894e279f
added support for I420 input (used by TV V4L) in lavc encoder
alex
parents:
3748
diff
changeset
|
917 if (out_fmt == IMGFMT_YV12) |
0195894e279f
added support for I420 input (used by TV V4L) in lavc encoder
alex
parents:
3748
diff
changeset
|
918 { |
0195894e279f
added support for I420 input (used by TV V4L) in lavc encoder
alex
parents:
3748
diff
changeset
|
919 /* U */ lavc_venc_picture.data[2] = lavc_venc_picture.data[0] + size; |
0195894e279f
added support for I420 input (used by TV V4L) in lavc encoder
alex
parents:
3748
diff
changeset
|
920 /* V */ lavc_venc_picture.data[1] = lavc_venc_picture.data[2] + size/4; |
0195894e279f
added support for I420 input (used by TV V4L) in lavc encoder
alex
parents:
3748
diff
changeset
|
921 } |
0195894e279f
added support for I420 input (used by TV V4L) in lavc encoder
alex
parents:
3748
diff
changeset
|
922 else /* IMGFMT_I420 */ |
0195894e279f
added support for I420 input (used by TV V4L) in lavc encoder
alex
parents:
3748
diff
changeset
|
923 { |
0195894e279f
added support for I420 input (used by TV V4L) in lavc encoder
alex
parents:
3748
diff
changeset
|
924 /* U */ lavc_venc_picture.data[1] = lavc_venc_picture.data[0] + size; |
0195894e279f
added support for I420 input (used by TV V4L) in lavc encoder
alex
parents:
3748
diff
changeset
|
925 /* V */ lavc_venc_picture.data[2] = lavc_venc_picture.data[1] + size/4; |
0195894e279f
added support for I420 input (used by TV V4L) in lavc encoder
alex
parents:
3748
diff
changeset
|
926 } |
3691
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
927 lavc_venc_picture.linesize[0] = lavc_venc_context.width; |
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
928 lavc_venc_picture.linesize[1] = lavc_venc_context.width / 2; |
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
929 lavc_venc_picture.linesize[2] = lavc_venc_context.width / 2; |
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
930 } |
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
931 #else |
3657
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
932 switch(out_fmt) |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
933 { |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
934 case IMGFMT_YV12: |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
935 lavc_venc_context.pix_fmt = PIX_FMT_YUV420P; |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
936 break; |
3691
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
937 #if 0 /* it's faulting :( -- libavcodec's bug! -- alex */ |
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
938 case IMGFMT_YUY2: /* or UYVY */ |
3657
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
939 lavc_venc_context.pix_fmt = PIX_FMT_YUV422; |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
940 break; |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
941 case IMGFMT_BGR24: |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
942 lavc_venc_context.pix_fmt = PIX_FMT_BGR24; |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
943 break; |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
944 case IMGFMT_RGB24: |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
945 lavc_venc_context.pix_fmt = PIX_FMT_RGB24; |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
946 break; |
3663
9092546e7765
made divx4 optional (also configure checking needed) and added avcodec_close
alex
parents:
3657
diff
changeset
|
947 #endif |
3657
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
948 default: |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
949 printf("Not supported image format! (%s)\n", |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
950 vo_format_name(out_fmt)); |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
951 return 0; /* FIXME */ |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
952 } |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
953 |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
954 printf("Using picture format: %s\n", vo_format_name(out_fmt)); |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
955 |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
956 memset(&lavc_venc_picture, 0, sizeof(lavc_venc_picture)); |
3691
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
957 |
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
958 printf("ahh: avpict_getsize=%d, vo_image_ptr=%d\n", avpicture_get_size(lavc_venc_context.pix_fmt, |
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
959 lavc_venc_context.width, lavc_venc_context.height), |
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
960 vo_h*vo_w*3/2); |
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
961 |
3657
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
962 avpicture_fill(&lavc_venc_picture, vo_image_ptr, |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
963 lavc_venc_context.pix_fmt, lavc_venc_context.width, |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
964 lavc_venc_context.height); |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
965 |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
966 { |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
967 char buf[1024]; |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
968 |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
969 avcodec_string((char *)&buf[0], 1023, &lavc_venc_context, 1); |
3663
9092546e7765
made divx4 optional (also configure checking needed) and added avcodec_close
alex
parents:
3657
diff
changeset
|
970 printf("%s\n", buf); |
3657
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
971 } |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
972 #endif |
3691
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
973 |
ed9404084ca7
fixed scaling and colors with libavcodec (and some comments added)
alex
parents:
3667
diff
changeset
|
974 #endif |
2531 | 975 } |
976 | |
2600 | 977 if(sh_audio) |
2583 | 978 switch(mux_a->codec){ |
3357 | 979 #ifdef HAVE_MP3LAME |
2583 | 980 case ACODEC_VBRMP3: |
981 | |
982 lame=lame_init(); | |
2591 | 983 lame_set_bWriteVbrTag(lame,0); |
2583 | 984 lame_set_in_samplerate(lame,sh_audio->samplerate); |
985 lame_set_num_channels(lame,mux_a->wf->nChannels); | |
2639 | 986 lame_set_out_samplerate(lame,mux_a->wf->nSamplesPerSec); |
2626 | 987 if(lame_param_vbr){ // VBR: |
988 lame_set_VBR(lame,lame_param_vbr); // vbr mode | |
989 lame_set_VBR_q(lame,lame_param_quality+1); // 1 = best vbr q 6=~128k | |
990 if(lame_param_br>0) lame_set_VBR_mean_bitrate_kbps(lame,lame_param_br); | |
991 } else { // CBR: | |
992 lame_set_quality(lame,lame_param_quality); // 0 = best q | |
993 if(lame_param_br>0) lame_set_brate(lame,lame_param_br); | |
994 } | |
995 if(lame_param_mode>=0) lame_set_mode(lame,lame_param_mode); // j-st | |
996 if(lame_param_ratio>0) lame_set_compression_ratio(lame,lame_param_ratio); | |
2583 | 997 lame_init_params(lame); |
2622 | 998 if(verbose){ |
2626 | 999 lame_print_config(lame); |
1000 lame_print_internals(lame); | |
2622 | 1001 } |
3357 | 1002 break; |
1003 #endif | |
2583 | 1004 |
1005 } | |
1006 | |
2531 | 1007 signal(SIGINT,exit_sighandler); // Interrupt from keyboard |
1008 signal(SIGQUIT,exit_sighandler); // Quit from keyboard | |
1009 signal(SIGTERM,exit_sighandler); // kill | |
1010 | |
1011 while(!eof){ | |
1012 | |
2571 | 1013 float frame_time=0; |
2531 | 1014 int blit_frame=0; |
1015 float a_pts=0; | |
1016 float v_pts=0; | |
2574 | 1017 unsigned char* start=NULL; |
1018 int in_size; | |
2613 | 1019 int skip_flag=0; // 1=skip -1=duplicate |
2531 | 1020 |
2643 | 1021 if(play_n_frames>=0){ |
1022 --play_n_frames; | |
1023 if(play_n_frames<0) break; | |
1024 } | |
1025 | |
2581 | 1026 if(sh_audio){ |
1027 // get audio: | |
2583 | 1028 while(mux_a->timer-audio_preload<mux_v->timer){ |
2653 | 1029 int len=0; |
2581 | 1030 if(mux_a->h.dwSampleSize){ |
2605 | 1031 // CBR - copy 0.5 sec of audio |
2583 | 1032 switch(mux_a->codec){ |
3385 | 1033 case ACODEC_COPY: // copy |
2583 | 1034 len=sh_audio->i_bps/2; |
1035 len/=mux_a->h.dwSampleSize;if(len<1) len=1; | |
1036 len*=mux_a->h.dwSampleSize; | |
1037 len=demux_read_data(sh_audio->ds,mux_a->buffer,len); | |
1038 break; | |
1039 case ACODEC_PCM: | |
1040 len=mux_a->h.dwSampleSize*(mux_a->h.dwRate/2); | |
2591 | 1041 len=dec_audio(sh_audio,mux_a->buffer,len); |
2583 | 1042 break; |
1043 } | |
2581 | 1044 } else { |
2605 | 1045 // VBR - encode/copy an audio frame |
1046 switch(mux_a->codec){ | |
3385 | 1047 case ACODEC_COPY: // copy |
1048 printf("VBR audio framecopy not yet implemented!\n"); | |
2605 | 1049 break; |
3357 | 1050 #ifdef HAVE_MP3LAME |
2605 | 1051 case ACODEC_VBRMP3: |
2591 | 1052 while(mux_a->buffer_len<4){ |
1053 unsigned char tmp[2304]; | |
1054 int len=dec_audio(sh_audio,tmp,2304); | |
1055 if(len<=0) break; // eof | |
1056 len=lame_encode_buffer_interleaved(lame, | |
1057 tmp,len/4, | |
1058 mux_a->buffer+mux_a->buffer_len,mux_a->buffer_size-mux_a->buffer_len); | |
1059 if(len<0) break; // error | |
1060 mux_a->buffer_len+=len; | |
1061 } | |
1062 if(mux_a->buffer_len<4) break; | |
1063 len=mp_decode_mp3_header(mux_a->buffer); | |
2639 | 1064 //printf("%d\n",len); |
2591 | 1065 if(len<=0) break; // bad frame! |
1066 while(mux_a->buffer_len<len){ | |
1067 unsigned char tmp[2304]; | |
1068 int len=dec_audio(sh_audio,tmp,2304); | |
1069 if(len<=0) break; // eof | |
1070 len=lame_encode_buffer_interleaved(lame, | |
1071 tmp,len/4, | |
1072 mux_a->buffer+mux_a->buffer_len,mux_a->buffer_size-mux_a->buffer_len); | |
1073 if(len<0) break; // error | |
1074 mux_a->buffer_len+=len; | |
1075 } | |
2605 | 1076 break; |
3357 | 1077 #endif |
2605 | 1078 } |
2581 | 1079 } |
2583 | 1080 if(len<=0) break; // EOF? |
1081 aviwrite_write_chunk(muxer,mux_a,muxer_f,len,0); | |
2655 | 1082 if(!mux_a->h.dwSampleSize && mux_a->timer>0) |
3354 | 1083 mux_a->wf->nAvgBytesPerSec=0.5f+(double)mux_a->size/mux_a->timer; // avg bps (VBR) |
2591 | 1084 if(mux_a->buffer_len>=len){ |
1085 mux_a->buffer_len-=len; | |
1086 memcpy(mux_a->buffer,mux_a->buffer+len,mux_a->buffer_len); | |
1087 } | |
2581 | 1088 } |
1089 } | |
1090 | |
1091 // get video frame! | |
1092 in_size=video_read_frame(sh_video,&frame_time,&start,force_fps); | |
1093 if(in_size<0){ eof=1; break; } | |
3361
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
1094 sh_video->timer+=frame_time; ++decoded_frameno; |
2613 | 1095 |
1096 v_timer_corr-=frame_time-(float)mux_v->h.dwScale/mux_v->h.dwRate; | |
2531 | 1097 |
2613 | 1098 // check frame duplicate/drop: |
1099 | |
1100 if(v_timer_corr>=(float)mux_v->h.dwScale/mux_v->h.dwRate){ | |
1101 v_timer_corr-=(float)mux_v->h.dwScale/mux_v->h.dwRate; | |
1102 ++skip_flag; // skip | |
1103 } else | |
1104 while(v_timer_corr<=-(float)mux_v->h.dwScale/mux_v->h.dwRate){ | |
1105 v_timer_corr+=(float)mux_v->h.dwScale/mux_v->h.dwRate; | |
1106 --skip_flag; // dup | |
1107 } | |
2531 | 1108 |
2613 | 1109 while( (v_pts_corr<=-(float)mux_v->h.dwScale/mux_v->h.dwRate && skip_flag>0) |
1110 || (v_pts_corr<=-2*(float)mux_v->h.dwScale/mux_v->h.dwRate) ){ | |
1111 v_pts_corr+=(float)mux_v->h.dwScale/mux_v->h.dwRate; | |
1112 --skip_flag; // dup | |
1113 } | |
1114 if( (v_pts_corr>=(float)mux_v->h.dwScale/mux_v->h.dwRate && skip_flag<0) | |
1115 || (v_pts_corr>=2*(float)mux_v->h.dwScale/mux_v->h.dwRate) ) | |
1116 if(skip_flag<=0){ // we can't skip more than 1 frame now | |
1117 v_pts_corr-=(float)mux_v->h.dwScale/mux_v->h.dwRate; | |
1118 ++skip_flag; // skip | |
1119 } | |
1120 | |
1121 | |
2531 | 1122 switch(mux_v->codec){ |
3384 | 1123 case VCODEC_COPY: |
2574 | 1124 mux_v->buffer=start; |
2639 | 1125 if(skip_flag<=0) aviwrite_write_chunk(muxer,mux_v,muxer_f,in_size,(sh_video->ds->flags&1)?0x10:0); |
2574 | 1126 break; |
3480 | 1127 case VCODEC_RAW: |
1128 blit_frame=decode_video(&video_out,sh_video,start,in_size,0); | |
1129 if(skip_flag>0) break; | |
1130 if(!blit_frame){ | |
1131 // empty. | |
1132 aviwrite_write_chunk(muxer,mux_v,muxer_f,0,0); | |
1133 break; | |
1134 } | |
1135 mux_v->buffer = vo_image_ptr; | |
1136 aviwrite_write_chunk(muxer,mux_v,muxer_f,mux_v->buffer_size,0x10); | |
1137 break; | |
3361
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
1138 case VCODEC_FRAMENO: |
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
1139 mux_v->buffer=&decoded_frameno; // tricky |
3363
1459912caea5
set all frames to keyframes for -ovc frameno - allow seeking in resulting audio-only avi
arpi
parents:
3362
diff
changeset
|
1140 if(skip_flag<=0) aviwrite_write_chunk(muxer,mux_v,muxer_f,sizeof(int),0x10); |
3361
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
1141 break; |
2531 | 1142 case VCODEC_DIVX4: |
3663
9092546e7765
made divx4 optional (also configure checking needed) and added avcodec_close
alex
parents:
3657
diff
changeset
|
1143 #ifndef HAVE_DIVX4ENCORE |
9092546e7765
made divx4 optional (also configure checking needed) and added avcodec_close
alex
parents:
3657
diff
changeset
|
1144 printf("No support for Divx4 encore compiled in\n"); |
9092546e7765
made divx4 optional (also configure checking needed) and added avcodec_close
alex
parents:
3657
diff
changeset
|
1145 return 0; /* FIXME */ |
9092546e7765
made divx4 optional (also configure checking needed) and added avcodec_close
alex
parents:
3657
diff
changeset
|
1146 #else |
2574 | 1147 blit_frame=decode_video(&video_out,sh_video,start,in_size,0); |
2639 | 1148 if(skip_flag>0) break; |
2574 | 1149 if(!blit_frame){ |
1150 // empty. | |
1151 aviwrite_write_chunk(muxer,mux_v,muxer_f,0,0); | |
1152 break; | |
1153 } | |
2531 | 1154 enc_frame.image=vo_image_ptr; |
1155 enc_frame.bitstream=mux_v->buffer; | |
1156 enc_frame.length=mux_v->buffer_size; | |
2643 | 1157 enc_frame.mvs=NULL; |
2531 | 1158 enc_frame.quant=0; |
1159 enc_frame.intra=0; | |
3377
4723f6fd750a
do not fault if 2pass VbrControl can't open the logfile
alex
parents:
3363
diff
changeset
|
1160 if(pass==2 && pass_working){ // handle 2-pass: |
4723f6fd750a
do not fault if 2pass VbrControl can't open the logfile
alex
parents:
3363
diff
changeset
|
1161 enc_frame.quant = VbrControl_get_quant(); |
2643 | 1162 enc_frame.intra = VbrControl_get_intra(); |
1163 encore(enc_handle,ENC_OPT_ENCODE_VBR,&enc_frame,&enc_result); | |
1164 VbrControl_update_2pass_vbr_encoding(enc_result.motion_bits, | |
1165 enc_result.texture_bits, | |
1166 enc_result.total_bits); | |
1167 } else { | |
1168 encore(enc_handle,ENC_OPT_ENCODE,&enc_frame,&enc_result); | |
3377
4723f6fd750a
do not fault if 2pass VbrControl can't open the logfile
alex
parents:
3363
diff
changeset
|
1169 if(pass==1 && pass_working){ |
2643 | 1170 VbrControl_update_2pass_vbr_analysis(enc_result.is_key_frame, |
1171 enc_result.motion_bits, | |
1172 enc_result.texture_bits, | |
1173 enc_result.total_bits, | |
1174 enc_result.quantizer); | |
1175 } | |
1176 } | |
1177 | |
2531 | 1178 // printf("encoding...\n"); |
1179 // printf(" len=%d key:%d qualt:%d \n",enc_frame.length,enc_result.is_key_frame,enc_result.quantizer); | |
1180 aviwrite_write_chunk(muxer,mux_v,muxer_f,enc_frame.length,enc_result.is_key_frame?0x10:0); | |
1181 break; | |
3663
9092546e7765
made divx4 optional (also configure checking needed) and added avcodec_close
alex
parents:
3657
diff
changeset
|
1182 #endif |
3657
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
1183 case VCODEC_LIBAVCODEC: |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
1184 { |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
1185 #ifndef USE_LIBAVCODEC |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
1186 printf("No support for FFmpeg's libavcodec compiled in\n"); |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
1187 #else |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
1188 int out_size; |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
1189 |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
1190 blit_frame=decode_video(&video_out,sh_video,start,in_size,0); |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
1191 if(skip_flag>0) break; |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
1192 if(!blit_frame){ |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
1193 // empty. |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
1194 aviwrite_write_chunk(muxer,mux_v,muxer_f,0,0); |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
1195 break; |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
1196 } |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
1197 |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
1198 out_size = avcodec_encode_video(&lavc_venc_context, mux_v->buffer, mux_v->buffer_size, |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
1199 &lavc_venc_picture); |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
1200 // printf("out_size = %d\n", out_size); |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
1201 aviwrite_write_chunk(muxer,mux_v,muxer_f,out_size,lavc_venc_context.key_frame?0x10:0); |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
1202 #endif |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
1203 } |
2531 | 1204 } |
2613 | 1205 |
1206 if(skip_flag<0){ | |
2605 | 1207 // duplicate frame |
2613 | 1208 printf("\nduplicate %d frame(s)!!! \n",-skip_flag); |
1209 while(skip_flag<0){ | |
1210 aviwrite_write_chunk(muxer,mux_v,muxer_f,0,0); | |
1211 ++skip_flag; | |
1212 } | |
2639 | 1213 } else |
1214 if(skip_flag>0){ | |
2605 | 1215 // skip frame |
1216 printf("\nskip frame!!! \n"); | |
2613 | 1217 --skip_flag; |
2605 | 1218 } |
1219 | |
1220 if(sh_audio){ | |
1221 float AV_delay,x; | |
1222 // A-V sync! | |
1223 if(pts_from_bps){ | |
1224 unsigned int samples=(sh_audio->audio.dwSampleSize)? | |
1225 ((ds_tell(d_audio)-sh_audio->a_in_buffer_len)/sh_audio->audio.dwSampleSize) : | |
1226 (d_audio->pack_no); // <- used for VBR audio | |
1227 a_pts=samples*(float)sh_audio->audio.dwScale/(float)sh_audio->audio.dwRate; | |
1228 delay_corrected=1; | |
1229 } else { | |
1230 // PTS = (last timestamp) + (bytes after last timestamp)/(bytes per sec) | |
1231 a_pts=d_audio->pts; | |
1232 if(!delay_corrected) if(a_pts) delay_corrected=1; | |
1233 //printf("*** %5.3f ***\n",a_pts); | |
1234 a_pts+=(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps; | |
1235 } | |
1236 v_pts=d_video->pts; | |
1237 // av = compensated (with out buffering delay) A-V diff | |
2613 | 1238 AV_delay=(a_pts-v_pts); AV_delay-=mux_a->timer-(mux_v->timer-(v_timer_corr+v_pts_corr)); |
2605 | 1239 // compensate input video timer by av: |
1240 x=AV_delay*0.1f; | |
1241 if(x<-max_pts_correction) x=-max_pts_correction; else | |
1242 if(x> max_pts_correction) x= max_pts_correction; | |
1243 if(default_max_pts_correction>=0) | |
1244 max_pts_correction=default_max_pts_correction; | |
1245 else | |
1246 max_pts_correction=sh_video->frametime*0.10; // +-10% of time | |
1247 // sh_video->timer-=x; | |
1248 c_total+=x; | |
2613 | 1249 v_pts_corr+=x; |
2605 | 1250 |
2613 | 1251 printf("A:%6.1f V:%6.1f A-V:%7.3f oAV:%7.3f diff:%7.3f ct:%7.3f vpc:%7.3f \r", |
2605 | 1252 a_pts,v_pts,a_pts-v_pts, |
1253 (float)(mux_a->timer-mux_v->timer), | |
2613 | 1254 AV_delay, c_total, v_pts_corr ); |
2605 | 1255 |
1256 } | |
1257 | |
1258 #if 0 | |
1259 mp_msg(MSGT_AVSYNC,MSGL_STATUS,"A:%6.1f V:%6.1f A-V:%7.3f ct:%7.3f %3d/%3d %2d%% %2d%% %4.1f%% %d%%\r", | |
1260 a_pts,v_pts,a_pts-v_pts,c_total, | |
1261 (int)sh_video->num_frames,(int)sh_video->num_frames_decoded, | |
1262 (sh_video->timer>0.5)?(int)(100.0*video_time_usage/(double)sh_video->timer):0, | |
1263 (sh_video->timer>0.5)?(int)(100.0*vout_time_usage/(double)sh_video->timer):0, | |
1264 (sh_video->timer>0.5)?(100.0*audio_time_usage/(double)sh_video->timer):0 | |
1265 ,cache_fill_status | |
1266 ); | |
1267 #endif | |
1268 | |
1269 fflush(stdout); | |
1270 | |
2531 | 1271 |
1272 | |
1273 } // while(!eof) | |
1274 | |
3357 | 1275 #ifdef HAVE_MP3LAME |
1276 // fixup CBR mp3 audio header: | |
3354 | 1277 if(sh_audio && mux_a->codec==ACODEC_VBRMP3 && !lame_param_vbr){ |
1278 mux_a->h.dwSampleSize=1; | |
1279 mux_a->h.dwRate=mux_a->wf->nAvgBytesPerSec; | |
1280 mux_a->h.dwScale=1; | |
1281 printf("\n\nCBR audio effective bitrate: %8.3f kbit/s (%d bytes/sec)\n", | |
1282 mux_a->h.dwRate*8.0f/1000.0f,mux_a->h.dwRate); | |
1283 } | |
3357 | 1284 #endif |
3354 | 1285 |
3663
9092546e7765
made divx4 optional (also configure checking needed) and added avcodec_close
alex
parents:
3657
diff
changeset
|
1286 #ifdef USE_LIBAVCODEC |
9092546e7765
made divx4 optional (also configure checking needed) and added avcodec_close
alex
parents:
3657
diff
changeset
|
1287 if (mux_v->codec == VCODEC_LIBAVCODEC) |
9092546e7765
made divx4 optional (also configure checking needed) and added avcodec_close
alex
parents:
3657
diff
changeset
|
1288 avcodec_close(&lavc_venc_context); |
9092546e7765
made divx4 optional (also configure checking needed) and added avcodec_close
alex
parents:
3657
diff
changeset
|
1289 #endif |
9092546e7765
made divx4 optional (also configure checking needed) and added avcodec_close
alex
parents:
3657
diff
changeset
|
1290 |
2840
808fe0767cf8
fix typos - patch by Colin Marquardt <colin@marquardt-home.de>
pl
parents:
2825
diff
changeset
|
1291 printf("\nWriting AVI index...\n"); |
2531 | 1292 aviwrite_write_index(muxer,muxer_f); |
2622 | 1293 printf("Fixup AVI header...\n"); |
2531 | 1294 fseek(muxer_f,0,SEEK_SET); |
1295 aviwrite_write_header(muxer,muxer_f); // update header | |
1296 fclose(muxer_f); | |
1297 | |
3361
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
1298 printf("\nVideo stream: %8.3f kbit/s (%d bps) size: %d bytes %5.3f secs\n", |
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
1299 (float)(mux_v->size/mux_v->timer*8.0f/1000.0f), (int)(mux_v->size/mux_v->timer), mux_v->size, (float)mux_v->timer); |
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
1300 if(sh_audio) |
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
1301 printf("\nAudio stream: %8.3f kbit/s (%d bps) size: %d bytes %5.3f secs\n", |
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
1302 (float)(mux_a->size/mux_a->timer*8.0f/1000.0f), (int)(mux_a->size/mux_a->timer), mux_a->size, (float)mux_a->timer); |
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
1303 |
2618 | 1304 if(stream) free_stream(stream); // kill cache thread |
1305 | |
3320
ac8b70dd5e45
use return 1; if interrupted - patch by Artur Skawina <skawina@geocities.com>
arpi
parents:
3240
diff
changeset
|
1306 return interrupted; |
2531 | 1307 } |