Mercurial > mplayer.hg
annotate mencoder.c @ 3363:1459912caea5
set all frames to keyframes for -ovc frameno - allow seeking in resulting audio-only avi
author | arpi |
---|---|
date | Fri, 07 Dec 2001 00:12:51 +0000 |
parents | fbf018a059e1 |
children | 4723f6fd750a |
rev | line source |
---|---|
2531 | 1 |
3361
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
2 #define VCODEC_FRAMENO 1 |
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
3 #define VCODEC_DIVX4 2 |
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
4 |
2583 | 5 #define ACODEC_PCM 1 |
6 #define ACODEC_VBRMP3 2 | |
2531 | 7 |
8 #include <stdio.h> | |
9 #include <stdlib.h> | |
10 #include <string.h> | |
11 #include <signal.h> | |
12 | |
2591 | 13 #include "config.h" |
2531 | 14 #include "mp_msg.h" |
2978 | 15 #include "version.h" |
2531 | 16 #include "help_mp.h" |
17 | |
2978 | 18 static char* banner_text= |
19 "\n\n" | |
20 "MEncoder " VERSION "(C) 2000-2001 Arpad Gereoffy (see DOCS!)\n" | |
21 "\n"; | |
22 | |
3323 | 23 #include "cpudetect.h" |
24 | |
25 | |
2531 | 26 #include "codec-cfg.h" |
27 | |
28 #include "stream.h" | |
29 #include "demuxer.h" | |
30 #include "stheader.h" | |
31 | |
32 #include "aviwrite.h" | |
33 | |
2897 | 34 #ifdef USE_LIBVO2 |
35 #include "libvo2/libvo2.h" | |
36 #else | |
2531 | 37 #include "libvo/video_out.h" |
2897 | 38 #endif |
2531 | 39 |
2574 | 40 #include "dec_audio.h" |
41 #include "dec_video.h" | |
42 | |
2531 | 43 #include <encore2.h> |
2643 | 44 #include "divx4_vbr.h" |
2531 | 45 |
3357 | 46 #ifdef HAVE_MP3LAME |
2591 | 47 #include <lame/lame.h> |
3357 | 48 #endif |
2583 | 49 |
3236 | 50 #include <inttypes.h> |
51 #include "../postproc/swscale.h" | |
52 | |
2583 | 53 //-------------------------- |
54 | |
2531 | 55 // cache2: |
2618 | 56 static int stream_cache_size=0; |
2531 | 57 #ifdef USE_STREAM_CACHE |
58 extern int cache_fill_status; | |
59 #else | |
60 #define cache_fill_status 0 | |
61 #endif | |
62 | |
2618 | 63 int vcd_track=0; |
64 int audio_id=-1; | |
65 int video_id=-1; | |
66 int dvdsub_id=-1; | |
67 | |
2531 | 68 char *audio_codec=NULL; // override audio codec |
69 char *video_codec=NULL; // override video codec | |
70 int audio_family=-1; // override audio codec family | |
71 int video_family=-1; // override video codec family | |
72 | |
3357 | 73 #ifdef HAVE_MP3LAME |
2661 | 74 int out_audio_codec=ACODEC_VBRMP3; |
3357 | 75 #else |
76 int out_audio_codec=ACODEC_PCM; | |
77 #endif | |
78 | |
2661 | 79 int out_video_codec=VCODEC_DIVX4; |
80 | |
2531 | 81 // audio stream skip/resync functions requires only for seeking. |
82 // (they should be implemented in the audio codec layer) | |
83 //void skip_audio_frame(sh_audio_t *sh_audio){} | |
84 //void resync_audio_stream(sh_audio_t *sh_audio){} | |
85 | |
2618 | 86 int verbose=0; // must be global! |
2531 | 87 |
88 double video_time_usage=0; | |
89 double vout_time_usage=0; | |
90 static double audio_time_usage=0; | |
91 static int total_time_usage_start=0; | |
92 static int benchmark=0; | |
93 | |
2605 | 94 // A-V sync: |
95 int delay_corrected=1; | |
96 static float default_max_pts_correction=-1;//0.01f; | |
97 static float max_pts_correction=0;//default_max_pts_correction; | |
98 static float c_total=0; | |
99 | |
2613 | 100 float force_fps=0; |
101 float force_ofps=0; // set to 24 for inverse telecine | |
2531 | 102 |
2618 | 103 int force_srate=0; |
104 | |
2626 | 105 char* out_filename="test.avi"; |
106 char* mp3_filename=NULL; | |
107 char* ac3_filename=NULL; | |
108 | |
2643 | 109 static int pass=0; |
110 static char* passtmpfile="divx2pass.log"; | |
111 | |
112 static int play_n_frames=-1; | |
113 | |
2661 | 114 //char *out_audio_codec=NULL; // override audio codec |
115 //char *out_video_codec=NULL; // override video codec | |
2626 | 116 |
2591 | 117 //#include "libmpeg2/mpeg2.h" |
118 //#include "libmpeg2/mpeg2_internal.h" | |
119 | |
2626 | 120 ENC_PARAM divx4_param; |
2643 | 121 int divx4_crispness=100; |
2626 | 122 |
3357 | 123 #ifdef HAVE_MP3LAME |
2626 | 124 int lame_param_quality=0; // best |
125 int lame_param_vbr=vbr_default; | |
126 int lame_param_mode=-1; // unset | |
127 int lame_param_padding=-1; // unset | |
128 int lame_param_br=-1; // unset | |
129 int lame_param_ratio=-1; // unset | |
3357 | 130 #endif |
2626 | 131 |
3236 | 132 static int scale_srcW=0; |
133 static int scale_srcH=0; | |
134 static int vo_w=0, vo_h=0; | |
2618 | 135 //-------------------------- config stuff: |
136 | |
137 #include "cfgparser.h" | |
138 | |
139 static int cfg_inc_verbose(struct config *conf){ ++verbose; return 0;} | |
140 | |
141 static int cfg_include(struct config *conf, char *filename){ | |
142 return parse_config_file(conf, filename); | |
143 } | |
144 | |
145 #include "get_path.c" | |
146 | |
147 #include "cfg-mplayer-def.h" | |
148 #include "cfg-mencoder.h" | |
149 | |
2591 | 150 //--------------------------------------------------------------------------- |
151 | |
2627 | 152 // dummy datas for gui :( |
153 | |
154 #ifdef HAVE_NEW_GUI | |
155 float rel_seek_secs=0; | |
156 int abs_seek_pos=0; | |
157 int use_gui=0; | |
158 | |
159 void exit_player(char* how){ | |
160 } | |
161 void vo_x11_putkey(int key){ | |
162 } | |
163 void vo_setwindow( int w,int g ) { | |
164 } | |
165 void vo_setwindowsize( int w,int h ) { | |
166 } | |
167 | |
168 int vo_resize = 0; | |
169 int vo_expose = 0; | |
170 | |
171 #endif | |
172 // --- | |
173 | |
2591 | 174 // mini dummy libvo: |
2531 | 175 |
176 static unsigned char* vo_image=NULL; | |
177 static unsigned char* vo_image_ptr=NULL; | |
178 | |
179 static uint32_t draw_slice(uint8_t *src[], int stride[], int w,int h, int x0,int y0){ | |
180 int y; | |
3236 | 181 // printf("draw_slice %dx%d %d;%d\n",w,h,x0,y0); |
182 if(scale_srcW) | |
183 { | |
184 uint8_t* dstPtr[3]= { | |
185 vo_image, | |
186 vo_image + vo_w*vo_h*5/4, | |
187 vo_image + vo_w*vo_h}; | |
188 SwScale_YV12slice(src, stride, y0, h, dstPtr, vo_w, 12, scale_srcW, scale_srcH, vo_w, vo_h); | |
189 } | |
190 else | |
191 { | |
2531 | 192 // copy Y: |
193 for(y=0;y<h;y++){ | |
2639 | 194 unsigned char* s=src[0]+stride[0]*y; |
2531 | 195 unsigned char* d=vo_image+vo_w*(y0+y)+x0; |
196 memcpy(d,s,w); | |
197 } | |
198 x0>>=1;y0>>=1; | |
199 w>>=1;h>>=1; | |
200 // copy U: | |
201 for(y=0;y<h;y++){ | |
2639 | 202 unsigned char* s=src[2]+stride[2]*y; |
2531 | 203 unsigned char* d=vo_image+vo_w*vo_h+(vo_w>>1)*(y0+y)+x0; |
204 memcpy(d,s,w); | |
205 } | |
206 // copy V: | |
207 for(y=0;y<h;y++){ | |
2639 | 208 unsigned char* s=src[1]+stride[1]*y; |
2531 | 209 unsigned char* d=vo_image+vo_w*vo_h+vo_w*vo_h/4+(vo_w>>1)*(y0+y)+x0; |
210 memcpy(d,s,w); | |
211 } | |
3236 | 212 } // !swscaler |
2531 | 213 } |
214 | |
215 static uint32_t draw_frame(uint8_t *src[]){ | |
216 // printf("This function shouldn't be called - report bug!\n"); | |
217 // later: add YUY2->YV12 conversion here! | |
218 vo_image_ptr=src[0]; | |
219 } | |
220 | |
221 vo_functions_t video_out; | |
222 | |
2591 | 223 //--------------------------------------------------------------------------- |
224 | |
225 int dec_audio(sh_audio_t *sh_audio,unsigned char* buffer,int total){ | |
226 int size=0; | |
227 int eof=0; | |
228 while(size<total && !eof){ | |
229 int len=total-size; | |
230 if(len>MAX_OUTBURST) len=MAX_OUTBURST; | |
231 if(len>sh_audio->a_buffer_size) len=sh_audio->a_buffer_size; | |
232 if(len>sh_audio->a_buffer_len){ | |
233 int ret=decode_audio(sh_audio, | |
234 &sh_audio->a_buffer[sh_audio->a_buffer_len], | |
235 len-sh_audio->a_buffer_len, | |
236 sh_audio->a_buffer_size-sh_audio->a_buffer_len); | |
237 if(ret>0) sh_audio->a_buffer_len+=ret; else eof=1; | |
238 } | |
239 if(len>sh_audio->a_buffer_len) len=sh_audio->a_buffer_len; | |
240 memcpy(buffer+size,sh_audio->a_buffer,len); | |
241 sh_audio->a_buffer_len-=len; size+=len; | |
242 if(sh_audio->a_buffer_len>0) | |
243 memcpy(sh_audio->a_buffer,&sh_audio->a_buffer[len],sh_audio->a_buffer_len); | |
244 } | |
245 return size; | |
246 } | |
247 | |
248 //--------------------------------------------------------------------------- | |
2531 | 249 |
250 static int eof=0; | |
3320
ac8b70dd5e45
use return 1; if interrupted - patch by Artur Skawina <skawina@geocities.com>
arpi
parents:
3240
diff
changeset
|
251 static int interrupted=0; |
2531 | 252 |
253 static void exit_sighandler(int x){ | |
254 eof=1; | |
3320
ac8b70dd5e45
use return 1; if interrupted - patch by Artur Skawina <skawina@geocities.com>
arpi
parents:
3240
diff
changeset
|
255 interrupted=1; |
2531 | 256 } |
257 | |
2618 | 258 int main(int argc,char* argv[], char *envp[]){ |
2531 | 259 |
260 stream_t* stream=NULL; | |
261 demuxer_t* demuxer=NULL; | |
262 demux_stream_t *d_audio=NULL; | |
263 demux_stream_t *d_video=NULL; | |
264 demux_stream_t *d_dvdsub=NULL; | |
265 sh_audio_t *sh_audio=NULL; | |
266 sh_video_t *sh_video=NULL; | |
267 int file_format=DEMUXER_TYPE_UNKNOWN; | |
268 int i; | |
269 unsigned int out_fmt; | |
270 | |
271 aviwrite_t* muxer=NULL; | |
272 aviwrite_stream_t* mux_a=NULL; | |
273 aviwrite_stream_t* mux_v=NULL; | |
274 FILE* muxer_f=NULL; | |
275 | |
276 ENC_FRAME enc_frame; | |
277 ENC_RESULT enc_result; | |
278 void* enc_handle=NULL; | |
279 | |
3357 | 280 #ifdef HAVE_MP3LAME |
2591 | 281 lame_global_flags *lame; |
3357 | 282 #endif |
2583 | 283 |
2653 | 284 float audio_preload=0.5; |
2581 | 285 |
2613 | 286 double v_pts_corr=0; |
287 double v_timer_corr=0; | |
2605 | 288 |
2618 | 289 char** filenames=NULL; |
290 char* filename=NULL; | |
291 int num_filenames; | |
292 | |
3361
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
293 int decoded_frameno=0; |
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
294 |
2531 | 295 //int out_buffer_size=0x200000; |
296 //unsigned char* out_buffer=malloc(out_buffer_size); | |
297 | |
2622 | 298 mp_msg_init(MSGL_STATUS); |
2978 | 299 mp_msg(MSGT_CPLAYER,MSGL_INFO,"%s",banner_text); |
2622 | 300 |
301 // check codec.conf | |
302 if(!parse_codec_cfg(get_path("codecs.conf"))){ | |
303 if(!parse_codec_cfg(DATADIR"/codecs.conf")){ | |
304 mp_msg(MSGT_MENCODER,MSGL_HINT,MSGTR_CopyCodecsConf); | |
305 exit(0); | |
306 } | |
307 } | |
2531 | 308 |
3323 | 309 /* Test for cpu capabilities (and corresponding OS support) for optimizing */ |
310 #ifdef ARCH_X86 | |
311 GetCpuCaps(&gCpuCaps); | |
312 mp_msg(MSGT_CPLAYER,MSGL_INFO,"CPUflags: Type: %d MMX: %d MMX2: %d 3DNow: %d 3DNow2: %d SSE: %d SSE2: %d\n", | |
313 gCpuCaps.cpuType,gCpuCaps.hasMMX,gCpuCaps.hasMMX2, | |
314 gCpuCaps.has3DNow, gCpuCaps.has3DNowExt, | |
315 gCpuCaps.hasSSE, gCpuCaps.hasSSE2); | |
316 #endif | |
317 | |
318 | |
2643 | 319 // set some defaults, before parsing configfile/commandline: |
320 divx4_param.min_quantizer = 2; | |
321 divx4_param.max_quantizer = 31; | |
322 divx4_param.rc_period = 2000; | |
323 divx4_param.rc_reaction_period = 10; | |
324 divx4_param.rc_reaction_ratio = 20; | |
325 | |
326 | |
2618 | 327 num_filenames=parse_command_line(conf, argc, argv, envp, &filenames); |
328 if(num_filenames<0) exit(1); // error parsing cmdline | |
329 if(!num_filenames && !vcd_track && !dvd_title){ | |
330 printf("\nMissing filename!\n\n"); | |
331 exit(1); | |
332 } | |
333 | |
2622 | 334 mp_msg_init(verbose+MSGL_STATUS); |
2600 | 335 |
2618 | 336 filename=(num_filenames>0)?filenames[0]:NULL; |
337 stream=open_stream(filename,vcd_track,&file_format); | |
2531 | 338 |
339 if(!stream){ | |
340 printf("Cannot open file/device\n"); | |
341 exit(1); | |
342 } | |
343 | |
344 printf("success: format: %d data: 0x%X - 0x%X\n",file_format, (int)(stream->start_pos),(int)(stream->end_pos)); | |
345 | |
2618 | 346 if(stream_cache_size) stream_enable_cache(stream,stream_cache_size*1024); |
2531 | 347 |
2882 | 348 //demuxer=demux_open(stream,file_format,video_id,audio_id,dvdsub_id); |
349 demuxer=demux_open(stream,file_format,audio_id,video_id,dvdsub_id); | |
2531 | 350 if(!demuxer){ |
351 printf("Cannot open demuxer\n"); | |
352 exit(1); | |
353 } | |
354 | |
355 d_audio=demuxer->audio; | |
356 d_video=demuxer->video; | |
357 d_dvdsub=demuxer->sub; | |
358 sh_audio=d_audio->sh; | |
359 sh_video=d_video->sh; | |
360 | |
361 if(!video_read_properties(sh_video)){ | |
362 printf("Couldn't read video properties\n"); | |
363 exit(1); | |
364 } | |
365 | |
2622 | 366 mp_msg(MSGT_MENCODER,MSGL_INFO,"[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.2f ftime:=%6.4f\n", |
2531 | 367 demuxer->file_format,sh_video->format, sh_video->disp_w,sh_video->disp_h, |
368 sh_video->fps,sh_video->frametime | |
369 ); | |
370 | |
371 | |
372 sh_video->codec=NULL; | |
3361
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
373 if(out_video_codec>1){ |
2884 | 374 |
2622 | 375 if(video_family!=-1) mp_msg(MSGT_MENCODER,MSGL_INFO,MSGTR_TryForceVideoFmt,video_family); |
2531 | 376 while(1){ |
377 sh_video->codec=find_codec(sh_video->format, | |
378 sh_video->bih?((unsigned int*) &sh_video->bih->biCompression):NULL,sh_video->codec,0); | |
379 if(!sh_video->codec){ | |
380 if(video_family!=-1) { | |
381 sh_video->codec=NULL; /* re-search */ | |
2622 | 382 mp_msg(MSGT_MENCODER,MSGL_WARN,MSGTR_CantFindVfmtFallback); |
2531 | 383 video_family=-1; |
384 continue; | |
385 } | |
2622 | 386 mp_msg(MSGT_MENCODER,MSGL_ERR,MSGTR_CantFindVideoCodec,sh_video->format); |
387 mp_msg(MSGT_MENCODER,MSGL_HINT, MSGTR_TryUpgradeCodecsConfOrRTFM,get_path("codecs.conf")); | |
2531 | 388 exit(1); |
389 } | |
390 if(video_codec && strcmp(sh_video->codec->name,video_codec)) continue; | |
391 else if(video_family!=-1 && sh_video->codec->driver!=video_family) continue; | |
392 break; | |
393 } | |
394 | |
2622 | 395 mp_msg(MSGT_MENCODER,MSGL_INFO,"%s video codec: [%s] drv:%d (%s)\n",video_codec?"Forcing":"Detected",sh_video->codec->name,sh_video->codec->driver,sh_video->codec->info); |
2531 | 396 |
397 for(i=0;i<CODECS_MAX_OUTFMT;i++){ | |
398 out_fmt=sh_video->codec->outfmt[i]; | |
399 if(out_fmt==0xFFFFFFFF) continue; | |
400 if(out_fmt==IMGFMT_YV12) break; | |
401 if(out_fmt==IMGFMT_I420) break; | |
402 if(out_fmt==IMGFMT_IYUV) break; | |
403 if(out_fmt==IMGFMT_YUY2) break; | |
2825 | 404 if(out_fmt==IMGFMT_UYVY) break; |
2531 | 405 } |
406 if(i>=CODECS_MAX_OUTFMT){ | |
2622 | 407 mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_VOincompCodec); |
2531 | 408 exit(1); // exit_player(MSGTR_Exit_error); |
409 } | |
410 sh_video->outfmtidx=i; | |
411 | |
3240 | 412 if(out_fmt==IMGFMT_YV12 && (vo_w!=0 || vo_h!=0)) |
3236 | 413 { |
414 scale_srcW= sh_video->disp_w; | |
415 scale_srcH= sh_video->disp_h; | |
3240 | 416 if(!vo_w) vo_w=sh_video->disp_w; |
417 if(!vo_h) vo_h=sh_video->disp_h; | |
3236 | 418 } |
419 else | |
420 { | |
421 vo_w=sh_video->disp_w; | |
422 vo_h=sh_video->disp_h; | |
423 } | |
424 | |
2531 | 425 if(out_fmt==IMGFMT_YV12 || out_fmt==IMGFMT_I420 || out_fmt==IMGFMT_IYUV){ |
426 vo_image=malloc(vo_w*vo_h*3/2); | |
427 vo_image_ptr=vo_image; | |
428 } | |
429 | |
430 if(!init_video(sh_video)){ | |
2622 | 431 mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_CouldntInitVideoCodec); |
2531 | 432 exit(1); |
433 } | |
434 | |
2884 | 435 } // if(out_video_codec) |
2581 | 436 |
437 if(sh_audio){ | |
438 // Go through the codec.conf and find the best codec... | |
439 sh_audio->codec=NULL; | |
2622 | 440 if(audio_family!=-1) mp_msg(MSGT_MENCODER,MSGL_INFO,MSGTR_TryForceAudioFmt,audio_family); |
2581 | 441 while(1){ |
442 sh_audio->codec=find_codec(sh_audio->format,NULL,sh_audio->codec,1); | |
443 if(!sh_audio->codec){ | |
444 if(audio_family!=-1) { | |
445 sh_audio->codec=NULL; /* re-search */ | |
2622 | 446 mp_msg(MSGT_MENCODER,MSGL_ERR,MSGTR_CantFindAfmtFallback); |
2581 | 447 audio_family=-1; |
448 continue; | |
449 } | |
2622 | 450 mp_msg(MSGT_MENCODER,MSGL_ERR,MSGTR_CantFindAudioCodec,sh_audio->format); |
451 mp_msg(MSGT_MENCODER,MSGL_HINT, MSGTR_TryUpgradeCodecsConfOrRTFM,get_path("codecs.conf")); | |
2581 | 452 sh_audio=d_audio->sh=NULL; |
453 break; | |
454 } | |
455 if(audio_codec && strcmp(sh_audio->codec->name,audio_codec)) continue; | |
456 else if(audio_family!=-1 && sh_audio->codec->driver!=audio_family) continue; | |
2622 | 457 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 | 458 break; |
459 } | |
460 } | |
461 | |
462 if(sh_audio){ | |
2622 | 463 mp_msg(MSGT_MENCODER,MSGL_V,"Initializing audio codec...\n"); |
2581 | 464 if(!init_audio(sh_audio)){ |
2622 | 465 mp_msg(MSGT_MENCODER,MSGL_ERR,MSGTR_CouldntInitAudioCodec); |
2581 | 466 sh_audio=d_audio->sh=NULL; |
467 } else { | |
2622 | 468 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 | 469 sh_audio->sample_format,sh_audio->i_bps,sh_audio->o_bps); |
470 } | |
471 } | |
472 | |
473 | |
474 | |
2531 | 475 // set up video encoder: |
3236 | 476 SwScale_Init(); |
2531 | 477 video_out.draw_slice=draw_slice; |
478 video_out.draw_frame=draw_frame; | |
479 | |
480 // set up output file: | |
2626 | 481 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
|
482 if(!muxer_f) { |
bc648c6a464a
fixes a segfault if file specified in -o can't be accessed
pl
parents:
2884
diff
changeset
|
483 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
|
484 exit(1); |
bc648c6a464a
fixes a segfault if file specified in -o can't be accessed
pl
parents:
2884
diff
changeset
|
485 } |
bc648c6a464a
fixes a segfault if file specified in -o can't be accessed
pl
parents:
2884
diff
changeset
|
486 |
2531 | 487 muxer=aviwrite_new_muxer(); |
2581 | 488 |
489 // ============= VIDEO =============== | |
490 | |
2531 | 491 mux_v=aviwrite_new_stream(muxer,AVIWRITE_TYPE_VIDEO); |
492 | |
493 mux_v->buffer_size=0x200000; | |
494 mux_v->buffer=malloc(mux_v->buffer_size); | |
495 | |
496 mux_v->source=sh_video; | |
497 | |
498 mux_v->h.dwSampleSize=0; // VBR | |
499 mux_v->h.dwScale=10000; | |
2613 | 500 mux_v->h.dwRate=mux_v->h.dwScale*(force_ofps?force_ofps:sh_video->fps); |
2531 | 501 |
2661 | 502 mux_v->codec=out_video_codec; |
2574 | 503 |
2531 | 504 switch(mux_v->codec){ |
505 case 0: | |
506 mux_v->bih=sh_video->bih; | |
507 break; | |
3361
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
508 case VCODEC_FRAMENO: |
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
509 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
|
510 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
|
511 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
|
512 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
|
513 mux_v->bih->biPlanes=1; |
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
514 mux_v->bih->biBitCount=24; |
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
515 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
|
516 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
|
517 break; |
2531 | 518 case VCODEC_DIVX4: |
519 mux_v->bih=malloc(sizeof(BITMAPINFOHEADER)); | |
520 mux_v->bih->biSize=sizeof(BITMAPINFOHEADER); | |
3236 | 521 mux_v->bih->biWidth=vo_w; |
522 mux_v->bih->biHeight=vo_h; | |
2635
c1e24e01601b
fixed AVI header creation - now should be compatible with NaNdub
arpi
parents:
2627
diff
changeset
|
523 mux_v->bih->biPlanes=1; |
2531 | 524 mux_v->bih->biBitCount=24; |
525 mux_v->bih->biCompression=mmioFOURCC('d','i','v','x'); | |
526 mux_v->bih->biSizeImage=mux_v->bih->biWidth*mux_v->bih->biHeight*(mux_v->bih->biBitCount/8); | |
527 break; | |
528 } | |
529 | |
2581 | 530 // ============= AUDIO =============== |
531 if(sh_audio){ | |
532 | |
533 mux_a=aviwrite_new_stream(muxer,AVIWRITE_TYPE_AUDIO); | |
534 | |
535 mux_a->buffer_size=0x100000; //16384; | |
536 mux_a->buffer=malloc(mux_a->buffer_size); | |
537 | |
538 mux_a->source=sh_audio; | |
539 | |
2661 | 540 mux_a->codec=out_audio_codec; |
2581 | 541 |
542 switch(mux_a->codec){ | |
543 case 0: | |
544 mux_a->h.dwSampleSize=sh_audio->audio.dwSampleSize; | |
545 mux_a->h.dwScale=sh_audio->audio.dwScale; | |
546 mux_a->h.dwRate=sh_audio->audio.dwRate; | |
547 mux_a->wf=sh_audio->wf; | |
548 break; | |
2583 | 549 case ACODEC_PCM: |
550 printf("CBR PCM audio selected\n"); | |
551 mux_a->h.dwSampleSize=2*sh_audio->channels; | |
552 mux_a->h.dwScale=1; | |
553 mux_a->h.dwRate=sh_audio->samplerate; | |
554 mux_a->wf=malloc(sizeof(WAVEFORMATEX)); | |
555 mux_a->wf->nBlockAlign=mux_a->h.dwSampleSize; | |
556 mux_a->wf->wFormatTag=0x1; // PCM | |
557 mux_a->wf->nChannels=sh_audio->channels; | |
558 mux_a->wf->nSamplesPerSec=sh_audio->samplerate; | |
559 mux_a->wf->nAvgBytesPerSec=mux_a->h.dwSampleSize*mux_a->wf->nSamplesPerSec; | |
560 mux_a->wf->wBitsPerSample=16; | |
561 mux_a->wf->cbSize=0; // FIXME for l3codeca.acm | |
562 break; | |
2581 | 563 case ACODEC_VBRMP3: |
564 mux_a->h.dwSampleSize=0; // VBR | |
2653 | 565 mux_a->h.dwScale=1152; // samples/frame |
2581 | 566 mux_a->h.dwRate=sh_audio->samplerate; |
2635
c1e24e01601b
fixed AVI header creation - now should be compatible with NaNdub
arpi
parents:
2627
diff
changeset
|
567 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
|
568 mux_a->wf=malloc(sizeof(MPEGLAYER3WAVEFORMAT)); // should be 30 |
2581 | 569 mux_a->wf->wFormatTag=0x55; // MP3 |
570 mux_a->wf->nChannels=sh_audio->channels; | |
2639 | 571 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
|
572 mux_a->wf->nAvgBytesPerSec=192000/8; // FIXME! |
2653 | 573 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
|
574 mux_a->wf->wBitsPerSample=0; //16; |
c1e24e01601b
fixed AVI header creation - now should be compatible with NaNdub
arpi
parents:
2627
diff
changeset
|
575 // from NaNdub: (requires for l3codeca.acm) |
c1e24e01601b
fixed AVI header creation - now should be compatible with NaNdub
arpi
parents:
2627
diff
changeset
|
576 mux_a->wf->cbSize=12; |
c1e24e01601b
fixed AVI header creation - now should be compatible with NaNdub
arpi
parents:
2627
diff
changeset
|
577 ((MPEGLAYER3WAVEFORMAT*)(mux_a->wf))->wID=1; |
c1e24e01601b
fixed AVI header creation - now should be compatible with NaNdub
arpi
parents:
2627
diff
changeset
|
578 ((MPEGLAYER3WAVEFORMAT*)(mux_a->wf))->fdwFlags=2; |
2653 | 579 ((MPEGLAYER3WAVEFORMAT*)(mux_a->wf))->nBlockSize=1152; // ??? |
2635
c1e24e01601b
fixed AVI header creation - now should be compatible with NaNdub
arpi
parents:
2627
diff
changeset
|
580 ((MPEGLAYER3WAVEFORMAT*)(mux_a->wf))->nFramesPerBlock=1; |
c1e24e01601b
fixed AVI header creation - now should be compatible with NaNdub
arpi
parents:
2627
diff
changeset
|
581 ((MPEGLAYER3WAVEFORMAT*)(mux_a->wf))->nCodecDelay=0; |
2581 | 582 break; |
583 } | |
584 } | |
585 | |
2840
808fe0767cf8
fix typos - patch by Colin Marquardt <colin@marquardt-home.de>
pl
parents:
2825
diff
changeset
|
586 printf("Writing AVI header...\n"); |
2531 | 587 aviwrite_write_header(muxer,muxer_f); |
588 | |
589 switch(mux_v->codec){ | |
590 case 0: | |
591 break; | |
3361
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
592 case VCODEC_FRAMENO: |
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
593 decoded_frameno=0; |
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
594 break; |
2531 | 595 case VCODEC_DIVX4: |
596 // init divx4linux: | |
3236 | 597 divx4_param.x_dim=vo_w; |
598 divx4_param.y_dim=vo_h; | |
2626 | 599 divx4_param.framerate=(float)mux_v->h.dwRate/mux_v->h.dwScale; |
600 if(!divx4_param.bitrate) divx4_param.bitrate=800000; | |
601 else if(divx4_param.bitrate<=16000) divx4_param.bitrate*=1000; | |
602 if(!divx4_param.quality) divx4_param.quality=5; // the quality of compression ( 1 - fastest, 5 - best ) | |
603 divx4_param.handle=NULL; | |
604 encore(NULL,ENC_OPT_INIT,&divx4_param,NULL); | |
605 enc_handle=divx4_param.handle; | |
2643 | 606 switch(out_fmt){ |
607 case IMGFMT_YV12: enc_frame.colorspace=ENC_CSP_YV12; break; | |
608 case IMGFMT_IYUV: | |
609 case IMGFMT_I420: enc_frame.colorspace=ENC_CSP_I420; break; | |
610 case IMGFMT_YUY2: enc_frame.colorspace=ENC_CSP_YUY2; break; | |
611 case IMGFMT_UYVY: enc_frame.colorspace=ENC_CSP_UYVY; break; | |
612 case IMGFMT_RGB24: | |
613 case IMGFMT_BGR24: | |
614 enc_frame.colorspace=ENC_CSP_RGB24; break; | |
615 default: | |
616 mp_msg(MSGT_MENCODER,MSGL_ERR,"divx4: unsupported out_fmt!\n"); | |
617 } | |
618 switch(pass){ | |
619 case 1: | |
620 VbrControl_init_2pass_vbr_analysis(passtmpfile, divx4_param.quality); | |
621 break; | |
622 case 2: | |
623 VbrControl_init_2pass_vbr_encoding(passtmpfile, | |
624 divx4_param.bitrate, | |
625 divx4_param.framerate, | |
626 divx4_crispness, | |
627 divx4_param.quality); | |
628 break; | |
629 } | |
2531 | 630 break; |
631 } | |
632 | |
2600 | 633 if(sh_audio) |
2583 | 634 switch(mux_a->codec){ |
3357 | 635 #ifdef HAVE_MP3LAME |
2583 | 636 case ACODEC_VBRMP3: |
637 | |
638 lame=lame_init(); | |
2591 | 639 lame_set_bWriteVbrTag(lame,0); |
2583 | 640 lame_set_in_samplerate(lame,sh_audio->samplerate); |
641 lame_set_num_channels(lame,mux_a->wf->nChannels); | |
2639 | 642 lame_set_out_samplerate(lame,mux_a->wf->nSamplesPerSec); |
2626 | 643 if(lame_param_vbr){ // VBR: |
644 lame_set_VBR(lame,lame_param_vbr); // vbr mode | |
645 lame_set_VBR_q(lame,lame_param_quality+1); // 1 = best vbr q 6=~128k | |
646 if(lame_param_br>0) lame_set_VBR_mean_bitrate_kbps(lame,lame_param_br); | |
647 } else { // CBR: | |
648 lame_set_quality(lame,lame_param_quality); // 0 = best q | |
649 if(lame_param_br>0) lame_set_brate(lame,lame_param_br); | |
650 } | |
651 if(lame_param_mode>=0) lame_set_mode(lame,lame_param_mode); // j-st | |
652 if(lame_param_ratio>0) lame_set_compression_ratio(lame,lame_param_ratio); | |
2583 | 653 lame_init_params(lame); |
2622 | 654 if(verbose){ |
2626 | 655 lame_print_config(lame); |
656 lame_print_internals(lame); | |
2622 | 657 } |
3357 | 658 break; |
659 #endif | |
2583 | 660 |
661 } | |
662 | |
2531 | 663 signal(SIGINT,exit_sighandler); // Interrupt from keyboard |
664 signal(SIGQUIT,exit_sighandler); // Quit from keyboard | |
665 signal(SIGTERM,exit_sighandler); // kill | |
666 | |
667 while(!eof){ | |
668 | |
2571 | 669 float frame_time=0; |
2531 | 670 int blit_frame=0; |
671 float a_pts=0; | |
672 float v_pts=0; | |
2574 | 673 unsigned char* start=NULL; |
674 int in_size; | |
2613 | 675 int skip_flag=0; // 1=skip -1=duplicate |
2531 | 676 |
2643 | 677 if(play_n_frames>=0){ |
678 --play_n_frames; | |
679 if(play_n_frames<0) break; | |
680 } | |
681 | |
2581 | 682 if(sh_audio){ |
683 // get audio: | |
2583 | 684 while(mux_a->timer-audio_preload<mux_v->timer){ |
2653 | 685 int len=0; |
2581 | 686 if(mux_a->h.dwSampleSize){ |
2605 | 687 // CBR - copy 0.5 sec of audio |
2583 | 688 switch(mux_a->codec){ |
689 case 0: // copy | |
690 len=sh_audio->i_bps/2; | |
691 len/=mux_a->h.dwSampleSize;if(len<1) len=1; | |
692 len*=mux_a->h.dwSampleSize; | |
693 len=demux_read_data(sh_audio->ds,mux_a->buffer,len); | |
694 break; | |
695 case ACODEC_PCM: | |
696 len=mux_a->h.dwSampleSize*(mux_a->h.dwRate/2); | |
2591 | 697 len=dec_audio(sh_audio,mux_a->buffer,len); |
2583 | 698 break; |
699 } | |
2581 | 700 } else { |
2605 | 701 // VBR - encode/copy an audio frame |
702 switch(mux_a->codec){ | |
703 case 0: // copy | |
704 printf("not yet implemented!\n"); | |
705 break; | |
3357 | 706 #ifdef HAVE_MP3LAME |
2605 | 707 case ACODEC_VBRMP3: |
2591 | 708 while(mux_a->buffer_len<4){ |
709 unsigned char tmp[2304]; | |
710 int len=dec_audio(sh_audio,tmp,2304); | |
711 if(len<=0) break; // eof | |
712 len=lame_encode_buffer_interleaved(lame, | |
713 tmp,len/4, | |
714 mux_a->buffer+mux_a->buffer_len,mux_a->buffer_size-mux_a->buffer_len); | |
715 if(len<0) break; // error | |
716 mux_a->buffer_len+=len; | |
717 } | |
718 if(mux_a->buffer_len<4) break; | |
719 len=mp_decode_mp3_header(mux_a->buffer); | |
2639 | 720 //printf("%d\n",len); |
2591 | 721 if(len<=0) break; // bad frame! |
722 while(mux_a->buffer_len<len){ | |
723 unsigned char tmp[2304]; | |
724 int len=dec_audio(sh_audio,tmp,2304); | |
725 if(len<=0) break; // eof | |
726 len=lame_encode_buffer_interleaved(lame, | |
727 tmp,len/4, | |
728 mux_a->buffer+mux_a->buffer_len,mux_a->buffer_size-mux_a->buffer_len); | |
729 if(len<0) break; // error | |
730 mux_a->buffer_len+=len; | |
731 } | |
2605 | 732 break; |
3357 | 733 #endif |
2605 | 734 } |
2581 | 735 } |
2583 | 736 if(len<=0) break; // EOF? |
737 aviwrite_write_chunk(muxer,mux_a,muxer_f,len,0); | |
2655 | 738 if(!mux_a->h.dwSampleSize && mux_a->timer>0) |
3354 | 739 mux_a->wf->nAvgBytesPerSec=0.5f+(double)mux_a->size/mux_a->timer; // avg bps (VBR) |
2591 | 740 if(mux_a->buffer_len>=len){ |
741 mux_a->buffer_len-=len; | |
742 memcpy(mux_a->buffer,mux_a->buffer+len,mux_a->buffer_len); | |
743 } | |
2581 | 744 } |
745 } | |
746 | |
747 // get video frame! | |
748 in_size=video_read_frame(sh_video,&frame_time,&start,force_fps); | |
749 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
|
750 sh_video->timer+=frame_time; ++decoded_frameno; |
2613 | 751 |
752 v_timer_corr-=frame_time-(float)mux_v->h.dwScale/mux_v->h.dwRate; | |
2531 | 753 |
2613 | 754 // check frame duplicate/drop: |
755 | |
756 if(v_timer_corr>=(float)mux_v->h.dwScale/mux_v->h.dwRate){ | |
757 v_timer_corr-=(float)mux_v->h.dwScale/mux_v->h.dwRate; | |
758 ++skip_flag; // skip | |
759 } else | |
760 while(v_timer_corr<=-(float)mux_v->h.dwScale/mux_v->h.dwRate){ | |
761 v_timer_corr+=(float)mux_v->h.dwScale/mux_v->h.dwRate; | |
762 --skip_flag; // dup | |
763 } | |
2531 | 764 |
2613 | 765 while( (v_pts_corr<=-(float)mux_v->h.dwScale/mux_v->h.dwRate && skip_flag>0) |
766 || (v_pts_corr<=-2*(float)mux_v->h.dwScale/mux_v->h.dwRate) ){ | |
767 v_pts_corr+=(float)mux_v->h.dwScale/mux_v->h.dwRate; | |
768 --skip_flag; // dup | |
769 } | |
770 if( (v_pts_corr>=(float)mux_v->h.dwScale/mux_v->h.dwRate && skip_flag<0) | |
771 || (v_pts_corr>=2*(float)mux_v->h.dwScale/mux_v->h.dwRate) ) | |
772 if(skip_flag<=0){ // we can't skip more than 1 frame now | |
773 v_pts_corr-=(float)mux_v->h.dwScale/mux_v->h.dwRate; | |
774 ++skip_flag; // skip | |
775 } | |
776 | |
777 | |
2531 | 778 switch(mux_v->codec){ |
2574 | 779 case 0: |
780 mux_v->buffer=start; | |
2639 | 781 if(skip_flag<=0) aviwrite_write_chunk(muxer,mux_v,muxer_f,in_size,(sh_video->ds->flags&1)?0x10:0); |
2574 | 782 break; |
3361
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
783 case VCODEC_FRAMENO: |
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
784 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
|
785 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
|
786 break; |
2531 | 787 case VCODEC_DIVX4: |
2574 | 788 blit_frame=decode_video(&video_out,sh_video,start,in_size,0); |
2639 | 789 if(skip_flag>0) break; |
2574 | 790 if(!blit_frame){ |
791 // empty. | |
792 aviwrite_write_chunk(muxer,mux_v,muxer_f,0,0); | |
793 break; | |
794 } | |
2531 | 795 enc_frame.image=vo_image_ptr; |
796 enc_frame.bitstream=mux_v->buffer; | |
797 enc_frame.length=mux_v->buffer_size; | |
2643 | 798 enc_frame.mvs=NULL; |
2531 | 799 enc_frame.quant=0; |
800 enc_frame.intra=0; | |
2643 | 801 if(pass==2){ // handle 2-pass: |
802 enc_frame.quant = VbrControl_get_quant(); | |
803 enc_frame.intra = VbrControl_get_intra(); | |
804 encore(enc_handle,ENC_OPT_ENCODE_VBR,&enc_frame,&enc_result); | |
805 VbrControl_update_2pass_vbr_encoding(enc_result.motion_bits, | |
806 enc_result.texture_bits, | |
807 enc_result.total_bits); | |
808 } else { | |
809 encore(enc_handle,ENC_OPT_ENCODE,&enc_frame,&enc_result); | |
810 if(pass==1){ | |
811 VbrControl_update_2pass_vbr_analysis(enc_result.is_key_frame, | |
812 enc_result.motion_bits, | |
813 enc_result.texture_bits, | |
814 enc_result.total_bits, | |
815 enc_result.quantizer); | |
816 } | |
817 } | |
818 | |
2531 | 819 // printf("encoding...\n"); |
820 // printf(" len=%d key:%d qualt:%d \n",enc_frame.length,enc_result.is_key_frame,enc_result.quantizer); | |
821 aviwrite_write_chunk(muxer,mux_v,muxer_f,enc_frame.length,enc_result.is_key_frame?0x10:0); | |
822 break; | |
823 } | |
2613 | 824 |
825 if(skip_flag<0){ | |
2605 | 826 // duplicate frame |
2613 | 827 printf("\nduplicate %d frame(s)!!! \n",-skip_flag); |
828 while(skip_flag<0){ | |
829 aviwrite_write_chunk(muxer,mux_v,muxer_f,0,0); | |
830 ++skip_flag; | |
831 } | |
2639 | 832 } else |
833 if(skip_flag>0){ | |
2605 | 834 // skip frame |
835 printf("\nskip frame!!! \n"); | |
2613 | 836 --skip_flag; |
2605 | 837 } |
838 | |
839 if(sh_audio){ | |
840 float AV_delay,x; | |
841 // A-V sync! | |
842 if(pts_from_bps){ | |
843 unsigned int samples=(sh_audio->audio.dwSampleSize)? | |
844 ((ds_tell(d_audio)-sh_audio->a_in_buffer_len)/sh_audio->audio.dwSampleSize) : | |
845 (d_audio->pack_no); // <- used for VBR audio | |
846 a_pts=samples*(float)sh_audio->audio.dwScale/(float)sh_audio->audio.dwRate; | |
847 delay_corrected=1; | |
848 } else { | |
849 // PTS = (last timestamp) + (bytes after last timestamp)/(bytes per sec) | |
850 a_pts=d_audio->pts; | |
851 if(!delay_corrected) if(a_pts) delay_corrected=1; | |
852 //printf("*** %5.3f ***\n",a_pts); | |
853 a_pts+=(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps; | |
854 } | |
855 v_pts=d_video->pts; | |
856 // av = compensated (with out buffering delay) A-V diff | |
2613 | 857 AV_delay=(a_pts-v_pts); AV_delay-=mux_a->timer-(mux_v->timer-(v_timer_corr+v_pts_corr)); |
2605 | 858 // compensate input video timer by av: |
859 x=AV_delay*0.1f; | |
860 if(x<-max_pts_correction) x=-max_pts_correction; else | |
861 if(x> max_pts_correction) x= max_pts_correction; | |
862 if(default_max_pts_correction>=0) | |
863 max_pts_correction=default_max_pts_correction; | |
864 else | |
865 max_pts_correction=sh_video->frametime*0.10; // +-10% of time | |
866 // sh_video->timer-=x; | |
867 c_total+=x; | |
2613 | 868 v_pts_corr+=x; |
2605 | 869 |
2613 | 870 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 | 871 a_pts,v_pts,a_pts-v_pts, |
872 (float)(mux_a->timer-mux_v->timer), | |
2613 | 873 AV_delay, c_total, v_pts_corr ); |
2605 | 874 |
875 } | |
876 | |
877 #if 0 | |
878 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", | |
879 a_pts,v_pts,a_pts-v_pts,c_total, | |
880 (int)sh_video->num_frames,(int)sh_video->num_frames_decoded, | |
881 (sh_video->timer>0.5)?(int)(100.0*video_time_usage/(double)sh_video->timer):0, | |
882 (sh_video->timer>0.5)?(int)(100.0*vout_time_usage/(double)sh_video->timer):0, | |
883 (sh_video->timer>0.5)?(100.0*audio_time_usage/(double)sh_video->timer):0 | |
884 ,cache_fill_status | |
885 ); | |
886 #endif | |
887 | |
888 fflush(stdout); | |
889 | |
2531 | 890 |
891 | |
892 } // while(!eof) | |
893 | |
3357 | 894 #ifdef HAVE_MP3LAME |
895 // fixup CBR mp3 audio header: | |
3354 | 896 if(sh_audio && mux_a->codec==ACODEC_VBRMP3 && !lame_param_vbr){ |
897 mux_a->h.dwSampleSize=1; | |
898 mux_a->h.dwRate=mux_a->wf->nAvgBytesPerSec; | |
899 mux_a->h.dwScale=1; | |
900 printf("\n\nCBR audio effective bitrate: %8.3f kbit/s (%d bytes/sec)\n", | |
901 mux_a->h.dwRate*8.0f/1000.0f,mux_a->h.dwRate); | |
902 } | |
3357 | 903 #endif |
3354 | 904 |
2840
808fe0767cf8
fix typos - patch by Colin Marquardt <colin@marquardt-home.de>
pl
parents:
2825
diff
changeset
|
905 printf("\nWriting AVI index...\n"); |
2531 | 906 aviwrite_write_index(muxer,muxer_f); |
2622 | 907 printf("Fixup AVI header...\n"); |
2531 | 908 fseek(muxer_f,0,SEEK_SET); |
909 aviwrite_write_header(muxer,muxer_f); // update header | |
910 fclose(muxer_f); | |
911 | |
3361
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
912 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
|
913 (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
|
914 if(sh_audio) |
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
915 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
|
916 (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
|
917 |
2618 | 918 if(stream) free_stream(stream); // kill cache thread |
919 | |
3320
ac8b70dd5e45
use return 1; if interrupted - patch by Artur Skawina <skawina@geocities.com>
arpi
parents:
3240
diff
changeset
|
920 return interrupted; |
2531 | 921 } |