Mercurial > mplayer.hg
annotate mencoder.c @ 5572:8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
- tvi interface changes, grab_audio/video now returns timestamp!
- tv demuxer gets 'ds' hint too
- some verbose skip/dup counters to mencoder
- tvi_bsdbt848.c updates
- aviwrite/mencoder size types int->off_t
author | arpi |
---|---|
date | Fri, 12 Apr 2002 10:40:38 +0000 |
parents | cfab2ce8a840 |
children | acfcb903b778 |
rev | line source |
---|---|
3384 | 1 #define VCODEC_COPY 0 |
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 |
5553
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
3 // real codecs: |
3361
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
4 #define VCODEC_DIVX4 2 |
3504
21fc87d76300
support for RGB/BGR modes (tested with raw and divx4)
alex
parents:
3480
diff
changeset
|
5 #define VCODEC_LIBAVCODEC 4 |
4427
6310422b9557
new video format: yuvrgb. patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4408
diff
changeset
|
6 #define VCODEC_RAWRGB 6 |
4575 | 7 #define VCODEC_VFW 7 |
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 | |
4368 | 12 #define ACODEC_NULL 3 |
2531 | 13 |
14 #include <stdio.h> | |
15 #include <stdlib.h> | |
16 #include <string.h> | |
17 #include <signal.h> | |
5572
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
18 #include <sys/time.h> |
2531 | 19 |
2591 | 20 #include "config.h" |
2531 | 21 #include "mp_msg.h" |
2978 | 22 #include "version.h" |
2531 | 23 #include "help_mp.h" |
24 | |
2978 | 25 static char* banner_text= |
26 "\n\n" | |
4757 | 27 "MEncoder " VERSION "(C) 2000-2002 Arpad Gereoffy (see DOCS!)\n" |
2978 | 28 "\n"; |
29 | |
3323 | 30 #include "cpudetect.h" |
31 | |
2531 | 32 #include "codec-cfg.h" |
4343
b0c8eed7473c
Extended DVD chapter specification. Remove -last-chapter option.
kmkaplan
parents:
4207
diff
changeset
|
33 #include "cfgparser.h" |
2531 | 34 |
35 #include "stream.h" | |
36 #include "demuxer.h" | |
37 #include "stheader.h" | |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4088
diff
changeset
|
38 #include "playtree.h" |
2531 | 39 |
40 #include "aviwrite.h" | |
41 | |
42 #include "libvo/video_out.h" | |
43 | |
2574 | 44 #include "dec_audio.h" |
45 #include "dec_video.h" | |
46 | |
3357 | 47 #ifdef HAVE_MP3LAME |
2591 | 48 #include <lame/lame.h> |
3357 | 49 #endif |
2583 | 50 |
3521 | 51 #ifdef HAVE_LIBCSS |
52 #include "libmpdemux/dvdauth.h" | |
53 #endif | |
54 | |
3236 | 55 #include <inttypes.h> |
56 | |
3385 | 57 #include "fastmemcpy.h" |
58 | |
4388 | 59 /************************************************************************** |
60 Video accelerated architecture | |
61 **************************************************************************/ | |
5553
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
62 vo_vaa_t vo_vaa; // FIXME! remove me! |
5511 | 63 int vo_doublebuffering=0; |
64 int vo_directrendering=0; | |
65 int vo_config_count=0; | |
4388 | 66 |
2583 | 67 //-------------------------- |
68 | |
2531 | 69 // cache2: |
2618 | 70 static int stream_cache_size=0; |
2531 | 71 #ifdef USE_STREAM_CACHE |
72 extern int cache_fill_status; | |
73 #else | |
74 #define cache_fill_status 0 | |
75 #endif | |
76 | |
2618 | 77 int vcd_track=0; |
78 int audio_id=-1; | |
79 int video_id=-1; | |
80 int dvdsub_id=-1; | |
5388
3af2729c5c87
* New command line switch for mplayer & mencoder:
kmkaplan
parents:
5386
diff
changeset
|
81 int vobsub_id=-1; |
5436 | 82 char* audio_lang=NULL; |
83 char* dvdsub_lang=NULL; | |
5388
3af2729c5c87
* New command line switch for mplayer & mencoder:
kmkaplan
parents:
5386
diff
changeset
|
84 static char* spudec_ifo=NULL; |
2618 | 85 |
4355 | 86 static int has_audio=1; |
2531 | 87 char *audio_codec=NULL; // override audio codec |
88 char *video_codec=NULL; // override video codec | |
89 int audio_family=-1; // override audio codec family | |
90 int video_family=-1; // override video codec family | |
91 | |
3357 | 92 #ifdef HAVE_MP3LAME |
2661 | 93 int out_audio_codec=ACODEC_VBRMP3; |
3357 | 94 #else |
95 int out_audio_codec=ACODEC_PCM; | |
96 #endif | |
97 | |
4620 | 98 int out_video_codec= |
99 #ifdef HAVE_DIVX4ENCORE | |
100 VCODEC_DIVX4; | |
101 #else | |
102 #ifdef USE_LIBAVCODEC | |
103 VCODEC_LIBAVCODEC; | |
104 #else | |
5569 | 105 VCODEC_COPY; |
4620 | 106 #endif |
107 #endif | |
108 | |
2661 | 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 double video_time_usage=0; |
117 double vout_time_usage=0; | |
4834 | 118 double max_video_time_usage=0; |
119 double max_vout_time_usage=0; | |
4838 | 120 double cur_video_time_usage=0; |
121 double cur_vout_time_usage=0; | |
2531 | 122 static double audio_time_usage=0; |
123 static int total_time_usage_start=0; | |
4844
76acf5bbda78
exclude benchmark stuff execution from normal playback
nick
parents:
4838
diff
changeset
|
124 int benchmark=0; |
2531 | 125 |
2605 | 126 // A-V sync: |
127 int delay_corrected=1; | |
128 static float default_max_pts_correction=-1;//0.01f; | |
129 static float max_pts_correction=0;//default_max_pts_correction; | |
130 static float c_total=0; | |
131 | |
2613 | 132 float force_fps=0; |
133 float force_ofps=0; // set to 24 for inverse telecine | |
2531 | 134 |
2618 | 135 int force_srate=0; |
136 | |
2626 | 137 char* out_filename="test.avi"; |
138 char* mp3_filename=NULL; | |
139 char* ac3_filename=NULL; | |
140 | |
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
|
141 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
|
142 |
5553
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
143 int pass=0; |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
144 char* passtmpfile="divx2pass.log"; |
3377
4723f6fd750a
do not fault if 2pass VbrControl can't open the logfile
alex
parents:
3363
diff
changeset
|
145 int pass_working=0; |
2643 | 146 |
147 static int play_n_frames=-1; | |
148 | |
2661 | 149 //char *out_audio_codec=NULL; // override audio codec |
150 //char *out_video_codec=NULL; // override video codec | |
2626 | 151 |
2591 | 152 //#include "libmpeg2/mpeg2.h" |
153 //#include "libmpeg2/mpeg2_internal.h" | |
154 | |
3357 | 155 #ifdef HAVE_MP3LAME |
2626 | 156 int lame_param_quality=0; // best |
157 int lame_param_vbr=vbr_default; | |
158 int lame_param_mode=-1; // unset | |
159 int lame_param_padding=-1; // unset | |
160 int lame_param_br=-1; // unset | |
161 int lame_param_ratio=-1; // unset | |
3357 | 162 #endif |
2626 | 163 |
3236 | 164 static int vo_w=0, vo_h=0; |
5270 | 165 static int input_pitch, input_bpp; |
166 | |
2618 | 167 //-------------------------- config stuff: |
168 | |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4088
diff
changeset
|
169 m_config_t* mconfig; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4088
diff
changeset
|
170 |
2618 | 171 static int cfg_inc_verbose(struct config *conf){ ++verbose; return 0;} |
172 | |
173 static int cfg_include(struct config *conf, char *filename){ | |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4088
diff
changeset
|
174 return m_config_parse_config_file(mconfig, filename); |
2618 | 175 } |
176 | |
4620 | 177 static char *seek_to_sec=NULL; |
178 static off_t seek_to_byte=0; | |
179 | |
4159
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
180 static int parse_end_at(struct config *conf, const char* param); |
4427
6310422b9557
new video format: yuvrgb. patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4408
diff
changeset
|
181 static uint8_t* flip_upside_down(uint8_t* dst, const uint8_t* src, int width, int height); |
4159
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
182 |
2618 | 183 #include "get_path.c" |
184 | |
185 #include "cfg-mplayer-def.h" | |
186 #include "cfg-mencoder.h" | |
187 | |
4088 | 188 #ifdef USE_DVDREAD |
189 #include "spudec.h" | |
190 #endif | |
5388
3af2729c5c87
* New command line switch for mplayer & mencoder:
kmkaplan
parents:
5386
diff
changeset
|
191 #include "vobsub.h" |
4088 | 192 |
4743 | 193 /* FIXME */ |
194 void mencoder_exit(int level, char *how) | |
195 { | |
196 if (how) | |
197 printf("Exiting... (%s)\n", how); | |
198 else | |
199 printf("Exiting...\n"); | |
200 | |
201 exit(level); | |
202 } | |
203 | |
4488 | 204 void parse_cfgfiles( m_config_t* conf ) |
205 { | |
206 char *conffile; | |
207 if ((conffile = get_path("mencoder")) == NULL) { | |
208 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_GetpathProblem); | |
209 } else { | |
210 if (m_config_parse_config_file(conf, conffile) < 0) | |
4743 | 211 mencoder_exit(1,"configfile error"); |
4488 | 212 free(conffile); |
213 } | |
214 } | |
215 | |
5572
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
216 |
2591 | 217 //--------------------------------------------------------------------------- |
218 | |
4088 | 219 void *vo_spudec=NULL; |
220 | |
2591 | 221 int dec_audio(sh_audio_t *sh_audio,unsigned char* buffer,int total){ |
222 int size=0; | |
223 int eof=0; | |
224 while(size<total && !eof){ | |
225 int len=total-size; | |
226 if(len>MAX_OUTBURST) len=MAX_OUTBURST; | |
227 if(len>sh_audio->a_buffer_size) len=sh_audio->a_buffer_size; | |
228 if(len>sh_audio->a_buffer_len){ | |
229 int ret=decode_audio(sh_audio, | |
230 &sh_audio->a_buffer[sh_audio->a_buffer_len], | |
231 len-sh_audio->a_buffer_len, | |
232 sh_audio->a_buffer_size-sh_audio->a_buffer_len); | |
233 if(ret>0) sh_audio->a_buffer_len+=ret; else eof=1; | |
234 } | |
235 if(len>sh_audio->a_buffer_len) len=sh_audio->a_buffer_len; | |
236 memcpy(buffer+size,sh_audio->a_buffer,len); | |
237 sh_audio->a_buffer_len-=len; size+=len; | |
238 if(sh_audio->a_buffer_len>0) | |
239 memcpy(sh_audio->a_buffer,&sh_audio->a_buffer[len],sh_audio->a_buffer_len); | |
240 } | |
241 return size; | |
242 } | |
243 | |
4767 | 244 extern void me_register_options(m_config_t* cfg); |
245 | |
2591 | 246 //--------------------------------------------------------------------------- |
2531 | 247 |
248 static int eof=0; | |
3320
ac8b70dd5e45
use return 1; if interrupted - patch by Artur Skawina <skawina@geocities.com>
arpi
parents:
3240
diff
changeset
|
249 static int interrupted=0; |
2531 | 250 |
4159
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
251 enum end_at_type_t {END_AT_NONE, END_AT_TIME, END_AT_SIZE}; |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
252 static enum end_at_type_t end_at_type = END_AT_NONE; |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
253 static int end_at; |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
254 |
2531 | 255 static void exit_sighandler(int x){ |
256 eof=1; | |
3320
ac8b70dd5e45
use return 1; if interrupted - patch by Artur Skawina <skawina@geocities.com>
arpi
parents:
3240
diff
changeset
|
257 interrupted=1; |
2531 | 258 } |
259 | |
5553
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
260 aviwrite_t* muxer=NULL; |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
261 FILE* muxer_f=NULL; |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
262 |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
263 // callback for ve_*.c: |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
264 void mencoder_write_chunk(aviwrite_stream_t *s,int len,unsigned int flags){ |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
265 aviwrite_write_chunk(muxer,s,muxer_f,len,flags); |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
266 } |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
267 |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
268 |
2618 | 269 int main(int argc,char* argv[], char *envp[]){ |
2531 | 270 |
271 stream_t* stream=NULL; | |
272 demuxer_t* demuxer=NULL; | |
4367
c2be4fb65cee
3-pass encoding support (reads frame skip/dup control and audio stream from frameno.avi)
arpi
parents:
4365
diff
changeset
|
273 stream_t* stream2=NULL; |
c2be4fb65cee
3-pass encoding support (reads frame skip/dup control and audio stream from frameno.avi)
arpi
parents:
4365
diff
changeset
|
274 demuxer_t* demuxer2=NULL; |
2531 | 275 demux_stream_t *d_audio=NULL; |
276 demux_stream_t *d_video=NULL; | |
277 demux_stream_t *d_dvdsub=NULL; | |
278 sh_audio_t *sh_audio=NULL; | |
279 sh_video_t *sh_video=NULL; | |
280 int file_format=DEMUXER_TYPE_UNKNOWN; | |
5149 | 281 int i; |
2531 | 282 |
5572
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
283 uint32_t ptimer_start; |
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
284 uint32_t audiorate=0; |
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
285 uint32_t videorate=0; |
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
286 uint32_t audiosamples=1; |
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
287 uint32_t videosamples=1; |
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
288 uint32_t skippedframes=0; |
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
289 uint32_t duplicatedframes=0; |
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
290 |
2531 | 291 aviwrite_stream_t* mux_a=NULL; |
292 aviwrite_stream_t* mux_v=NULL; | |
5572
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
293 off_t muxer_f_size=0; |
2531 | 294 |
3357 | 295 #ifdef HAVE_MP3LAME |
2591 | 296 lame_global_flags *lame; |
3357 | 297 #endif |
2583 | 298 |
2653 | 299 float audio_preload=0.5; |
2581 | 300 |
2613 | 301 double v_pts_corr=0; |
302 double v_timer_corr=0; | |
2605 | 303 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4088
diff
changeset
|
304 play_tree_t* playtree; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4088
diff
changeset
|
305 play_tree_iter_t* playtree_iter; |
2618 | 306 char* filename=NULL; |
4367
c2be4fb65cee
3-pass encoding support (reads frame skip/dup control and audio stream from frameno.avi)
arpi
parents:
4365
diff
changeset
|
307 char* frameno_filename="frameno.avi"; |
2618 | 308 |
3361
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
309 int decoded_frameno=0; |
4367
c2be4fb65cee
3-pass encoding support (reads frame skip/dup control and audio stream from frameno.avi)
arpi
parents:
4365
diff
changeset
|
310 int next_frameno=-1; |
3361
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
311 |
4387 | 312 unsigned int timer_start; |
313 | |
5223 | 314 mp_msg_init(); |
315 mp_msg_set_level(MSGL_STATUS); | |
2978 | 316 mp_msg(MSGT_CPLAYER,MSGL_INFO,"%s",banner_text); |
2622 | 317 |
318 // check codec.conf | |
319 if(!parse_codec_cfg(get_path("codecs.conf"))){ | |
3748 | 320 if(!parse_codec_cfg(CONFDIR"/codecs.conf")){ |
2622 | 321 mp_msg(MSGT_MENCODER,MSGL_HINT,MSGTR_CopyCodecsConf); |
4743 | 322 mencoder_exit(1,NULL); |
2622 | 323 } |
324 } | |
2531 | 325 |
3323 | 326 /* Test for cpu capabilities (and corresponding OS support) for optimizing */ |
327 #ifdef ARCH_X86 | |
328 GetCpuCaps(&gCpuCaps); | |
329 mp_msg(MSGT_CPLAYER,MSGL_INFO,"CPUflags: Type: %d MMX: %d MMX2: %d 3DNow: %d 3DNow2: %d SSE: %d SSE2: %d\n", | |
330 gCpuCaps.cpuType,gCpuCaps.hasMMX,gCpuCaps.hasMMX2, | |
331 gCpuCaps.has3DNow, gCpuCaps.has3DNowExt, | |
332 gCpuCaps.hasSSE, gCpuCaps.hasSSE2); | |
333 #endif | |
334 | |
4367
c2be4fb65cee
3-pass encoding support (reads frame skip/dup control and audio stream from frameno.avi)
arpi
parents:
4365
diff
changeset
|
335 // FIXME: get rid of -dvd and other tricky options and config/playtree |
c2be4fb65cee
3-pass encoding support (reads frame skip/dup control and audio stream from frameno.avi)
arpi
parents:
4365
diff
changeset
|
336 stream2=open_stream(frameno_filename,0,&i); |
c2be4fb65cee
3-pass encoding support (reads frame skip/dup control and audio stream from frameno.avi)
arpi
parents:
4365
diff
changeset
|
337 if(stream2){ |
c2be4fb65cee
3-pass encoding support (reads frame skip/dup control and audio stream from frameno.avi)
arpi
parents:
4365
diff
changeset
|
338 demuxer2=demux_open(stream2,DEMUXER_TYPE_AVI,-1,-1,-2); |
c2be4fb65cee
3-pass encoding support (reads frame skip/dup control and audio stream from frameno.avi)
arpi
parents:
4365
diff
changeset
|
339 if(demuxer2) printf("Using pass3 control file: %s\n",frameno_filename); |
c2be4fb65cee
3-pass encoding support (reads frame skip/dup control and audio stream from frameno.avi)
arpi
parents:
4365
diff
changeset
|
340 } |
c2be4fb65cee
3-pass encoding support (reads frame skip/dup control and audio stream from frameno.avi)
arpi
parents:
4365
diff
changeset
|
341 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4088
diff
changeset
|
342 playtree = play_tree_new(); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4088
diff
changeset
|
343 mconfig = m_config_new(playtree); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4088
diff
changeset
|
344 m_config_register_options(mconfig,mencoder_opts); |
4767 | 345 me_register_options(mconfig); |
4488 | 346 parse_cfgfiles(mconfig); |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4088
diff
changeset
|
347 |
4743 | 348 if(m_config_parse_command_line(mconfig, argc, argv, envp) < 0) mencoder_exit(1, "error parsing cmdline"); |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4088
diff
changeset
|
349 playtree = play_tree_cleanup(playtree); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4088
diff
changeset
|
350 if(playtree) { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4088
diff
changeset
|
351 playtree_iter = play_tree_iter_new(playtree,mconfig); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4088
diff
changeset
|
352 if(playtree_iter) { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4088
diff
changeset
|
353 if(play_tree_iter_step(playtree_iter,0,0) != PLAY_TREE_ITER_ENTRY) { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4088
diff
changeset
|
354 play_tree_iter_free(playtree_iter); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4088
diff
changeset
|
355 playtree_iter = NULL; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4088
diff
changeset
|
356 } |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4088
diff
changeset
|
357 filename = play_tree_iter_get_file(playtree_iter,1); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4088
diff
changeset
|
358 } |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4088
diff
changeset
|
359 } |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4088
diff
changeset
|
360 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4088
diff
changeset
|
361 if(!filename && !vcd_track && !dvd_title && !tv_param_on){ |
2618 | 362 printf("\nMissing filename!\n\n"); |
4743 | 363 mencoder_exit(1,NULL); |
2618 | 364 } |
365 | |
5223 | 366 mp_msg_set_level(verbose+MSGL_STATUS); |
2600 | 367 |
2618 | 368 stream=open_stream(filename,vcd_track,&file_format); |
2531 | 369 |
370 if(!stream){ | |
371 printf("Cannot open file/device\n"); | |
4743 | 372 mencoder_exit(1,NULL); |
2531 | 373 } |
374 | |
375 printf("success: format: %d data: 0x%X - 0x%X\n",file_format, (int)(stream->start_pos),(int)(stream->end_pos)); | |
376 | |
5436 | 377 #ifdef USE_DVDREAD |
378 if(stream->type==STREAMTYPE_DVD){ | |
379 if(audio_lang && audio_id==-1) audio_id=dvd_aid_from_lang(stream,audio_lang); | |
380 if(dvdsub_lang && dvdsub_id==-1) dvdsub_id=dvd_sid_from_lang(stream,dvdsub_lang); | |
381 } | |
382 #endif | |
383 | |
3563 | 384 if(stream_cache_size) stream_enable_cache(stream,stream_cache_size*1024,0,0); |
2531 | 385 |
3979 | 386 #ifdef HAVE_LIBCSS |
387 // current_module="libcss"; | |
388 if (dvdimportkey) { | |
389 if (dvd_import_key(dvdimportkey)) { | |
390 mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_ErrorDVDkey); | |
4743 | 391 mencoder_exit(1,NULL); |
3979 | 392 } |
393 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_CmdlineDVDkey); | |
394 } | |
395 if (dvd_auth_device) { | |
396 // if (dvd_auth(dvd_auth_device,f)) { | |
397 if (dvd_auth(dvd_auth_device,filename)) { | |
398 mp_msg(MSGT_CPLAYER,MSGL_FATAL,"Error in DVD auth...\n"); | |
4743 | 399 mencoder_exit(1,NULL); |
3979 | 400 } |
401 mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_DVDauthOk); | |
402 } | |
403 #endif | |
404 | |
4367
c2be4fb65cee
3-pass encoding support (reads frame skip/dup control and audio stream from frameno.avi)
arpi
parents:
4365
diff
changeset
|
405 if(!has_audio || demuxer2) audio_id=-2; /* do NOT read audio packets... */ |
4355 | 406 |
2882 | 407 //demuxer=demux_open(stream,file_format,video_id,audio_id,dvdsub_id); |
408 demuxer=demux_open(stream,file_format,audio_id,video_id,dvdsub_id); | |
2531 | 409 if(!demuxer){ |
410 printf("Cannot open demuxer\n"); | |
4743 | 411 mencoder_exit(1,NULL); |
2531 | 412 } |
413 | |
4367
c2be4fb65cee
3-pass encoding support (reads frame skip/dup control and audio stream from frameno.avi)
arpi
parents:
4365
diff
changeset
|
414 d_audio=demuxer2 ? demuxer2->audio : demuxer->audio; |
2531 | 415 d_video=demuxer->video; |
416 d_dvdsub=demuxer->sub; | |
417 sh_audio=d_audio->sh; | |
418 sh_video=d_video->sh; | |
419 | |
420 if(!video_read_properties(sh_video)){ | |
421 printf("Couldn't read video properties\n"); | |
4743 | 422 mencoder_exit(1,NULL); |
2531 | 423 } |
424 | |
2622 | 425 mp_msg(MSGT_MENCODER,MSGL_INFO,"[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.2f ftime:=%6.4f\n", |
2531 | 426 demuxer->file_format,sh_video->format, sh_video->disp_w,sh_video->disp_h, |
427 sh_video->fps,sh_video->frametime | |
428 ); | |
2581 | 429 |
4620 | 430 if(sh_audio && (out_audio_codec || seek_to_sec || !sh_audio->wf)){ |
2581 | 431 // Go through the codec.conf and find the best codec... |
432 sh_audio->codec=NULL; | |
2622 | 433 if(audio_family!=-1) mp_msg(MSGT_MENCODER,MSGL_INFO,MSGTR_TryForceAudioFmt,audio_family); |
2581 | 434 while(1){ |
435 sh_audio->codec=find_codec(sh_audio->format,NULL,sh_audio->codec,1); | |
436 if(!sh_audio->codec){ | |
437 if(audio_family!=-1) { | |
438 sh_audio->codec=NULL; /* re-search */ | |
2622 | 439 mp_msg(MSGT_MENCODER,MSGL_ERR,MSGTR_CantFindAfmtFallback); |
2581 | 440 audio_family=-1; |
441 continue; | |
442 } | |
2622 | 443 mp_msg(MSGT_MENCODER,MSGL_ERR,MSGTR_CantFindAudioCodec,sh_audio->format); |
444 mp_msg(MSGT_MENCODER,MSGL_HINT, MSGTR_TryUpgradeCodecsConfOrRTFM,get_path("codecs.conf")); | |
2581 | 445 sh_audio=d_audio->sh=NULL; |
446 break; | |
447 } | |
448 if(audio_codec && strcmp(sh_audio->codec->name,audio_codec)) continue; | |
449 else if(audio_family!=-1 && sh_audio->codec->driver!=audio_family) continue; | |
2622 | 450 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 | 451 break; |
452 } | |
453 } | |
454 | |
4620 | 455 if(sh_audio && (out_audio_codec || seek_to_sec || !sh_audio->wf)){ |
2622 | 456 mp_msg(MSGT_MENCODER,MSGL_V,"Initializing audio codec...\n"); |
2581 | 457 if(!init_audio(sh_audio)){ |
2622 | 458 mp_msg(MSGT_MENCODER,MSGL_ERR,MSGTR_CouldntInitAudioCodec); |
2581 | 459 sh_audio=d_audio->sh=NULL; |
460 } else { | |
2622 | 461 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 | 462 sh_audio->sample_format,sh_audio->i_bps,sh_audio->o_bps); |
463 } | |
464 } | |
465 | |
2531 | 466 // set up video encoder: |
467 | |
5388
3af2729c5c87
* New command line switch for mplayer & mencoder:
kmkaplan
parents:
5386
diff
changeset
|
468 if (spudec_ifo) { |
3af2729c5c87
* New command line switch for mplayer & mencoder:
kmkaplan
parents:
5386
diff
changeset
|
469 unsigned int palette[16], width, height; |
3af2729c5c87
* New command line switch for mplayer & mencoder:
kmkaplan
parents:
5386
diff
changeset
|
470 if (vobsub_parse_ifo(spudec_ifo, palette, &width, &height, 1) >= 0) |
3af2729c5c87
* New command line switch for mplayer & mencoder:
kmkaplan
parents:
5386
diff
changeset
|
471 vo_spudec=spudec_new_scaled(palette, sh_video->disp_w, sh_video->disp_h); |
3af2729c5c87
* New command line switch for mplayer & mencoder:
kmkaplan
parents:
5386
diff
changeset
|
472 } |
5392
d7c586ebbacf
Fix bug noticed by Hajba Szilard in message <20020329151644.A23301@revai.hu>
kmkaplan
parents:
5390
diff
changeset
|
473 #ifdef USE_DVDREAD |
5388
3af2729c5c87
* New command line switch for mplayer & mencoder:
kmkaplan
parents:
5386
diff
changeset
|
474 if (vo_spudec==NULL) { |
4557 | 475 vo_spudec=spudec_new_scaled(stream->type==STREAMTYPE_DVD?((dvd_priv_t *)(stream->priv))->cur_pgc->palette:NULL, |
4088 | 476 sh_video->disp_w, sh_video->disp_h); |
5388
3af2729c5c87
* New command line switch for mplayer & mencoder:
kmkaplan
parents:
5386
diff
changeset
|
477 } |
4088 | 478 #endif |
479 | |
2531 | 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); |
4743 | 484 mencoder_exit(1,NULL); |
2887
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 | |
4575 | 493 mux_v->buffer_size=0x200000; // 2MB |
2531 | 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 |
5553
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
504 mux_v->bih=NULL; |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
505 sh_video->codec=NULL; |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
506 sh_video->video_out=NULL; |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
507 sh_video->vfilter=NULL; // fixme! |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
508 |
2531 | 509 switch(mux_v->codec){ |
3384 | 510 case VCODEC_COPY: |
511 if (sh_video->bih) | |
512 mux_v->bih=sh_video->bih; | |
513 else | |
514 { | |
515 mux_v->bih=malloc(sizeof(BITMAPINFOHEADER)); | |
516 mux_v->bih->biSize=sizeof(BITMAPINFOHEADER); | |
517 mux_v->bih->biWidth=sh_video->disp_w; | |
518 mux_v->bih->biHeight=sh_video->disp_h; | |
519 mux_v->bih->biCompression=sh_video->format; | |
520 mux_v->bih->biPlanes=1; | |
521 mux_v->bih->biBitCount=24; // FIXME!!! | |
522 mux_v->bih->biSizeImage=mux_v->bih->biWidth*mux_v->bih->biHeight*(mux_v->bih->biBitCount/8); | |
523 } | |
524 printf("videocodec: framecopy (%dx%d %dbpp fourcc=%x)\n", | |
525 mux_v->bih->biWidth, mux_v->bih->biHeight, | |
526 mux_v->bih->biBitCount, mux_v->bih->biCompression); | |
2531 | 527 break; |
3361
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
528 case VCODEC_FRAMENO: |
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
529 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
|
530 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
|
531 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
|
532 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
|
533 mux_v->bih->biPlanes=1; |
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
534 mux_v->bih->biBitCount=24; |
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
535 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
|
536 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
|
537 break; |
5553
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
538 default: |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
539 |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
540 switch(mux_v->codec){ |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
541 case VCODEC_DIVX4: |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
542 sh_video->vfilter=vf_open_encoder(NULL,"divx4",mux_v); break; |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
543 case VCODEC_LIBAVCODEC: |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
544 sh_video->vfilter=vf_open_encoder(NULL,"lavc",mux_v); break; |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
545 case VCODEC_RAWRGB: |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
546 sh_video->vfilter=vf_open_encoder(NULL,"rawrgb",mux_v); break; |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
547 case VCODEC_VFW: |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
548 sh_video->vfilter=vf_open_encoder(NULL,"vfw",mux_v); break; |
4743 | 549 } |
5553
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
550 if(!mux_v->bih || !sh_video->vfilter){ |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
551 mp_msg(MSGT_MENCODER,MSGL_FATAL,"Failed to open the encoder\n"); |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
552 mencoder_exit(1,NULL); |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
553 } |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
554 sh_video->vfilter=append_filters(sh_video->vfilter); |
3377
4723f6fd750a
do not fault if 2pass VbrControl can't open the logfile
alex
parents:
3363
diff
changeset
|
555 |
5553
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
556 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n"); |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
557 // Go through the codec.conf and find the best codec... |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
558 sh_video->inited=0; |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
559 codecs_reset_selection(0); |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
560 if(video_codec){ |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
561 // forced codec by name: |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
562 mp_msg(MSGT_CPLAYER,MSGL_INFO,"Forced video codec: %s\n",video_codec); |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
563 init_video(sh_video,video_codec,-1,-1); |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
564 } else { |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
565 int status; |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
566 // try in stability order: UNTESTED, WORKING, BUGGY, BROKEN |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
567 if(video_family>=0) mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_TryForceVideoFmt,video_family); |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
568 for(status=CODECS_STATUS__MAX;status>=CODECS_STATUS__MIN;--status){ |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
569 if(video_family>=0) // try first the preferred codec family: |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
570 if(init_video(sh_video,NULL,video_family,status)) break; |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
571 if(init_video(sh_video,NULL,-1,status)) break; |
4365
9e20866c3250
added better fourcc handling for lavc, exiting if no lavc video codec name specified
alex
parents:
4355
diff
changeset
|
572 } |
5553
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
573 } |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
574 if(!sh_video->inited){ |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
575 mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantFindVideoCodec,sh_video->format); |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
576 mp_msg(MSGT_CPLAYER,MSGL_HINT, MSGTR_TryUpgradeCodecsConfOrRTFM,get_path("codecs.conf")); |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
577 mencoder_exit(1,NULL); |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
578 } |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
579 mp_msg(MSGT_CPLAYER,MSGL_INFO,"%s video codec: [%s] drv:%d prio:%d (%s)\n", |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
580 video_codec?mp_gettext("Forcing"):mp_gettext("Detected"),sh_video->codec->name,sh_video->codec->driver,sh_video->codec->priority!=-1?sh_video->codec->priority:0,sh_video->codec->info); |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
581 mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n"); |
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
|
582 |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
583 } |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
584 |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
585 /* force output fourcc to .. */ |
4365
9e20866c3250
added better fourcc handling for lavc, exiting if no lavc video codec name specified
alex
parents:
4355
diff
changeset
|
586 if ((force_fourcc != NULL) && (strlen(force_fourcc) >= 4)) |
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
|
587 { |
af1f8e2d693a
added libavcodec support (mjpeg,h263,rv10,mpeg1 codecs tested&working) and added -ffourcc option (force fourcc in ouput)
alex
parents:
3563
diff
changeset
|
588 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
|
589 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
|
590 printf("Forcing output fourcc to %x [%.4s]\n", |
4365
9e20866c3250
added better fourcc handling for lavc, exiting if no lavc video codec name specified
alex
parents:
4355
diff
changeset
|
591 mux_v->bih->biCompression, (char *)&mux_v->bih->biCompression); |
2531 | 592 } |
593 | |
4370 | 594 if(demuxer->file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf! |
595 | |
2581 | 596 // ============= AUDIO =============== |
597 if(sh_audio){ | |
598 | |
599 mux_a=aviwrite_new_stream(muxer,AVIWRITE_TYPE_AUDIO); | |
600 | |
601 mux_a->buffer_size=0x100000; //16384; | |
602 mux_a->buffer=malloc(mux_a->buffer_size); | |
603 | |
604 mux_a->source=sh_audio; | |
605 | |
2661 | 606 mux_a->codec=out_audio_codec; |
2581 | 607 |
608 switch(mux_a->codec){ | |
3385 | 609 case ACODEC_COPY: |
4369 | 610 if (sh_audio->wf){ |
3385 | 611 mux_a->wf=sh_audio->wf; |
4370 | 612 if(!sh_audio->i_bps) sh_audio->i_bps=mux_a->wf->nAvgBytesPerSec; |
4369 | 613 } else { |
3385 | 614 mux_a->wf = malloc(sizeof(WAVEFORMATEX)); |
4370 | 615 mux_a->wf->nBlockAlign = 1; //mux_a->h.dwSampleSize; |
4369 | 616 mux_a->wf->wFormatTag = sh_audio->format; |
3385 | 617 mux_a->wf->nChannels = sh_audio->channels; |
618 mux_a->wf->nSamplesPerSec = sh_audio->samplerate; | |
4369 | 619 mux_a->wf->nAvgBytesPerSec=sh_audio->i_bps; //mux_a->h.dwSampleSize*mux_a->wf->nSamplesPerSec; |
3480 | 620 mux_a->wf->wBitsPerSample = 16; // FIXME |
3385 | 621 mux_a->wf->cbSize=0; // FIXME for l3codeca.acm |
622 } | |
4370 | 623 if(sh_audio->audio.dwScale){ |
624 mux_a->h.dwSampleSize=sh_audio->audio.dwSampleSize; | |
625 mux_a->h.dwScale=sh_audio->audio.dwScale; | |
626 mux_a->h.dwRate=sh_audio->audio.dwRate; | |
627 } else { | |
628 mux_a->h.dwSampleSize=mux_a->wf->nBlockAlign; | |
629 mux_a->h.dwScale=mux_a->h.dwSampleSize; | |
630 mux_a->h.dwRate=mux_a->wf->nAvgBytesPerSec; | |
631 } | |
632 printf("audiocodec: framecopy (format=%x chans=%d rate=%d bits=%d bps=%d sample=%d)\n", | |
3385 | 633 mux_a->wf->wFormatTag, mux_a->wf->nChannels, mux_a->wf->nSamplesPerSec, |
4370 | 634 mux_a->wf->wBitsPerSample, mux_a->wf->nAvgBytesPerSec, mux_a->h.dwSampleSize); |
2581 | 635 break; |
2583 | 636 case ACODEC_PCM: |
637 printf("CBR PCM audio selected\n"); | |
638 mux_a->h.dwSampleSize=2*sh_audio->channels; | |
639 mux_a->h.dwScale=1; | |
640 mux_a->h.dwRate=sh_audio->samplerate; | |
641 mux_a->wf=malloc(sizeof(WAVEFORMATEX)); | |
642 mux_a->wf->nBlockAlign=mux_a->h.dwSampleSize; | |
643 mux_a->wf->wFormatTag=0x1; // PCM | |
644 mux_a->wf->nChannels=sh_audio->channels; | |
645 mux_a->wf->nSamplesPerSec=sh_audio->samplerate; | |
646 mux_a->wf->nAvgBytesPerSec=mux_a->h.dwSampleSize*mux_a->wf->nSamplesPerSec; | |
647 mux_a->wf->wBitsPerSample=16; | |
648 mux_a->wf->cbSize=0; // FIXME for l3codeca.acm | |
649 break; | |
2581 | 650 case ACODEC_VBRMP3: |
3385 | 651 printf("MP3 audio selected\n"); |
2581 | 652 mux_a->h.dwSampleSize=0; // VBR |
2653 | 653 mux_a->h.dwScale=1152; // samples/frame |
2581 | 654 mux_a->h.dwRate=sh_audio->samplerate; |
2635
c1e24e01601b
fixed AVI header creation - now should be compatible with NaNdub
arpi
parents:
2627
diff
changeset
|
655 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
|
656 mux_a->wf=malloc(sizeof(MPEGLAYER3WAVEFORMAT)); // should be 30 |
2581 | 657 mux_a->wf->wFormatTag=0x55; // MP3 |
658 mux_a->wf->nChannels=sh_audio->channels; | |
2639 | 659 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
|
660 mux_a->wf->nAvgBytesPerSec=192000/8; // FIXME! |
2653 | 661 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
|
662 mux_a->wf->wBitsPerSample=0; //16; |
c1e24e01601b
fixed AVI header creation - now should be compatible with NaNdub
arpi
parents:
2627
diff
changeset
|
663 // from NaNdub: (requires for l3codeca.acm) |
c1e24e01601b
fixed AVI header creation - now should be compatible with NaNdub
arpi
parents:
2627
diff
changeset
|
664 mux_a->wf->cbSize=12; |
c1e24e01601b
fixed AVI header creation - now should be compatible with NaNdub
arpi
parents:
2627
diff
changeset
|
665 ((MPEGLAYER3WAVEFORMAT*)(mux_a->wf))->wID=1; |
c1e24e01601b
fixed AVI header creation - now should be compatible with NaNdub
arpi
parents:
2627
diff
changeset
|
666 ((MPEGLAYER3WAVEFORMAT*)(mux_a->wf))->fdwFlags=2; |
2653 | 667 ((MPEGLAYER3WAVEFORMAT*)(mux_a->wf))->nBlockSize=1152; // ??? |
2635
c1e24e01601b
fixed AVI header creation - now should be compatible with NaNdub
arpi
parents:
2627
diff
changeset
|
668 ((MPEGLAYER3WAVEFORMAT*)(mux_a->wf))->nFramesPerBlock=1; |
c1e24e01601b
fixed AVI header creation - now should be compatible with NaNdub
arpi
parents:
2627
diff
changeset
|
669 ((MPEGLAYER3WAVEFORMAT*)(mux_a->wf))->nCodecDelay=0; |
2581 | 670 break; |
671 } | |
672 } | |
673 | |
2840
808fe0767cf8
fix typos - patch by Colin Marquardt <colin@marquardt-home.de>
pl
parents:
2825
diff
changeset
|
674 printf("Writing AVI header...\n"); |
2531 | 675 aviwrite_write_header(muxer,muxer_f); |
676 | |
5553
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
677 decoded_frameno=0; |
2531 | 678 |
2600 | 679 if(sh_audio) |
2583 | 680 switch(mux_a->codec){ |
3357 | 681 #ifdef HAVE_MP3LAME |
2583 | 682 case ACODEC_VBRMP3: |
683 | |
684 lame=lame_init(); | |
2591 | 685 lame_set_bWriteVbrTag(lame,0); |
2583 | 686 lame_set_in_samplerate(lame,sh_audio->samplerate); |
687 lame_set_num_channels(lame,mux_a->wf->nChannels); | |
2639 | 688 lame_set_out_samplerate(lame,mux_a->wf->nSamplesPerSec); |
2626 | 689 if(lame_param_vbr){ // VBR: |
690 lame_set_VBR(lame,lame_param_vbr); // vbr mode | |
691 lame_set_VBR_q(lame,lame_param_quality+1); // 1 = best vbr q 6=~128k | |
692 if(lame_param_br>0) lame_set_VBR_mean_bitrate_kbps(lame,lame_param_br); | |
693 } else { // CBR: | |
694 lame_set_quality(lame,lame_param_quality); // 0 = best q | |
695 if(lame_param_br>0) lame_set_brate(lame,lame_param_br); | |
696 } | |
697 if(lame_param_mode>=0) lame_set_mode(lame,lame_param_mode); // j-st | |
698 if(lame_param_ratio>0) lame_set_compression_ratio(lame,lame_param_ratio); | |
2583 | 699 lame_init_params(lame); |
2622 | 700 if(verbose){ |
2626 | 701 lame_print_config(lame); |
702 lame_print_internals(lame); | |
2622 | 703 } |
3357 | 704 break; |
705 #endif | |
2583 | 706 } |
707 | |
2531 | 708 signal(SIGINT,exit_sighandler); // Interrupt from keyboard |
709 signal(SIGQUIT,exit_sighandler); // Quit from keyboard | |
710 signal(SIGTERM,exit_sighandler); // kill | |
711 | |
4387 | 712 timer_start=GetTimerMS(); |
713 | |
4620 | 714 if (seek_to_sec) { |
715 int a,b; float d; | |
716 | |
717 if (sscanf(seek_to_sec, "%d:%d:%f", &a,&b,&d)==3) | |
718 d += 3600*a + 60*b; | |
719 else if (sscanf(seek_to_sec, "%d:%f", &a, &d)==2) | |
720 d += 60*a; | |
721 else | |
722 sscanf(seek_to_sec, "%f", &d); | |
723 | |
724 demux_seek(demuxer, d, 1); | |
725 } | |
726 | |
5572
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
727 if(tv_param_on == 1) |
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
728 { |
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
729 fprintf(stderr,"Forcing audio preload to 0, max pts correction to 0\n"); |
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
730 audio_preload = 0.0; |
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
731 default_max_pts_correction = 0; |
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
732 } |
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
733 |
2531 | 734 while(!eof){ |
735 | |
2571 | 736 float frame_time=0; |
2531 | 737 int blit_frame=0; |
738 float a_pts=0; | |
739 float v_pts=0; | |
2574 | 740 unsigned char* start=NULL; |
741 int in_size; | |
2613 | 742 int skip_flag=0; // 1=skip -1=duplicate |
2531 | 743 |
5572
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
744 if((end_at_type == END_AT_SIZE && end_at <= ftello(muxer_f)) || |
4159
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
745 (end_at_type == END_AT_TIME && end_at < sh_video->timer)) |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
746 break; |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
747 |
2643 | 748 if(play_n_frames>=0){ |
749 --play_n_frames; | |
750 if(play_n_frames<0) break; | |
751 } | |
752 | |
2581 | 753 if(sh_audio){ |
754 // get audio: | |
2583 | 755 while(mux_a->timer-audio_preload<mux_v->timer){ |
2653 | 756 int len=0; |
5572
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
757 |
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
758 ptimer_start = GetTimerMS(); |
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
759 |
2581 | 760 if(mux_a->h.dwSampleSize){ |
2605 | 761 // CBR - copy 0.5 sec of audio |
2583 | 762 switch(mux_a->codec){ |
3385 | 763 case ACODEC_COPY: // copy |
4370 | 764 len=mux_a->wf->nAvgBytesPerSec/2; |
2583 | 765 len/=mux_a->h.dwSampleSize;if(len<1) len=1; |
766 len*=mux_a->h.dwSampleSize; | |
767 len=demux_read_data(sh_audio->ds,mux_a->buffer,len); | |
768 break; | |
769 case ACODEC_PCM: | |
770 len=mux_a->h.dwSampleSize*(mux_a->h.dwRate/2); | |
2591 | 771 len=dec_audio(sh_audio,mux_a->buffer,len); |
2583 | 772 break; |
773 } | |
2581 | 774 } else { |
2605 | 775 // VBR - encode/copy an audio frame |
776 switch(mux_a->codec){ | |
3385 | 777 case ACODEC_COPY: // copy |
4367
c2be4fb65cee
3-pass encoding support (reads frame skip/dup control and audio stream from frameno.avi)
arpi
parents:
4365
diff
changeset
|
778 len=ds_get_packet(sh_audio->ds,(unsigned char**) &mux_a->buffer); |
c2be4fb65cee
3-pass encoding support (reads frame skip/dup control and audio stream from frameno.avi)
arpi
parents:
4365
diff
changeset
|
779 // printf("VBR audio framecopy not yet implemented!\n"); |
2605 | 780 break; |
3357 | 781 #ifdef HAVE_MP3LAME |
2605 | 782 case ACODEC_VBRMP3: |
2591 | 783 while(mux_a->buffer_len<4){ |
784 unsigned char tmp[2304]; | |
785 int len=dec_audio(sh_audio,tmp,2304); | |
786 if(len<=0) break; // eof | |
787 len=lame_encode_buffer_interleaved(lame, | |
788 tmp,len/4, | |
789 mux_a->buffer+mux_a->buffer_len,mux_a->buffer_size-mux_a->buffer_len); | |
790 if(len<0) break; // error | |
791 mux_a->buffer_len+=len; | |
792 } | |
793 if(mux_a->buffer_len<4) break; | |
794 len=mp_decode_mp3_header(mux_a->buffer); | |
2639 | 795 //printf("%d\n",len); |
2591 | 796 if(len<=0) break; // bad frame! |
797 while(mux_a->buffer_len<len){ | |
798 unsigned char tmp[2304]; | |
799 int len=dec_audio(sh_audio,tmp,2304); | |
800 if(len<=0) break; // eof | |
801 len=lame_encode_buffer_interleaved(lame, | |
802 tmp,len/4, | |
803 mux_a->buffer+mux_a->buffer_len,mux_a->buffer_size-mux_a->buffer_len); | |
804 if(len<0) break; // error | |
805 mux_a->buffer_len+=len; | |
806 } | |
2605 | 807 break; |
3357 | 808 #endif |
2605 | 809 } |
2581 | 810 } |
2583 | 811 if(len<=0) break; // EOF? |
812 aviwrite_write_chunk(muxer,mux_a,muxer_f,len,0); | |
2655 | 813 if(!mux_a->h.dwSampleSize && mux_a->timer>0) |
3354 | 814 mux_a->wf->nAvgBytesPerSec=0.5f+(double)mux_a->size/mux_a->timer; // avg bps (VBR) |
2591 | 815 if(mux_a->buffer_len>=len){ |
816 mux_a->buffer_len-=len; | |
817 memcpy(mux_a->buffer,mux_a->buffer+len,mux_a->buffer_len); | |
818 } | |
5572
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
819 |
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
820 |
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
821 audiosamples++; |
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
822 audiorate+= (GetTimerMS() - ptimer_start); |
2581 | 823 } |
824 } | |
825 | |
826 // get video frame! | |
5572
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
827 |
2581 | 828 in_size=video_read_frame(sh_video,&frame_time,&start,force_fps); |
829 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
|
830 sh_video->timer+=frame_time; ++decoded_frameno; |
5572
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
831 |
2613 | 832 v_timer_corr-=frame_time-(float)mux_v->h.dwScale/mux_v->h.dwRate; |
2531 | 833 |
5553
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
834 if(demuxer2){ // 3-pass encoding, read control file (frameno.avi) |
4367
c2be4fb65cee
3-pass encoding support (reads frame skip/dup control and audio stream from frameno.avi)
arpi
parents:
4365
diff
changeset
|
835 // find our frame: |
c2be4fb65cee
3-pass encoding support (reads frame skip/dup control and audio stream from frameno.avi)
arpi
parents:
4365
diff
changeset
|
836 while(next_frameno<decoded_frameno){ |
c2be4fb65cee
3-pass encoding support (reads frame skip/dup control and audio stream from frameno.avi)
arpi
parents:
4365
diff
changeset
|
837 int* start; |
c2be4fb65cee
3-pass encoding support (reads frame skip/dup control and audio stream from frameno.avi)
arpi
parents:
4365
diff
changeset
|
838 int len=ds_get_packet(demuxer2->video,(unsigned char**) &start); |
c2be4fb65cee
3-pass encoding support (reads frame skip/dup control and audio stream from frameno.avi)
arpi
parents:
4365
diff
changeset
|
839 if(len<0){ eof=1;break;} |
c2be4fb65cee
3-pass encoding support (reads frame skip/dup control and audio stream from frameno.avi)
arpi
parents:
4365
diff
changeset
|
840 if(len==0) --skip_flag; else // duplicate |
c2be4fb65cee
3-pass encoding support (reads frame skip/dup control and audio stream from frameno.avi)
arpi
parents:
4365
diff
changeset
|
841 if(len==4) next_frameno=start[0]; |
c2be4fb65cee
3-pass encoding support (reads frame skip/dup control and audio stream from frameno.avi)
arpi
parents:
4365
diff
changeset
|
842 } |
c2be4fb65cee
3-pass encoding support (reads frame skip/dup control and audio stream from frameno.avi)
arpi
parents:
4365
diff
changeset
|
843 if(eof) break; |
5572
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
844 // if(skip_flag) printf("!!!!!!!!!!!!\n"); |
4367
c2be4fb65cee
3-pass encoding support (reads frame skip/dup control and audio stream from frameno.avi)
arpi
parents:
4365
diff
changeset
|
845 skip_flag=next_frameno-decoded_frameno; |
c2be4fb65cee
3-pass encoding support (reads frame skip/dup control and audio stream from frameno.avi)
arpi
parents:
4365
diff
changeset
|
846 // find next frame: |
c2be4fb65cee
3-pass encoding support (reads frame skip/dup control and audio stream from frameno.avi)
arpi
parents:
4365
diff
changeset
|
847 while(next_frameno<=decoded_frameno){ |
c2be4fb65cee
3-pass encoding support (reads frame skip/dup control and audio stream from frameno.avi)
arpi
parents:
4365
diff
changeset
|
848 int* start; |
c2be4fb65cee
3-pass encoding support (reads frame skip/dup control and audio stream from frameno.avi)
arpi
parents:
4365
diff
changeset
|
849 int len=ds_get_packet(demuxer2->video,(unsigned char**) &start); |
c2be4fb65cee
3-pass encoding support (reads frame skip/dup control and audio stream from frameno.avi)
arpi
parents:
4365
diff
changeset
|
850 if(len<0){ eof=1;break;} |
c2be4fb65cee
3-pass encoding support (reads frame skip/dup control and audio stream from frameno.avi)
arpi
parents:
4365
diff
changeset
|
851 if(len==0) --skip_flag; else // duplicate |
c2be4fb65cee
3-pass encoding support (reads frame skip/dup control and audio stream from frameno.avi)
arpi
parents:
4365
diff
changeset
|
852 if(len==4) next_frameno=start[0]; |
c2be4fb65cee
3-pass encoding support (reads frame skip/dup control and audio stream from frameno.avi)
arpi
parents:
4365
diff
changeset
|
853 } |
c2be4fb65cee
3-pass encoding support (reads frame skip/dup control and audio stream from frameno.avi)
arpi
parents:
4365
diff
changeset
|
854 // if(eof) break; |
c2be4fb65cee
3-pass encoding support (reads frame skip/dup control and audio stream from frameno.avi)
arpi
parents:
4365
diff
changeset
|
855 // printf("Current fno=%d requested=%d skip=%d \n",decoded_frameno,fno,skip_flag); |
c2be4fb65cee
3-pass encoding support (reads frame skip/dup control and audio stream from frameno.avi)
arpi
parents:
4365
diff
changeset
|
856 } else { |
c2be4fb65cee
3-pass encoding support (reads frame skip/dup control and audio stream from frameno.avi)
arpi
parents:
4365
diff
changeset
|
857 |
2613 | 858 // check frame duplicate/drop: |
859 | |
860 if(v_timer_corr>=(float)mux_v->h.dwScale/mux_v->h.dwRate){ | |
861 v_timer_corr-=(float)mux_v->h.dwScale/mux_v->h.dwRate; | |
862 ++skip_flag; // skip | |
863 } else | |
864 while(v_timer_corr<=-(float)mux_v->h.dwScale/mux_v->h.dwRate){ | |
865 v_timer_corr+=(float)mux_v->h.dwScale/mux_v->h.dwRate; | |
866 --skip_flag; // dup | |
867 } | |
2531 | 868 |
2613 | 869 while( (v_pts_corr<=-(float)mux_v->h.dwScale/mux_v->h.dwRate && skip_flag>0) |
870 || (v_pts_corr<=-2*(float)mux_v->h.dwScale/mux_v->h.dwRate) ){ | |
871 v_pts_corr+=(float)mux_v->h.dwScale/mux_v->h.dwRate; | |
872 --skip_flag; // dup | |
873 } | |
874 if( (v_pts_corr>=(float)mux_v->h.dwScale/mux_v->h.dwRate && skip_flag<0) | |
875 || (v_pts_corr>=2*(float)mux_v->h.dwScale/mux_v->h.dwRate) ) | |
876 if(skip_flag<=0){ // we can't skip more than 1 frame now | |
877 v_pts_corr-=(float)mux_v->h.dwScale/mux_v->h.dwRate; | |
878 ++skip_flag; // skip | |
879 } | |
880 | |
4367
c2be4fb65cee
3-pass encoding support (reads frame skip/dup control and audio stream from frameno.avi)
arpi
parents:
4365
diff
changeset
|
881 } // demuxer2 |
c2be4fb65cee
3-pass encoding support (reads frame skip/dup control and audio stream from frameno.avi)
arpi
parents:
4365
diff
changeset
|
882 |
4088 | 883 #ifdef USE_DVDREAD |
884 // DVD sub: | |
885 if(vo_spudec){ | |
886 unsigned char* packet=NULL; | |
887 int len; | |
888 while((len=ds_get_packet_sub(d_dvdsub,&packet))>0){ | |
889 mp_msg(MSGT_MENCODER,MSGL_V,"\rDVD sub: len=%d v_pts=%5.3f s_pts=%5.3f \n",len,d_video->pts,d_dvdsub->pts); | |
5553
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
890 spudec_assemble(vo_spudec,packet,len,90000*d_dvdsub->pts); |
4088 | 891 } |
5553
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
892 spudec_heartbeat(vo_spudec,90000*d_video->pts); |
4088 | 893 } |
894 #endif | |
2613 | 895 |
5572
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
896 ptimer_start = GetTimerMS(); |
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
897 |
2531 | 898 switch(mux_v->codec){ |
3384 | 899 case VCODEC_COPY: |
2574 | 900 mux_v->buffer=start; |
2639 | 901 if(skip_flag<=0) aviwrite_write_chunk(muxer,mux_v,muxer_f,in_size,(sh_video->ds->flags&1)?0x10:0); |
2574 | 902 break; |
5553
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
903 case VCODEC_FRAMENO: |
3361
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
904 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
|
905 if(skip_flag<=0) aviwrite_write_chunk(muxer,mux_v,muxer_f,sizeof(int),0x10); |
4575 | 906 break; |
5553
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
907 default: |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
908 // decode_video will callback down to ve_*.c encoders, through the video filters |
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
909 blit_frame=decode_video(sh_video,start,in_size,(skip_flag>0)?1:0); |
2639 | 910 if(skip_flag>0) break; |
5553
38697931adf4
video codecs moved to libmpencoders, crop/scale removed, use -vop for that
arpi
parents:
5546
diff
changeset
|
911 if(!blit_frame) aviwrite_write_chunk(muxer,mux_v,muxer_f,0,0); // empty. |
2531 | 912 } |
2613 | 913 |
5572
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
914 videosamples++; |
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
915 videorate+=(GetTimerMS() - ptimer_start); |
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
916 |
2613 | 917 if(skip_flag<0){ |
2605 | 918 // duplicate frame |
5572
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
919 if(!tv_param_on && !verbose) printf("\nduplicate %d frame(s)!!! \n",-skip_flag); |
2613 | 920 while(skip_flag<0){ |
5572
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
921 duplicatedframes++; |
2613 | 922 aviwrite_write_chunk(muxer,mux_v,muxer_f,0,0); |
923 ++skip_flag; | |
924 } | |
2639 | 925 } else |
926 if(skip_flag>0){ | |
2605 | 927 // skip frame |
5572
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
928 if(!tv_param_on && !verbose) printf("\nskip frame!!! \n"); |
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
929 skippedframes++; |
2613 | 930 --skip_flag; |
2605 | 931 } |
932 | |
4367
c2be4fb65cee
3-pass encoding support (reads frame skip/dup control and audio stream from frameno.avi)
arpi
parents:
4365
diff
changeset
|
933 if(sh_audio && !demuxer2){ |
2605 | 934 float AV_delay,x; |
935 // A-V sync! | |
936 if(pts_from_bps){ | |
937 unsigned int samples=(sh_audio->audio.dwSampleSize)? | |
938 ((ds_tell(d_audio)-sh_audio->a_in_buffer_len)/sh_audio->audio.dwSampleSize) : | |
939 (d_audio->pack_no); // <- used for VBR audio | |
4378 | 940 // printf("samples=%d \n",samples); |
2605 | 941 a_pts=samples*(float)sh_audio->audio.dwScale/(float)sh_audio->audio.dwRate; |
942 delay_corrected=1; | |
943 } else { | |
944 // PTS = (last timestamp) + (bytes after last timestamp)/(bytes per sec) | |
945 a_pts=d_audio->pts; | |
946 if(!delay_corrected) if(a_pts) delay_corrected=1; | |
947 //printf("*** %5.3f ***\n",a_pts); | |
948 a_pts+=(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps; | |
949 } | |
950 v_pts=d_video->pts; | |
951 // av = compensated (with out buffering delay) A-V diff | |
2613 | 952 AV_delay=(a_pts-v_pts); AV_delay-=mux_a->timer-(mux_v->timer-(v_timer_corr+v_pts_corr)); |
2605 | 953 // compensate input video timer by av: |
954 x=AV_delay*0.1f; | |
955 if(x<-max_pts_correction) x=-max_pts_correction; else | |
956 if(x> max_pts_correction) x= max_pts_correction; | |
957 if(default_max_pts_correction>=0) | |
958 max_pts_correction=default_max_pts_correction; | |
959 else | |
960 max_pts_correction=sh_video->frametime*0.10; // +-10% of time | |
961 // sh_video->timer-=x; | |
962 c_total+=x; | |
2613 | 963 v_pts_corr+=x; |
4387 | 964 } |
2605 | 965 |
4387 | 966 // printf("A:%6.1f V:%6.1f A-V:%7.3f oAV:%7.3f diff:%7.3f ct:%7.3f vpc:%7.3f \r", |
967 // a_pts,v_pts,a_pts-v_pts, | |
968 // (float)(mux_a->timer-mux_v->timer), | |
969 // AV_delay, c_total, v_pts_corr ); | |
970 // printf("V:%6.1f \r", d_video->pts ); | |
2605 | 971 |
972 #if 0 | |
973 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", | |
974 a_pts,v_pts,a_pts-v_pts,c_total, | |
975 (int)sh_video->num_frames,(int)sh_video->num_frames_decoded, | |
976 (sh_video->timer>0.5)?(int)(100.0*video_time_usage/(double)sh_video->timer):0, | |
977 (sh_video->timer>0.5)?(int)(100.0*vout_time_usage/(double)sh_video->timer):0, | |
978 (sh_video->timer>0.5)?(100.0*audio_time_usage/(double)sh_video->timer):0 | |
979 ,cache_fill_status | |
980 ); | |
981 #endif | |
982 | |
4387 | 983 { float t=(GetTimerMS()-timer_start)*0.001f; |
984 float len=(demuxer->movi_end-demuxer->movi_start); | |
985 float p=len>1000 ? (float)(demuxer->filepos-demuxer->movi_start) / len : 0; | |
4393 | 986 if(!len && sh_audio && sh_audio->audio.dwLength>100){ |
987 p=(sh_audio->audio.dwSampleSize? ds_tell(sh_audio->ds)/sh_audio->audio.dwSampleSize : sh_audio->ds->pack_no) | |
988 / (float)(sh_audio->audio.dwLength); | |
989 } | |
4392
b50b2b0c65ea
status print fixes - DVD estimation worx, print remaining time instead of total
arpi
parents:
4388
diff
changeset
|
990 #if 0 |
b50b2b0c65ea
status print fixes - DVD estimation worx, print remaining time instead of total
arpi
parents:
4388
diff
changeset
|
991 mp_msg(MSGT_AVSYNC,MSGL_STATUS,"%d < %d < %d \r", |
b50b2b0c65ea
status print fixes - DVD estimation worx, print remaining time instead of total
arpi
parents:
4388
diff
changeset
|
992 (int)demuxer->movi_start, |
b50b2b0c65ea
status print fixes - DVD estimation worx, print remaining time instead of total
arpi
parents:
4388
diff
changeset
|
993 (int)demuxer->filepos, |
b50b2b0c65ea
status print fixes - DVD estimation worx, print remaining time instead of total
arpi
parents:
4388
diff
changeset
|
994 (int)demuxer->movi_end); |
b50b2b0c65ea
status print fixes - DVD estimation worx, print remaining time instead of total
arpi
parents:
4388
diff
changeset
|
995 #else |
5572
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
996 if(verbose) { |
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
997 mp_msg(MSGT_AVSYNC,MSGL_STATUS,"Pos:%6.1fs %6df (%2d%%) %3dfps Trem:%4dmin %3dmb A-V:%5.3f [%d:%d] A/Vms %d/%d D/S %d/%d \r", |
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
998 mux_v->timer, decoded_frameno, (int)(p*100), |
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
999 (t>1) ? (int)(decoded_frameno/t) : 0, |
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
1000 (p>0.001) ? (int)((t/p-t)/60) : 0, |
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
1001 (p>0.001) ? (int)(ftello(muxer_f)/p/1024/1024) : 0, |
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
1002 v_pts_corr, |
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
1003 (mux_v->timer>1) ? (int)(mux_v->size/mux_v->timer/125) : 0, |
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
1004 (mux_a && mux_a->timer>1) ? (int)(mux_a->size/mux_a->timer/125) : 0, |
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
1005 audiorate/audiosamples, videorate/videosamples, |
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
1006 duplicatedframes, skippedframes |
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
1007 ); |
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
1008 } else |
4394 | 1009 mp_msg(MSGT_AVSYNC,MSGL_STATUS,"Pos:%6.1fs %6df (%2d%%) %3dfps Trem:%4dmin %3dmb A-V:%5.3f [%d:%d]\r", |
4387 | 1010 mux_v->timer, decoded_frameno, (int)(p*100), |
1011 (t>1) ? (int)(decoded_frameno/t) : 0, | |
4392
b50b2b0c65ea
status print fixes - DVD estimation worx, print remaining time instead of total
arpi
parents:
4388
diff
changeset
|
1012 (p>0.001) ? (int)((t/p-t)/60) : 0, |
4387 | 1013 (p>0.001) ? (int)(ftell(muxer_f)/p/1024/1024) : 0, |
4394 | 1014 v_pts_corr, |
1015 (mux_v->timer>1) ? (int)(mux_v->size/mux_v->timer/125) : 0, | |
4427
6310422b9557
new video format: yuvrgb. patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4408
diff
changeset
|
1016 (mux_a && mux_a->timer>1) ? (int)(mux_a->size/mux_a->timer/125) : 0 |
4387 | 1017 ); |
4392
b50b2b0c65ea
status print fixes - DVD estimation worx, print remaining time instead of total
arpi
parents:
4388
diff
changeset
|
1018 #endif |
4387 | 1019 } |
2605 | 1020 fflush(stdout); |
1021 | |
2531 | 1022 |
1023 | |
1024 } // while(!eof) | |
1025 | |
3357 | 1026 #ifdef HAVE_MP3LAME |
1027 // fixup CBR mp3 audio header: | |
3354 | 1028 if(sh_audio && mux_a->codec==ACODEC_VBRMP3 && !lame_param_vbr){ |
1029 mux_a->h.dwSampleSize=1; | |
1030 mux_a->h.dwRate=mux_a->wf->nAvgBytesPerSec; | |
1031 mux_a->h.dwScale=1; | |
1032 printf("\n\nCBR audio effective bitrate: %8.3f kbit/s (%d bytes/sec)\n", | |
1033 mux_a->h.dwRate*8.0f/1000.0f,mux_a->h.dwRate); | |
1034 } | |
3357 | 1035 #endif |
3354 | 1036 |
2840
808fe0767cf8
fix typos - patch by Colin Marquardt <colin@marquardt-home.de>
pl
parents:
2825
diff
changeset
|
1037 printf("\nWriting AVI index...\n"); |
2531 | 1038 aviwrite_write_index(muxer,muxer_f); |
5572
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
1039 muxer_f_size=ftello(muxer_f); |
2622 | 1040 printf("Fixup AVI header...\n"); |
2531 | 1041 fseek(muxer_f,0,SEEK_SET); |
1042 aviwrite_write_header(muxer,muxer_f); // update header | |
4377 | 1043 fclose(muxer_f); |
4368 | 1044 |
1045 if(out_video_codec==VCODEC_FRAMENO && mux_v->timer>100){ | |
4392
b50b2b0c65ea
status print fixes - DVD estimation worx, print remaining time instead of total
arpi
parents:
4388
diff
changeset
|
1046 printf("Recommended video bitrate for 650MB CD: %d\n",(int)((650*1024*1024-muxer_f_size)/mux_v->timer/125)); |
b50b2b0c65ea
status print fixes - DVD estimation worx, print remaining time instead of total
arpi
parents:
4388
diff
changeset
|
1047 printf("Recommended video bitrate for 700MB CD: %d\n",(int)((700*1024*1024-muxer_f_size)/mux_v->timer/125)); |
b50b2b0c65ea
status print fixes - DVD estimation worx, print remaining time instead of total
arpi
parents:
4388
diff
changeset
|
1048 printf("Recommended video bitrate for 800MB CD: %d\n",(int)((800*1024*1024-muxer_f_size)/mux_v->timer/125)); |
4368 | 1049 } |
1050 | |
4355 | 1051 printf("\nVideo stream: %8.3f kbit/s (%d bps) size: %d bytes %5.3f secs %d frames\n", |
5572
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
1052 (float)(mux_v->size/mux_v->timer*8.0f/1000.0f), (int)(mux_v->size/mux_v->timer), (int)mux_v->size, (float)mux_v->timer, decoded_frameno); |
3361
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
1053 if(sh_audio) |
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
1054 printf("\nAudio stream: %8.3f kbit/s (%d bps) size: %d bytes %5.3f secs\n", |
5572
8cd761968f35
BSD-BT848 TV update patch by Charles Henrich <henrich@sigbus.com>
arpi
parents:
5569
diff
changeset
|
1055 (float)(mux_a->size/mux_a->timer*8.0f/1000.0f), (int)(mux_a->size/mux_a->timer), (int)mux_a->size, (float)mux_a->timer); |
3361
5d70491f438c
new video codec: frameno (just the number of frame - for 3-pass encoding)
arpi
parents:
3357
diff
changeset
|
1056 |
2618 | 1057 if(stream) free_stream(stream); // kill cache thread |
1058 | |
3320
ac8b70dd5e45
use return 1; if interrupted - patch by Artur Skawina <skawina@geocities.com>
arpi
parents:
3240
diff
changeset
|
1059 return interrupted; |
2531 | 1060 } |
4159
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1061 |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1062 static int parse_end_at(struct config *conf, const char* param) |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1063 { |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1064 int i; |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1065 |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1066 end_at_type = END_AT_NONE; |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1067 |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1068 /* End at size parsing */ |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1069 { |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1070 char unit[4]; |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1071 |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1072 end_at_type = END_AT_SIZE; |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1073 |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1074 if(sscanf(param, "%d%3s", &end_at, unit) == 2) { |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1075 if(!strcasecmp(unit, "b")) |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1076 ; |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1077 else if(!strcasecmp(unit, "kb")) |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1078 end_at *= 1024; |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1079 else if(!strcasecmp(unit, "mb")) |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1080 end_at *= 1024*1024; |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1081 else |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1082 end_at_type = END_AT_NONE; |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1083 } |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1084 else |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1085 end_at_type = END_AT_NONE; |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1086 } |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1087 |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1088 /* End at time parsing. This has to be last because of |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1089 * sscanf("%f", ...) below */ |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1090 if(end_at_type == END_AT_NONE) |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1091 { |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1092 int a,b; float d; |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1093 |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1094 end_at_type = END_AT_TIME; |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1095 |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1096 if (sscanf(param, "%d:%d:%f", &a, &b, &d) == 3) |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1097 end_at = 3600*a + 60*b + d; |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1098 else if (sscanf(param, "%d:%f", &a, &d) == 2) |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1099 end_at = 60*a + d; |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1100 else if (sscanf(param, "%f", &d) == 1) |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1101 end_at = d; |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1102 else |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1103 end_at_type = END_AT_NONE; |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1104 } |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1105 |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1106 if(end_at_type == END_AT_NONE) |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1107 return ERR_FUNC_ERR; |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1108 |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1109 return 1; |
42fec596fe7c
-endpos option, patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4156
diff
changeset
|
1110 } |
4427
6310422b9557
new video format: yuvrgb. patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4408
diff
changeset
|
1111 |
6310422b9557
new video format: yuvrgb. patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4408
diff
changeset
|
1112 /* Flip the image in src and store the result in dst. src and dst may overlap. |
6310422b9557
new video format: yuvrgb. patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4408
diff
changeset
|
1113 width is the size of each line in bytes. */ |
6310422b9557
new video format: yuvrgb. patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4408
diff
changeset
|
1114 static uint8_t* flip_upside_down(uint8_t* dst, const uint8_t* src, int width, |
6310422b9557
new video format: yuvrgb. patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4408
diff
changeset
|
1115 int height) |
6310422b9557
new video format: yuvrgb. patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4408
diff
changeset
|
1116 { |
6310422b9557
new video format: yuvrgb. patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4408
diff
changeset
|
1117 uint8_t* tmp = malloc(width); |
6310422b9557
new video format: yuvrgb. patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4408
diff
changeset
|
1118 int i; |
6310422b9557
new video format: yuvrgb. patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4408
diff
changeset
|
1119 |
6310422b9557
new video format: yuvrgb. patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4408
diff
changeset
|
1120 for(i = 0; i < height/2; i++) { |
6310422b9557
new video format: yuvrgb. patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4408
diff
changeset
|
1121 memcpy(tmp, &src[i*width], width); |
6310422b9557
new video format: yuvrgb. patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4408
diff
changeset
|
1122 memcpy(&dst[i * width], &src[(height - i) * width], width); |
6310422b9557
new video format: yuvrgb. patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4408
diff
changeset
|
1123 memcpy(&dst[(height - i) * width], tmp, width); |
6310422b9557
new video format: yuvrgb. patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4408
diff
changeset
|
1124 } |
6310422b9557
new video format: yuvrgb. patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4408
diff
changeset
|
1125 |
6310422b9557
new video format: yuvrgb. patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4408
diff
changeset
|
1126 free(tmp); |
6310422b9557
new video format: yuvrgb. patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4408
diff
changeset
|
1127 return dst; |
6310422b9557
new video format: yuvrgb. patch by Fredrik Kuivinen <freku045@student.liu.se>
arpi
parents:
4408
diff
changeset
|
1128 } |
5270 | 1129 |