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