2001-12-08 12:21:23 +00:00
# define VCODEC_COPY 0
2001-12-06 23:59:46 +00:00
# define VCODEC_FRAMENO 1
2002-04-11 02:52:03 +00:00
// real codecs:
2001-12-06 23:59:46 +00:00
# define VCODEC_DIVX4 2
2001-12-15 17:12:20 +00:00
# define VCODEC_LIBAVCODEC 4
2002-02-07 20:22:03 +00:00
# define VCODEC_VFW 7
2002-04-12 21:50:38 +00:00
# define VCODEC_LIBDV 8
2002-09-21 12:41:29 +00:00
# define VCODEC_XVID 9
2002-12-16 01:49:39 +00:00
# define VCODEC_QTVIDEO 10
2003-03-03 11:03:19 +00:00
# define VCODEC_NUV 11
2004-02-17 12:43:07 +00:00
# define VCODEC_RAW 12
2001-12-06 23:59:46 +00:00
2001-12-08 13:30:06 +00:00
# define ACODEC_COPY 0
2001-10-31 00:25:28 +00:00
# define ACODEC_PCM 1
# define ACODEC_VBRMP3 2
2002-01-27 00:43:57 +00:00
# define ACODEC_NULL 3
2003-11-03 16:35:40 +00:00
# define ACODEC_LAVC 4
2001-10-29 01:11:18 +00:00
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <signal.h>
2004-04-30 20:05:54 +00:00
# include "config.h"
2003-03-31 17:32:46 +00:00
# ifdef __MINGW32__
# define SIGQUIT 3
# endif
2004-04-30 16:56:00 +00:00
# ifdef WIN32
# include <windows.h>
# endif
2002-04-12 10:40:38 +00:00
# include <sys/time.h>
2001-10-29 01:11:18 +00:00
2002-09-29 19:26:40 +00:00
2001-11-18 19:12:25 +00:00
# include "version.h"
2002-09-29 19:26:40 +00:00
# include "mp_msg.h"
2001-10-29 01:11:18 +00:00
# include "help_mp.h"
2001-12-04 21:35:18 +00:00
# include "cpudetect.h"
2001-10-29 01:11:18 +00:00
# include "codec-cfg.h"
2002-11-12 01:56:42 +00:00
# include "m_option.h"
# include "m_config.h"
# include "parser-mecmd.h"
2001-10-29 01:11:18 +00:00
2002-09-29 19:26:40 +00:00
# include "libmpdemux/stream.h"
# include "libmpdemux/demuxer.h"
# include "libmpdemux/stheader.h"
# include "libmpdemux/mp3_hdr.h"
2002-12-27 22:43:20 +00:00
# include "libmpdemux/muxer.h"
2001-10-29 01:11:18 +00:00
# include "libvo/video_out.h"
2002-10-05 22:55:45 +00:00
# include "libao2/afmt.h"
2002-09-22 00:43:14 +00:00
# include "libmpcodecs/mp_image.h"
2002-04-13 19:14:34 +00:00
# include "libmpcodecs/dec_audio.h"
# include "libmpcodecs/dec_video.h"
2002-06-27 19:33:28 +00:00
# include "libmpcodecs/vf.h"
2001-10-30 21:55:28 +00:00
2002-09-22 00:43:14 +00:00
// for MPEGLAYER3WAVEFORMAT:
2004-04-28 10:18:33 +00:00
# include "libmpdemux/ms_hdr.h"
2002-09-22 00:43:14 +00:00
2001-12-06 22:27:09 +00:00
# ifdef HAVE_MP3LAME
2002-06-27 19:33:28 +00:00
# undef CDECL
2001-10-31 16:08:01 +00:00
# include <lame/lame.h>
2001-12-06 22:27:09 +00:00
# endif
2001-10-31 00:25:28 +00:00
2001-12-01 01:29:25 +00:00
# include <inttypes.h>
2002-09-29 19:26:40 +00:00
# include "libvo/fastmemcpy.h"
2001-12-08 13:30:06 +00:00
2003-02-09 20:18:23 +00:00
# include "osdep/timer.h"
2002-09-22 02:33:28 +00:00
2003-11-03 16:35:40 +00:00
# ifdef USE_LIBAVCODEC
// for lavc audio encoding
2003-11-07 23:32:38 +00:00
# ifdef USE_LIBAVCODEC_SO
# include <ffmpeg/avcodec.h>
# else
2003-11-03 16:35:40 +00:00
# include "libavcodec/avcodec.h"
2003-11-07 23:32:38 +00:00
# endif
2003-11-03 16:35:40 +00:00
static AVCodec * lavc_acodec ;
static AVCodecContext * lavc_actx = NULL ;
extern char * lavc_param_acodec ;
extern int lavc_param_abitrate ;
extern int lavc_param_atag ;
// tmp buffer for lavc audio encoding (to free!!!!!)
static void * lavc_abuf = NULL ;
extern int avcodec_inited ;
static uint32_t lavc_find_atag ( char * codec ) ;
# endif
2002-04-07 02:12:15 +00:00
int vo_doublebuffering = 0 ;
int vo_directrendering = 0 ;
int vo_config_count = 0 ;
2003-12-08 09:32:40 +00:00
int forced_subs_only = 0 ;
2002-01-27 18:39:53 +00:00
2001-10-29 01:11:18 +00:00
//--------------------------
// cache2:
2002-10-23 22:07:29 +00:00
int stream_cache_size = - 1 ;
2001-10-29 01:11:18 +00:00
# ifdef USE_STREAM_CACHE
extern int cache_fill_status ;
# else
# define cache_fill_status 0
# endif
2001-11-02 01:25:13 +00:00
int audio_id = - 1 ;
int video_id = - 1 ;
int dvdsub_id = - 1 ;
2002-03-29 03:17:57 +00:00
int vobsub_id = - 1 ;
2003-05-23 15:01:25 +00:00
char * audio_lang = NULL ;
2003-04-07 16:04:02 +00:00
char * dvdsub_lang = NULL ;
2002-03-29 03:17:57 +00:00
static char * spudec_ifo = NULL ;
2001-11-02 01:25:13 +00:00
2002-09-29 19:26:40 +00:00
static char * * audio_codec_list = NULL ; // override audio codec
static char * * video_codec_list = NULL ; // override video codec
static char * * audio_fm_list = NULL ; // override audio codec family
static char * * video_fm_list = NULL ; // override video codec family
2001-10-29 01:11:18 +00:00
2002-09-29 19:26:40 +00:00
static int out_audio_codec = - 1 ;
static int out_video_codec = - 1 ;
2002-02-10 00:07:34 +00:00
2002-12-27 22:43:20 +00:00
int out_file_format = MUXER_TYPE_AVI ; // default to AVI
2001-10-29 01:11:18 +00:00
// audio stream skip/resync functions requires only for seeking.
// (they should be implemented in the audio codec layer)
//void skip_audio_frame(sh_audio_t *sh_audio){}
//void resync_audio_stream(sh_audio_t *sh_audio){}
2001-11-02 01:25:13 +00:00
int verbose = 0 ; // must be global!
2004-01-29 12:01:26 +00:00
int quiet = 0 ;
2001-10-29 01:11:18 +00:00
double video_time_usage = 0 ;
double vout_time_usage = 0 ;
2002-02-24 11:23:48 +00:00
double max_video_time_usage = 0 ;
double max_vout_time_usage = 0 ;
2002-02-24 15:54:13 +00:00
double cur_video_time_usage = 0 ;
double cur_vout_time_usage = 0 ;
2002-02-24 17:10:06 +00:00
int benchmark = 0 ;
2001-10-29 01:11:18 +00:00
2001-11-01 02:31:23 +00:00
// A-V sync:
int delay_corrected = 1 ;
static float default_max_pts_correction = - 1 ; //0.01f;
static float max_pts_correction = 0 ; //default_max_pts_correction;
static float c_total = 0 ;
2002-09-29 19:26:40 +00:00
static float audio_preload = 0.5 ;
static float audio_delay = 0.0 ;
static int audio_density = 2 ;
2002-08-01 08:39:33 +00:00
2003-03-11 19:03:31 +00:00
float force_fps = 0 ;
2002-09-29 19:26:40 +00:00
static float force_ofps = 0 ; // set to 24 for inverse telecine
2002-04-15 02:33:05 +00:00
static int skip_limit = - 1 ;
2001-10-29 01:11:18 +00:00
2002-09-29 19:26:40 +00:00
static int force_srate = 0 ;
2002-10-06 11:23:02 +00:00
static int audio_output_format = 0 ;
2001-11-02 01:25:13 +00:00
2002-07-08 21:44:51 +00:00
char * vobsub_out = NULL ;
unsigned int vobsub_out_index = 0 ;
char * vobsub_out_id = NULL ;
2001-11-02 03:22:33 +00:00
char * out_filename = " test.avi " ;
2001-12-22 14:32:08 +00:00
char * force_fourcc = NULL ;
2002-04-11 02:52:03 +00:00
char * passtmpfile = " divx2pass.log " ;
2001-11-03 00:44:02 +00:00
static int play_n_frames = - 1 ;
2002-06-28 17:13:18 +00:00
static int play_n_frames_mf = - 1 ;
2001-11-03 00:44:02 +00:00
2002-04-17 21:51:18 +00:00
# include "libvo/font_load.h"
# include "libvo/sub.h"
// sub:
char * font_name = NULL ;
2003-12-08 12:14:32 +00:00
# ifdef HAVE_FONTCONFIG
2003-12-08 13:30:30 +00:00
extern int font_fontconfig ;
2003-12-08 12:14:32 +00:00
# endif
2002-04-17 21:51:18 +00:00
float font_factor = 0.75 ;
2003-04-07 16:04:02 +00:00
char * * sub_name = NULL ;
2002-04-17 21:51:18 +00:00
float sub_delay = 0 ;
float sub_fps = 0 ;
int sub_auto = 0 ;
2002-07-25 03:37:28 +00:00
int subcc_enabled = 0 ;
2002-12-05 00:03:35 +00:00
int suboverlap_enabled = 1 ;
2002-04-17 21:51:18 +00:00
# ifdef USE_SUB
2003-04-07 16:04:02 +00:00
static sub_data * subdata = NULL ;
2002-04-17 21:51:18 +00:00
float sub_last_pts = - 303 ;
# endif
2003-01-24 01:04:50 +00:00
int auto_expand = 1 ;
2004-04-28 04:02:46 +00:00
int encode_duplicates = 1 ;
2003-01-24 01:04:50 +00:00
2002-08-29 20:50:49 +00:00
// infos are empty by default
char * info_name = NULL ;
char * info_artist = NULL ;
char * info_genre = NULL ;
char * info_subject = NULL ;
char * info_copyright = NULL ;
char * info_sourceform = NULL ;
char * info_comment = NULL ;
2002-04-17 21:51:18 +00:00
2001-11-03 23:01:17 +00:00
//char *out_audio_codec=NULL; // override audio codec
//char *out_video_codec=NULL; // override video codec
2001-11-02 03:22:33 +00:00
2001-10-31 16:08:01 +00:00
//#include "libmpeg2/mpeg2.h"
//#include "libmpeg2/mpeg2_internal.h"
2001-12-06 22:27:09 +00:00
# ifdef HAVE_MP3LAME
2001-11-02 03:22:33 +00:00
int lame_param_quality = 0 ; // best
2002-05-01 14:42:42 +00:00
int lame_param_algqual = 5 ; // same as old default
2001-11-02 03:22:33 +00:00
int lame_param_vbr = vbr_default ;
int lame_param_mode = - 1 ; // unset
int lame_param_padding = - 1 ; // unset
int lame_param_br = - 1 ; // unset
int lame_param_ratio = - 1 ; // unset
2002-04-26 20:19:31 +00:00
float lame_param_scale = - 1 ; // unset
2004-01-23 01:13:00 +00:00
int lame_param_lowpassfreq = 0 ; //auto
int lame_param_highpassfreq = 0 ; //auto
2004-05-19 04:33:00 +00:00
int lame_param_free_format = 0 ; //disabled
int lame_param_br_min = 0 ; //not specified
int lame_param_br_max = 0 ; //not specified
2004-01-23 01:13:00 +00:00
2002-12-21 22:16:49 +00:00
# if HAVE_MP3LAME >= 392
int lame_param_fast = 0 ; // unset
static char * lame_param_preset = NULL ; // unset
static int lame_presets_set ( lame_t gfp , int fast , int cbr , const char * preset_name ) ;
static void lame_presets_longinfo_dm ( FILE * msgfp ) ;
# endif
2001-12-06 22:27:09 +00:00
# endif
2001-11-02 03:22:33 +00:00
2002-09-29 19:26:40 +00:00
//static int vo_w=0, vo_h=0;
2002-03-23 13:13:12 +00:00
2001-11-02 01:25:13 +00:00
//-------------------------- config stuff:
2002-01-14 23:38:49 +00:00
m_config_t * mconfig ;
2003-08-13 16:29:32 +00:00
extern int m_config_parse_config_file ( m_config_t * config , char * conffile ) ;
2002-11-12 01:56:42 +00:00
2003-08-13 16:29:32 +00:00
static int cfg_inc_verbose ( m_option_t * conf ) { + + verbose ; return 0 ; }
2001-11-02 01:25:13 +00:00
2003-08-13 16:29:32 +00:00
static int cfg_include ( m_option_t * conf , char * filename ) {
2002-01-14 23:38:49 +00:00
return m_config_parse_config_file ( mconfig , filename ) ;
2001-11-02 01:25:13 +00:00
}
2002-02-10 00:07:34 +00:00
static char * seek_to_sec = NULL ;
static off_t seek_to_byte = 0 ;
2003-08-13 16:29:32 +00:00
static int parse_end_at ( m_option_t * conf , const char * param ) ;
2002-09-20 18:54:22 +00:00
//static uint8_t* flip_upside_down(uint8_t* dst, const uint8_t* src, int width, int height);
2002-01-15 00:20:50 +00:00
2001-11-02 01:25:13 +00:00
# include "get_path.c"
# include "cfg-mplayer-def.h"
# include "cfg-mencoder.h"
2002-01-11 16:06:45 +00:00
# ifdef USE_DVDREAD
# include "spudec.h"
# endif
2002-03-29 03:17:57 +00:00
# include "vobsub.h"
2002-01-11 16:06:45 +00:00
2002-02-17 13:50:26 +00:00
/* FIXME */
2003-10-22 17:04:39 +00:00
static void mencoder_exit ( int level , char * how )
2002-02-17 13:50:26 +00:00
{
if ( how )
printf ( " Exiting... (%s) \n " , how ) ;
else
printf ( " Exiting... \n " ) ;
exit ( level ) ;
}
2002-02-02 23:39:53 +00:00
void parse_cfgfiles ( m_config_t * conf )
{
char * conffile ;
if ( ( conffile = get_path ( " mencoder " ) ) = = NULL ) {
mp_msg ( MSGT_CPLAYER , MSGL_ERR , MSGTR_GetpathProblem ) ;
} else {
if ( m_config_parse_config_file ( conf , conffile ) < 0 )
2002-02-17 13:50:26 +00:00
mencoder_exit ( 1 , " configfile error " ) ;
2002-02-02 23:39:53 +00:00
free ( conffile ) ;
}
}
2002-04-12 10:40:38 +00:00
2001-10-31 16:08:01 +00:00
//---------------------------------------------------------------------------
2002-09-29 19:26:40 +00:00
static int dec_audio ( sh_audio_t * sh_audio , unsigned char * buffer , int total ) {
2001-10-31 16:08:01 +00:00
int size = 0 ;
2002-06-13 21:35:10 +00:00
int at_eof = 0 ;
while ( size < total & & ! at_eof ) {
2001-10-31 16:08:01 +00:00
int len = total - size ;
if ( len > MAX_OUTBURST ) len = MAX_OUTBURST ;
2002-10-05 22:55:45 +00:00
if ( len > sh_audio - > a_out_buffer_size ) len = sh_audio - > a_out_buffer_size ;
if ( len > sh_audio - > a_out_buffer_len ) {
2001-10-31 16:08:01 +00:00
int ret = decode_audio ( sh_audio ,
2002-10-05 22:55:45 +00:00
& sh_audio - > a_out_buffer [ sh_audio - > a_out_buffer_len ] ,
len - sh_audio - > a_out_buffer_len ,
sh_audio - > a_out_buffer_size - sh_audio - > a_out_buffer_len ) ;
if ( ret > 0 ) sh_audio - > a_out_buffer_len + = ret ; else at_eof = 1 ;
2001-10-31 16:08:01 +00:00
}
2002-10-05 22:55:45 +00:00
if ( len > sh_audio - > a_out_buffer_len ) len = sh_audio - > a_out_buffer_len ;
memcpy ( buffer + size , sh_audio - > a_out_buffer , len ) ;
sh_audio - > a_out_buffer_len - = len ; size + = len ;
if ( sh_audio - > a_out_buffer_len > 0 )
memcpy ( sh_audio - > a_out_buffer , & sh_audio - > a_out_buffer [ len ] , sh_audio - > a_out_buffer_len ) ;
2001-10-31 16:08:01 +00:00
}
return size ;
}
//---------------------------------------------------------------------------
2001-10-29 01:11:18 +00:00
2002-06-13 21:35:10 +00:00
static int at_eof = 0 ;
2001-12-04 20:35:31 +00:00
static int interrupted = 0 ;
2001-10-29 01:11:18 +00:00
2002-01-15 00:20:50 +00:00
enum end_at_type_t { END_AT_NONE , END_AT_TIME , END_AT_SIZE } ;
static enum end_at_type_t end_at_type = END_AT_NONE ;
2002-12-04 23:34:29 +00:00
static double end_at ;
2002-01-15 00:20:50 +00:00
2001-10-29 01:11:18 +00:00
static void exit_sighandler ( int x ) {
2002-06-13 21:35:10 +00:00
at_eof = 1 ;
2004-01-29 12:01:26 +00:00
interrupted = 2 ; /* 1 means error */
2001-10-29 01:11:18 +00:00
}
2002-12-27 22:43:20 +00:00
static muxer_t * muxer = NULL ;
2002-09-29 19:26:40 +00:00
static FILE * muxer_f = NULL ;
2002-04-11 02:52:03 +00:00
2002-11-06 23:54:29 +00:00
extern void print_wave_header ( WAVEFORMATEX * h ) ;
2002-04-11 02:52:03 +00:00
2002-08-31 15:04:18 +00:00
int main ( int argc , char * argv [ ] ) {
2001-10-29 01:11:18 +00:00
stream_t * stream = NULL ;
demuxer_t * demuxer = NULL ;
2002-01-26 22:30:02 +00:00
stream_t * stream2 = NULL ;
demuxer_t * demuxer2 = NULL ;
2001-10-29 01:11:18 +00:00
demux_stream_t * d_audio = NULL ;
demux_stream_t * d_video = NULL ;
demux_stream_t * d_dvdsub = NULL ;
sh_audio_t * sh_audio = NULL ;
sh_video_t * sh_video = NULL ;
int file_format = DEMUXER_TYPE_UNKNOWN ;
2004-04-17 16:46:41 +00:00
int i = DEMUXER_TYPE_UNKNOWN ;
2002-07-08 21:44:51 +00:00
void * vobsub_writer = NULL ;
2001-10-29 01:11:18 +00:00
2002-04-12 10:40:38 +00:00
uint32_t ptimer_start ;
uint32_t audiorate = 0 ;
uint32_t videorate = 0 ;
uint32_t audiosamples = 1 ;
uint32_t videosamples = 1 ;
uint32_t skippedframes = 0 ;
uint32_t duplicatedframes = 0 ;
2002-09-10 23:19:20 +00:00
uint32_t badframes = 0 ;
2002-04-12 10:40:38 +00:00
2002-12-27 22:43:20 +00:00
muxer_stream_t * mux_a = NULL ;
muxer_stream_t * mux_v = NULL ;
2002-04-12 10:40:38 +00:00
off_t muxer_f_size = 0 ;
2001-10-29 01:11:18 +00:00
2001-12-06 22:27:09 +00:00
# ifdef HAVE_MP3LAME
2001-10-31 16:08:01 +00:00
lame_global_flags * lame ;
2001-12-06 22:27:09 +00:00
# endif
2001-10-31 00:25:28 +00:00
2001-11-01 21:47:28 +00:00
double v_pts_corr = 0 ;
double v_timer_corr = 0 ;
2001-11-01 02:31:23 +00:00
2002-11-12 01:56:42 +00:00
m_entry_t * filelist = NULL ;
2001-11-02 01:25:13 +00:00
char * filename = NULL ;
2002-01-26 22:30:02 +00:00
char * frameno_filename = " frameno.avi " ;
2001-11-02 01:25:13 +00:00
2001-12-06 23:59:46 +00:00
int decoded_frameno = 0 ;
2002-01-26 22:30:02 +00:00
int next_frameno = - 1 ;
2001-12-06 23:59:46 +00:00
2002-01-27 18:29:33 +00:00
unsigned int timer_start ;
2002-03-20 15:38:13 +00:00
mp_msg_init ( ) ;
mp_msg_set_level ( MSGL_STATUS ) ;
2004-01-12 03:47:49 +00:00
mp_msg ( MSGT_CPLAYER , MSGL_INFO , " MEncoder " VERSION " (C) 2000-2004 MPlayer Team \n \n " ) ;
2001-11-02 02:08:00 +00:00
2001-12-04 21:35:18 +00:00
/* Test for cpu capabilities (and corresponding OS support) for optimizing */
GetCpuCaps ( & gCpuCaps ) ;
2003-01-18 19:29:46 +00:00
# ifdef ARCH_X86
2001-12-04 21:35:18 +00:00
mp_msg ( MSGT_CPLAYER , MSGL_INFO , " CPUflags: Type: %d MMX: %d MMX2: %d 3DNow: %d 3DNow2: %d SSE: %d SSE2: %d \n " ,
gCpuCaps . cpuType , gCpuCaps . hasMMX , gCpuCaps . hasMMX2 ,
gCpuCaps . has3DNow , gCpuCaps . has3DNowExt ,
gCpuCaps . hasSSE , gCpuCaps . hasSSE2 ) ;
2003-07-22 10:46:22 +00:00
# ifdef RUNTIME_CPUDETECT
mp_msg ( MSGT_CPLAYER , MSGL_INFO , MSGTR_CompiledWithRuntimeDetection ) ;
# else
mp_msg ( MSGT_CPLAYER , MSGL_INFO , MSGTR_CompiledWithCPUExtensions ) ;
# ifdef HAVE_MMX
mp_msg ( MSGT_CPLAYER , MSGL_INFO , " MMX " ) ;
2001-12-04 21:35:18 +00:00
# endif
2003-07-22 10:46:22 +00:00
# ifdef HAVE_MMX2
mp_msg ( MSGT_CPLAYER , MSGL_INFO , " MMX2 " ) ;
# endif
# ifdef HAVE_3DNOW
mp_msg ( MSGT_CPLAYER , MSGL_INFO , " 3DNow " ) ;
# endif
# ifdef HAVE_3DNOWEX
mp_msg ( MSGT_CPLAYER , MSGL_INFO , " 3DNowEx " ) ;
# endif
# ifdef HAVE_SSE
mp_msg ( MSGT_CPLAYER , MSGL_INFO , " SSE " ) ;
# endif
# ifdef HAVE_SSE2
mp_msg ( MSGT_CPLAYER , MSGL_INFO , " SSE2 " ) ;
# endif
mp_msg ( MSGT_CPLAYER , MSGL_INFO , " \n \n " ) ;
# endif
# endif
2003-12-02 23:40:05 +00:00
InitTimer ( ) ;
2002-04-28 17:48:45 +00:00
// check codec.conf
2004-01-08 18:02:31 +00:00
if ( ! codecs_file | | ! parse_codec_cfg ( codecs_file ) ) {
if ( ! parse_codec_cfg ( get_path ( " codecs.conf " ) ) ) {
if ( ! parse_codec_cfg ( MPLAYER_CONFDIR " /codecs.conf " ) ) {
if ( ! parse_codec_cfg ( NULL ) ) {
mp_msg ( MSGT_MENCODER , MSGL_HINT , MSGTR_CopyCodecsConf ) ;
mencoder_exit ( 1 , NULL ) ;
}
mp_msg ( MSGT_MENCODER , MSGL_INFO , MSGTR_BuiltinCodecsConf ) ;
2002-12-15 23:45:19 +00:00
}
2002-04-28 17:48:45 +00:00
}
}
2002-11-12 01:56:42 +00:00
// FIXME: get rid of -dvd and other tricky options
2002-01-26 22:30:02 +00:00
stream2 = open_stream ( frameno_filename , 0 , & i ) ;
if ( stream2 ) {
2003-01-19 00:21:54 +00:00
demuxer2 = demux_open ( stream2 , DEMUXER_TYPE_AVI , - 1 , - 1 , - 2 , NULL ) ;
2002-08-07 18:24:25 +00:00
if ( demuxer2 ) printf ( MSGTR_UsingPass3ControllFile , frameno_filename ) ;
2003-01-12 19:41:38 +00:00
else mp_msg ( MSGT_DEMUXER , MSGL_ERR , MSGTR_FormatNotRecognized ) ;
2002-01-26 22:30:02 +00:00
}
2002-11-12 01:56:42 +00:00
mconfig = m_config_new ( ) ;
m_config_register_options ( mconfig , mencoder_opts ) ;
parse_cfgfiles ( mconfig ) ;
filelist = m_config_parse_me_command_line ( mconfig , argc , argv ) ;
if ( ! filelist ) mencoder_exit ( 1 , " error parsing cmdline " ) ;
m_entry_set_options ( mconfig , & filelist [ 0 ] ) ;
filename = filelist [ 0 ] . name ;
2002-01-14 23:38:49 +00:00
2003-03-30 17:07:31 +00:00
if ( ! filename ) {
2002-08-07 18:24:25 +00:00
printf ( MSGTR_MissingFilename ) ;
2002-02-17 13:50:26 +00:00
mencoder_exit ( 1 , NULL ) ;
2001-11-02 01:25:13 +00:00
}
2002-03-20 15:38:13 +00:00
mp_msg_set_level ( verbose + MSGL_STATUS ) ;
2001-10-31 22:59:56 +00:00
2002-06-02 15:25:52 +00:00
// check font
# ifdef USE_OSD
2002-08-28 20:52:02 +00:00
# ifdef HAVE_FREETYPE
init_freetype ( ) ;
2003-12-08 12:14:32 +00:00
# endif
# ifdef HAVE_FONTCONFIG
if ( ! font_fontconfig )
{
# endif
2002-06-02 15:25:52 +00:00
if ( font_name ) {
vo_font = read_font_desc ( font_name , font_factor , verbose > 1 ) ;
if ( ! vo_font ) mp_msg ( MSGT_CPLAYER , MSGL_ERR , MSGTR_CantLoadFont , font_name ) ;
} else {
// try default:
vo_font = read_font_desc ( get_path ( " font/font.desc " ) , font_factor , verbose > 1 ) ;
if ( ! vo_font )
2003-06-09 12:15:48 +00:00
vo_font = read_font_desc ( MPLAYER_DATADIR " /font/font.desc " , font_factor , verbose > 1 ) ;
2002-06-02 15:25:52 +00:00
}
2003-12-08 12:14:32 +00:00
# ifdef HAVE_FONTCONFIG
}
2002-08-28 20:52:02 +00:00
# endif
2002-06-02 15:25:52 +00:00
# endif
vo_init_osd ( ) ;
2003-03-30 17:07:31 +00:00
stream = open_stream ( filename , 0 , & file_format ) ;
2001-10-29 01:11:18 +00:00
if ( ! stream ) {
2002-08-07 18:24:25 +00:00
printf ( MSGTR_CannotOpenFile_Device ) ;
2002-02-17 13:50:26 +00:00
mencoder_exit ( 1 , NULL ) ;
2001-10-29 01:11:18 +00:00
}
printf ( " success: format: %d data: 0x%X - 0x%X \n " , file_format , ( int ) ( stream - > start_pos ) , ( int ) ( stream - > end_pos ) ) ;
2002-03-31 22:01:54 +00:00
# ifdef USE_DVDREAD
if ( stream - > type = = STREAMTYPE_DVD ) {
if ( audio_lang & & audio_id = = - 1 ) audio_id = dvd_aid_from_lang ( stream , audio_lang ) ;
if ( dvdsub_lang & & dvdsub_id = = - 1 ) dvdsub_id = dvd_sid_from_lang ( stream , dvdsub_lang ) ;
}
# endif
2002-04-15 00:36:21 +00:00
stream - > start_pos + = seek_to_byte ;
2001-10-29 01:11:18 +00:00
2002-10-23 22:07:29 +00:00
if ( stream_cache_size > 0 ) stream_enable_cache ( stream , stream_cache_size * 1024 , 0 , 0 ) ;
2002-04-15 00:36:21 +00:00
2002-09-28 18:45:47 +00:00
if ( demuxer2 ) audio_id = - 2 ; /* do NOT read audio packets... */
2002-01-26 16:32:06 +00:00
2001-11-13 21:43:29 +00:00
//demuxer=demux_open(stream,file_format,video_id,audio_id,dvdsub_id);
2003-01-19 00:21:54 +00:00
demuxer = demux_open ( stream , file_format , audio_id , video_id , dvdsub_id , filename ) ;
2001-10-29 01:11:18 +00:00
if ( ! demuxer ) {
2003-01-12 19:41:38 +00:00
mp_msg ( MSGT_DEMUXER , MSGL_ERR , MSGTR_FormatNotRecognized ) ;
2002-08-07 18:24:25 +00:00
printf ( MSGTR_CannotOpenDemuxer ) ;
2002-02-17 13:50:26 +00:00
mencoder_exit ( 1 , NULL ) ;
2001-10-29 01:11:18 +00:00
}
2002-01-26 22:30:02 +00:00
d_audio = demuxer2 ? demuxer2 - > audio : demuxer - > audio ;
2001-10-29 01:11:18 +00:00
d_video = demuxer - > video ;
d_dvdsub = demuxer - > sub ;
sh_audio = d_audio - > sh ;
sh_video = d_video - > sh ;
2003-11-23 19:30:05 +00:00
if ( ! sh_video )
{
mp_msg ( MSGT_CPLAYER , MSGL_FATAL , " Video stream is mandatory! \n " ) ;
mencoder_exit ( 1 , NULL ) ;
}
2001-10-29 01:11:18 +00:00
if ( ! video_read_properties ( sh_video ) ) {
2002-10-19 20:26:04 +00:00
printf ( MSGTR_CannotReadVideoProperties ) ;
2002-02-17 13:50:26 +00:00
mencoder_exit ( 1 , NULL ) ;
2001-10-29 01:11:18 +00:00
}
2001-11-02 02:08:00 +00:00
mp_msg ( MSGT_MENCODER , MSGL_INFO , " [V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.2f ftime:=%6.4f \n " ,
2001-10-29 01:11:18 +00:00
demuxer - > file_format , sh_video - > format , sh_video - > disp_w , sh_video - > disp_h ,
sh_video - > fps , sh_video - > frametime
) ;
2002-03-18 01:51:47 +00:00
2002-12-04 23:37:17 +00:00
if ( force_fps ) {
sh_video - > fps = force_fps ;
sh_video - > frametime = 1.0f / sh_video - > fps ;
mp_msg ( MSGT_MENCODER , MSGL_INFO , " input fps will be interpreted as %5.2f instead \n " , sh_video - > fps ) ;
}
2004-03-09 14:46:34 +00:00
if ( sh_audio & & out_file_format = = MUXER_TYPE_RAWVIDEO ) {
mp_msg ( MSGT_MENCODER , MSGL_ERR , " Output file format RAWVIDEO does not support audio - disabling audio \n " ) ;
sh_audio = NULL ;
}
2002-08-05 13:41:32 +00:00
if ( sh_audio & & out_audio_codec < 0 ) {
2003-01-05 14:18:53 +00:00
if ( audio_id = = - 2 )
2003-01-05 14:35:35 +00:00
mp_msg ( MSGT_MENCODER , MSGL_ERR , " This demuxer doesn't support -nosound yet. \n " ) ;
2002-08-07 18:24:25 +00:00
mp_msg ( MSGT_MENCODER , MSGL_FATAL , MSGTR_NoAudioEncoderSelected ) ;
2002-08-05 13:41:32 +00:00
mencoder_exit ( 1 , NULL ) ;
}
if ( sh_video & & out_video_codec < 0 ) {
2002-08-07 18:24:25 +00:00
mp_msg ( MSGT_MENCODER , MSGL_FATAL , MSGTR_NoVideoEncoderSelected ) ;
2002-08-05 13:41:32 +00:00
mencoder_exit ( 1 , NULL ) ;
}
2002-02-10 00:07:34 +00:00
if ( sh_audio & & ( out_audio_codec | | seek_to_sec | | ! sh_audio - > wf ) ) {
2001-10-30 23:17:35 +00:00
// Go through the codec.conf and find the best codec...
2002-09-25 23:45:34 +00:00
mp_msg ( MSGT_CPLAYER , MSGL_INFO , " ========================================================================== \n " ) ;
2002-09-28 02:23:20 +00:00
if ( ! init_best_audio_codec ( sh_audio , audio_codec_list , audio_fm_list ) ) {
2002-09-25 23:45:34 +00:00
sh_audio = d_audio - > sh = NULL ; // failed to init :(
2001-10-30 23:17:35 +00:00
}
2002-09-25 23:45:34 +00:00
mp_msg ( MSGT_CPLAYER , MSGL_INFO , " ========================================================================== \n " ) ;
2001-10-30 23:17:35 +00:00
}
2001-10-29 01:11:18 +00:00
// set up video encoder:
2002-07-08 21:44:51 +00:00
if ( vobsub_out ) {
unsigned int palette [ 16 ] , width , height ;
unsigned char tmp [ 3 ] = { 0 , 0 , 0 } ;
if ( spudec_ifo & & vobsub_parse_ifo ( NULL , spudec_ifo , palette , & width , & height , 1 , dvdsub_id , tmp ) > = 0 )
vobsub_writer = vobsub_out_open ( vobsub_out , palette , sh_video - > disp_w , sh_video - > disp_h ,
2002-09-01 14:30:55 +00:00
vobsub_out_id ? vobsub_out_id : ( char * ) tmp , vobsub_out_index ) ;
2002-07-08 21:44:51 +00:00
# ifdef USE_DVDREAD
if ( vobsub_writer = = NULL ) {
char tmp [ 3 ] ;
if ( vobsub_out_id = = NULL & & stream - > type = = STREAMTYPE_DVD ) {
int i ;
dvd_priv_t * dvd = ( dvd_priv_t * ) stream - > priv ;
for ( i = 0 ; i < dvd - > nr_of_subtitles ; + + i )
if ( dvd - > subtitles [ i ] . id = = dvdsub_id ) {
tmp [ 0 ] = ( dvd - > subtitles [ i ] . language > > 8 ) & 0xff ;
tmp [ 1 ] = dvd - > subtitles [ i ] . language & 0xff ;
tmp [ 2 ] = 0 ;
vobsub_out_id = tmp ;
break ;
}
}
vobsub_writer = vobsub_out_open ( vobsub_out , stream - > type = = STREAMTYPE_DVD ? ( ( dvd_priv_t * ) ( stream - > priv ) ) - > cur_pgc - > palette : NULL ,
sh_video - > disp_w , sh_video - > disp_h , vobsub_out_id , vobsub_out_index ) ;
}
# endif
}
else {
2002-03-29 03:17:57 +00:00
if ( spudec_ifo ) {
unsigned int palette [ 16 ] , width , height ;
2002-07-08 21:44:51 +00:00
if ( vobsub_parse_ifo ( NULL , spudec_ifo , palette , & width , & height , 1 , - 1 , NULL ) > = 0 )
2002-03-29 03:17:57 +00:00
vo_spudec = spudec_new_scaled ( palette , sh_video - > disp_w , sh_video - > disp_h ) ;
}
2002-01-11 16:06:45 +00:00
# ifdef USE_DVDREAD
2002-03-29 15:12:41 +00:00
if ( vo_spudec = = NULL ) {
2002-02-06 22:55:47 +00:00
vo_spudec = spudec_new_scaled ( stream - > type = = STREAMTYPE_DVD ? ( ( dvd_priv_t * ) ( stream - > priv ) ) - > cur_pgc - > palette : NULL ,
2002-01-11 16:06:45 +00:00
sh_video - > disp_w , sh_video - > disp_h ) ;
2002-03-29 03:17:57 +00:00
}
2002-01-11 16:06:45 +00:00
# endif
2002-07-08 21:44:51 +00:00
}
2002-01-11 16:06:45 +00:00
2002-04-17 21:51:18 +00:00
# ifdef USE_SUB
// after reading video params we should load subtitles because
// we know fps so now we can adjust subtitles time to ~6 seconds AST
// check .sub
// current_module="read_subtitles_file";
2003-04-07 16:04:02 +00:00
if ( sub_name & & sub_name [ 0 ] ) {
subdata = sub_read_file ( sub_name [ 0 ] , sh_video - > fps ) ;
if ( ! subdata ) mp_msg ( MSGT_CPLAYER , MSGL_ERR , MSGTR_CantLoadSub , sub_name [ 0 ] ) ;
2002-04-17 21:51:18 +00:00
} else
if ( sub_auto ) { // auto load sub file ...
2003-04-07 16:04:02 +00:00
subdata = sub_read_file ( filename ? sub_filenames ( get_path ( " sub/ " ) , filename ) [ 0 ]
2002-04-17 21:51:18 +00:00
: " default.sub " , sh_video - > fps ) ;
}
# endif
2003-12-08 09:32:40 +00:00
// Apply current settings for forced subs
spudec_set_forced_subs_only ( vo_spudec , forced_subs_only ) ;
2002-04-17 21:51:18 +00:00
2001-10-29 01:11:18 +00:00
// set up output file:
2001-11-02 03:22:33 +00:00
muxer_f = fopen ( out_filename , " wb " ) ;
2001-11-13 23:43:33 +00:00
if ( ! muxer_f ) {
2002-08-07 18:24:25 +00:00
printf ( MSGTR_CannotOpenOutputFile , out_filename ) ;
2002-02-17 13:50:26 +00:00
mencoder_exit ( 1 , NULL ) ;
2001-11-13 23:43:33 +00:00
}
2003-01-19 01:48:52 +00:00
muxer = muxer_new_muxer ( out_file_format , muxer_f ) ;
2001-10-30 23:17:35 +00:00
// ============= VIDEO ===============
2002-12-27 22:43:20 +00:00
mux_v = muxer_new_stream ( muxer , MUXER_TYPE_VIDEO ) ;
2001-10-29 01:11:18 +00:00
2002-02-07 20:22:03 +00:00
mux_v - > buffer_size = 0x200000 ; // 2MB
2001-10-29 01:11:18 +00:00
mux_v - > buffer = malloc ( mux_v - > buffer_size ) ;
mux_v - > source = sh_video ;
mux_v - > h . dwSampleSize = 0 ; // VBR
2004-02-10 14:12:26 +00:00
# ifdef USE_LIBAVCODEC
{
AVRational q = av_d2q ( force_ofps ? force_ofps : sh_video - > fps , 30000 ) ;
mux_v - > h . dwScale = q . den ;
mux_v - > h . dwRate = q . num ;
}
# else
2001-10-29 01:11:18 +00:00
mux_v - > h . dwScale = 10000 ;
2001-11-01 21:47:28 +00:00
mux_v - > h . dwRate = mux_v - > h . dwScale * ( force_ofps ? force_ofps : sh_video - > fps ) ;
2004-02-10 14:12:26 +00:00
# endif
2001-10-29 01:11:18 +00:00
2001-11-03 23:01:17 +00:00
mux_v - > codec = out_video_codec ;
2001-10-30 21:55:28 +00:00
2002-04-11 02:52:03 +00:00
mux_v - > bih = NULL ;
sh_video - > codec = NULL ;
sh_video - > video_out = NULL ;
sh_video - > vfilter = NULL ; // fixme!
2001-10-29 01:11:18 +00:00
switch ( mux_v - > codec ) {
2001-12-08 12:21:23 +00:00
case VCODEC_COPY :
if ( sh_video - > bih )
mux_v - > bih = sh_video - > bih ;
else
{
2004-06-08 16:43:24 +00:00
mux_v - > bih = calloc ( 1 , sizeof ( BITMAPINFOHEADER ) ) ;
2001-12-08 12:21:23 +00:00
mux_v - > bih - > biSize = sizeof ( BITMAPINFOHEADER ) ;
mux_v - > bih - > biWidth = sh_video - > disp_w ;
mux_v - > bih - > biHeight = sh_video - > disp_h ;
mux_v - > bih - > biCompression = sh_video - > format ;
mux_v - > bih - > biPlanes = 1 ;
mux_v - > bih - > biBitCount = 24 ; // FIXME!!!
mux_v - > bih - > biSizeImage = mux_v - > bih - > biWidth * mux_v - > bih - > biHeight * ( mux_v - > bih - > biBitCount / 8 ) ;
}
printf ( " videocodec: framecopy (%dx%d %dbpp fourcc=%x) \n " ,
mux_v - > bih - > biWidth , mux_v - > bih - > biHeight ,
mux_v - > bih - > biBitCount , mux_v - > bih - > biCompression ) ;
2001-10-29 01:11:18 +00:00
break ;
2001-12-06 23:59:46 +00:00
case VCODEC_FRAMENO :
2004-06-08 16:43:24 +00:00
mux_v - > bih = calloc ( 1 , sizeof ( BITMAPINFOHEADER ) ) ;
2001-12-06 23:59:46 +00:00
mux_v - > bih - > biSize = sizeof ( BITMAPINFOHEADER ) ;
2002-09-29 19:26:40 +00:00
mux_v - > bih - > biWidth = sh_video - > disp_w ;
mux_v - > bih - > biHeight = sh_video - > disp_h ;
2001-12-06 23:59:46 +00:00
mux_v - > bih - > biPlanes = 1 ;
mux_v - > bih - > biBitCount = 24 ;
mux_v - > bih - > biCompression = mmioFOURCC ( ' F ' , ' r ' , ' N ' , ' o ' ) ;
mux_v - > bih - > biSizeImage = mux_v - > bih - > biWidth * mux_v - > bih - > biHeight * ( mux_v - > bih - > biBitCount / 8 ) ;
break ;
2002-04-11 02:52:03 +00:00
default :
2001-12-08 01:43:02 +00:00
2002-04-11 02:52:03 +00:00
switch ( mux_v - > codec ) {
case VCODEC_DIVX4 :
2002-06-27 19:33:28 +00:00
sh_video - > vfilter = vf_open_encoder ( NULL , " divx4 " , ( char * ) mux_v ) ; break ;
2002-04-11 02:52:03 +00:00
case VCODEC_LIBAVCODEC :
2002-06-27 19:33:28 +00:00
sh_video - > vfilter = vf_open_encoder ( NULL , " lavc " , ( char * ) mux_v ) ; break ;
2004-02-17 12:43:07 +00:00
case VCODEC_RAW :
sh_video - > vfilter = vf_open_encoder ( NULL , " raw " , ( char * ) mux_v ) ; break ;
2002-04-11 02:52:03 +00:00
case VCODEC_VFW :
2002-06-27 19:33:28 +00:00
sh_video - > vfilter = vf_open_encoder ( NULL , " vfw " , ( char * ) mux_v ) ; break ;
2002-04-12 21:50:38 +00:00
case VCODEC_LIBDV :
2002-06-27 19:33:28 +00:00
sh_video - > vfilter = vf_open_encoder ( NULL , " libdv " , ( char * ) mux_v ) ; break ;
2002-09-21 12:41:29 +00:00
case VCODEC_XVID :
sh_video - > vfilter = vf_open_encoder ( NULL , " xvid " , ( char * ) mux_v ) ; break ;
2002-12-16 01:49:39 +00:00
case VCODEC_QTVIDEO :
sh_video - > vfilter = vf_open_encoder ( NULL , " qtvideo " , ( char * ) mux_v ) ; break ;
2003-03-03 11:03:19 +00:00
case VCODEC_NUV :
sh_video - > vfilter = vf_open_encoder ( NULL , " nuv " , ( char * ) mux_v ) ; break ;
2002-01-26 20:18:59 +00:00
}
2002-04-11 02:52:03 +00:00
if ( ! mux_v - > bih | | ! sh_video - > vfilter ) {
2002-08-07 18:24:25 +00:00
mp_msg ( MSGT_MENCODER , MSGL_FATAL , MSGTR_EncoderOpenFailed ) ;
2002-04-11 02:52:03 +00:00
mencoder_exit ( 1 , NULL ) ;
2002-01-26 20:18:59 +00:00
}
2002-04-17 21:51:18 +00:00
// append 'expand' filter, it fixes stride problems and renders osd:
2003-03-15 18:50:58 +00:00
if ( auto_expand ) {
char * vf_args [ ] = { " osd " , " 1 " , NULL } ;
sh_video - > vfilter = vf_open_filter ( sh_video - > vfilter , " expand " , vf_args ) ;
}
2002-04-11 02:52:03 +00:00
sh_video - > vfilter = append_filters ( sh_video - > vfilter ) ;
2002-09-25 23:45:34 +00:00
mp_msg ( MSGT_CPLAYER , MSGL_INFO , " ========================================================================== \n " ) ;
2002-09-26 01:31:18 +00:00
init_best_video_codec ( sh_video , video_codec_list , video_fm_list ) ;
2002-09-25 23:45:34 +00:00
mp_msg ( MSGT_CPLAYER , MSGL_INFO , " ========================================================================== \n " ) ;
if ( ! sh_video - > inited ) mencoder_exit ( 1 , NULL ) ;
2001-12-22 14:32:08 +00:00
}
/* force output fourcc to .. */
2002-01-26 20:18:59 +00:00
if ( ( force_fourcc ! = NULL ) & & ( strlen ( force_fourcc ) > = 4 ) )
2001-12-22 14:32:08 +00:00
{
mux_v - > bih - > biCompression = mmioFOURCC ( force_fourcc [ 0 ] , force_fourcc [ 1 ] ,
force_fourcc [ 2 ] , force_fourcc [ 3 ] ) ;
2002-08-07 18:24:25 +00:00
printf ( MSGTR_ForcingOutputFourcc ,
2002-01-26 20:18:59 +00:00
mux_v - > bih - > biCompression , ( char * ) & mux_v - > bih - > biCompression ) ;
2001-10-29 01:11:18 +00:00
}
2002-11-02 00:45:12 +00:00
//if(demuxer->file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf!
2002-01-27 02:31:06 +00:00
2001-10-30 23:17:35 +00:00
// ============= AUDIO ===============
if ( sh_audio ) {
2002-12-27 22:43:20 +00:00
mux_a = muxer_new_stream ( muxer , MUXER_TYPE_AUDIO ) ;
2001-10-30 23:17:35 +00:00
mux_a - > buffer_size = 0x100000 ; //16384;
mux_a - > buffer = malloc ( mux_a - > buffer_size ) ;
2004-02-18 13:33:16 +00:00
if ( ! mux_a - > buffer )
mencoder_exit ( 1 , " memory allocation failed " ) ;
2001-10-30 23:17:35 +00:00
mux_a - > source = sh_audio ;
2001-11-03 23:01:17 +00:00
mux_a - > codec = out_audio_codec ;
2001-10-30 23:17:35 +00:00
switch ( mux_a - > codec ) {
2001-12-08 13:30:06 +00:00
case ACODEC_COPY :
2002-01-27 01:23:23 +00:00
if ( sh_audio - > wf ) {
2001-12-08 13:30:06 +00:00
mux_a - > wf = sh_audio - > wf ;
2002-01-27 02:31:06 +00:00
if ( ! sh_audio - > i_bps ) sh_audio - > i_bps = mux_a - > wf - > nAvgBytesPerSec ;
2002-01-27 01:23:23 +00:00
} else {
2001-12-08 13:30:06 +00:00
mux_a - > wf = malloc ( sizeof ( WAVEFORMATEX ) ) ;
2002-01-27 02:31:06 +00:00
mux_a - > wf - > nBlockAlign = 1 ; //mux_a->h.dwSampleSize;
2002-10-06 23:24:36 +00:00
mux_a - > wf - > wFormatTag = sh_audio - > format ;
2001-12-08 13:30:06 +00:00
mux_a - > wf - > nChannels = sh_audio - > channels ;
mux_a - > wf - > nSamplesPerSec = sh_audio - > samplerate ;
2002-01-27 01:23:23 +00:00
mux_a - > wf - > nAvgBytesPerSec = sh_audio - > i_bps ; //mux_a->h.dwSampleSize*mux_a->wf->nSamplesPerSec;
2001-12-13 17:50:19 +00:00
mux_a - > wf - > wBitsPerSample = 16 ; // FIXME
2001-12-08 13:30:06 +00:00
mux_a - > wf - > cbSize = 0 ; // FIXME for l3codeca.acm
}
2002-01-27 02:31:06 +00:00
if ( sh_audio - > audio . dwScale ) {
mux_a - > h . dwSampleSize = sh_audio - > audio . dwSampleSize ;
mux_a - > h . dwScale = sh_audio - > audio . dwScale ;
mux_a - > h . dwRate = sh_audio - > audio . dwRate ;
2002-08-01 08:39:33 +00:00
// mux_a->h.dwStart=sh_audio->audio.dwStart;
2002-01-27 02:31:06 +00:00
} else {
mux_a - > h . dwSampleSize = mux_a - > wf - > nBlockAlign ;
mux_a - > h . dwScale = mux_a - > h . dwSampleSize ;
mux_a - > h . dwRate = mux_a - > wf - > nAvgBytesPerSec ;
}
2002-11-06 23:54:29 +00:00
printf ( " audiocodec: framecopy (format=%x chans=%d rate=%ld bits=%d bps=%ld sample=%ld) \n " ,
2001-12-08 13:30:06 +00:00
mux_a - > wf - > wFormatTag , mux_a - > wf - > nChannels , mux_a - > wf - > nSamplesPerSec ,
2002-01-27 02:31:06 +00:00
mux_a - > wf - > wBitsPerSample , mux_a - > wf - > nAvgBytesPerSec , mux_a - > h . dwSampleSize ) ;
2001-10-30 23:17:35 +00:00
break ;
2001-10-31 00:25:28 +00:00
case ACODEC_PCM :
printf ( " CBR PCM audio selected \n " ) ;
mux_a - > h . dwScale = 1 ;
2002-10-05 22:55:45 +00:00
mux_a - > h . dwRate = force_srate ? force_srate : sh_audio - > samplerate ;
2001-10-31 00:25:28 +00:00
mux_a - > wf = malloc ( sizeof ( WAVEFORMATEX ) ) ;
mux_a - > wf - > wFormatTag = 0x1 ; // PCM
2002-10-05 22:55:45 +00:00
mux_a - > wf - > nChannels = audio_output_channels ? audio_output_channels : sh_audio - > channels ;
2003-03-29 16:47:20 +00:00
mux_a - > h . dwSampleSize = 2 * mux_a - > wf - > nChannels ;
mux_a - > wf - > nBlockAlign = mux_a - > h . dwSampleSize ;
2002-10-05 22:55:45 +00:00
mux_a - > wf - > nSamplesPerSec = mux_a - > h . dwRate ;
2001-10-31 00:25:28 +00:00
mux_a - > wf - > nAvgBytesPerSec = mux_a - > h . dwSampleSize * mux_a - > wf - > nSamplesPerSec ;
mux_a - > wf - > wBitsPerSample = 16 ;
mux_a - > wf - > cbSize = 0 ; // FIXME for l3codeca.acm
2002-10-05 22:55:45 +00:00
// setup filter:
if ( ! init_audio_filters ( sh_audio ,
sh_audio - > samplerate ,
sh_audio - > channels , sh_audio - > sample_format , sh_audio - > samplesize ,
mux_a - > wf - > nSamplesPerSec , mux_a - > wf - > nChannels ,
( mux_a - > wf - > wBitsPerSample = = 8 ) ? AFMT_U8 : AFMT_S16_LE ,
mux_a - > wf - > wBitsPerSample / 8 ,
16384 , mux_a - > wf - > nAvgBytesPerSec ) ) {
mp_msg ( MSGT_CPLAYER , MSGL_ERR , " Couldn't find matching filter / ao format! \n " ) ;
}
2001-10-31 00:25:28 +00:00
break ;
2002-10-06 10:49:41 +00:00
# ifdef HAVE_MP3LAME
2001-10-30 23:17:35 +00:00
case ACODEC_VBRMP3 :
2001-12-08 13:30:06 +00:00
printf ( " MP3 audio selected \n " ) ;
2001-10-30 23:17:35 +00:00
mux_a - > h . dwSampleSize = 0 ; // VBR
2002-04-18 17:28:48 +00:00
mux_a - > h . dwRate = force_srate ? force_srate : sh_audio - > samplerate ;
mux_a - > h . dwScale = ( mux_a - > h . dwRate < 32000 ) ? 576 : 1152 ; // samples/frame
2001-11-02 17:43:05 +00:00
if ( sizeof ( MPEGLAYER3WAVEFORMAT ) ! = 30 ) mp_msg ( MSGT_MENCODER , MSGL_WARN , " sizeof(MPEGLAYER3WAVEFORMAT)==%d!=30, maybe broken C compiler? \n " , sizeof ( MPEGLAYER3WAVEFORMAT ) ) ;
mux_a - > wf = malloc ( sizeof ( MPEGLAYER3WAVEFORMAT ) ) ; // should be 30
2001-10-30 23:17:35 +00:00
mux_a - > wf - > wFormatTag = 0x55 ; // MP3
2002-10-05 22:55:45 +00:00
mux_a - > wf - > nChannels = ( lame_param_mode < 0 ) ? sh_audio - > channels :
( ( lame_param_mode = = 3 ) ? 1 : 2 ) ;
mux_a - > wf - > nSamplesPerSec = mux_a - > h . dwRate ;
2001-11-02 17:43:05 +00:00
mux_a - > wf - > nAvgBytesPerSec = 192000 / 8 ; // FIXME!
2002-06-23 17:34:29 +00:00
mux_a - > wf - > nBlockAlign = ( mux_a - > h . dwRate < 32000 ) ? 576 : 1152 ; // required for l3codeca.acm + WMP 6.4
2001-11-02 17:43:05 +00:00
mux_a - > wf - > wBitsPerSample = 0 ; //16;
// from NaNdub: (requires for l3codeca.acm)
mux_a - > wf - > cbSize = 12 ;
( ( MPEGLAYER3WAVEFORMAT * ) ( mux_a - > wf ) ) - > wID = 1 ;
( ( MPEGLAYER3WAVEFORMAT * ) ( mux_a - > wf ) ) - > fdwFlags = 2 ;
2002-04-18 17:28:48 +00:00
( ( MPEGLAYER3WAVEFORMAT * ) ( mux_a - > wf ) ) - > nBlockSize = ( mux_a - > h . dwRate < 32000 ) ? 576 : 1152 ; // ???
2001-11-02 17:43:05 +00:00
( ( MPEGLAYER3WAVEFORMAT * ) ( mux_a - > wf ) ) - > nFramesPerBlock = 1 ;
( ( MPEGLAYER3WAVEFORMAT * ) ( mux_a - > wf ) ) - > nCodecDelay = 0 ;
2002-10-05 22:55:45 +00:00
// setup filter:
if ( ! init_audio_filters ( sh_audio ,
sh_audio - > samplerate ,
sh_audio - > channels , sh_audio - > sample_format , sh_audio - > samplesize ,
mux_a - > wf - > nSamplesPerSec , mux_a - > wf - > nChannels ,
2002-11-03 09:54:49 +00:00
# ifdef WORDS_BIGENDIAN
AFMT_S16_BE , 2 ,
# else
2002-10-05 22:55:45 +00:00
AFMT_S16_LE , 2 ,
2002-11-03 09:54:49 +00:00
# endif
2002-10-05 22:55:45 +00:00
4608 , mux_a - > h . dwRate * mux_a - > wf - > nChannels * 2 ) ) {
mp_msg ( MSGT_CPLAYER , MSGL_ERR , " Couldn't find matching filter / ao format! \n " ) ;
}
2001-10-30 23:17:35 +00:00
break ;
2002-10-06 10:49:41 +00:00
# endif
2003-11-03 16:35:40 +00:00
# ifdef USE_LIBAVCODEC
case ACODEC_LAVC :
if ( ! lavc_param_acodec )
{
mp_msg ( MSGT_MENCODER , MSGL_FATAL , " Audio LAVC, Missing codec name! \n " ) ;
exit ( 1 ) ;
}
if ( ! avcodec_inited ) {
avcodec_init ( ) ;
avcodec_register_all ( ) ;
avcodec_inited = 1 ;
}
lavc_acodec = avcodec_find_encoder_by_name ( lavc_param_acodec ) ;
if ( ! lavc_acodec )
{
mp_msg ( MSGT_MENCODER , MSGL_FATAL , " Audio LAVC, couldn't find encoder for codec %s \n " , lavc_param_acodec ) ;
exit ( 1 ) ;
}
lavc_actx = avcodec_alloc_context ( ) ;
if ( lavc_actx = = NULL )
{
mp_msg ( MSGT_MENCODER , MSGL_FATAL , " Audio LAVC, couldn't allocate context! \n " ) ;
exit ( 1 ) ;
}
if ( lavc_param_atag = = 0 )
lavc_param_atag = lavc_find_atag ( lavc_param_acodec ) ;
// put sample parameters
lavc_actx - > channels = audio_output_channels ? audio_output_channels : sh_audio - > channels ;
lavc_actx - > sample_rate = force_srate ? force_srate : sh_audio - > samplerate ;
lavc_actx - > bit_rate = lavc_param_abitrate * 1000 ;
/*
* Special case for imaadpcm .
* The bitrate is only dependant on samplerate .
* We have to known frame_size and block_align in advance ,
* so I just copied the code from libavcodec / adpcm . c
*
* However , ms imaadpcm uses a block_align of 2048 ,
* lavc defaults to 1024
*/
if ( lavc_param_atag = = 0x11 ) {
int blkalign = 2048 ;
int framesize = ( blkalign - 4 * lavc_actx - > channels ) * 8 / ( 4 * lavc_actx - > channels ) + 1 ;
lavc_actx - > bit_rate = lavc_actx - > sample_rate * 8 * blkalign / framesize ;
}
if ( avcodec_open ( lavc_actx , lavc_acodec ) < 0 )
{
mp_msg ( MSGT_MENCODER , MSGL_FATAL , " Couldn't open codec %s, br=%d \n " , lavc_param_acodec , lavc_param_abitrate ) ;
exit ( 1 ) ;
}
if ( lavc_param_atag = = 0x11 ) {
lavc_actx - > block_align = 2048 ;
lavc_actx - > frame_size = ( lavc_actx - > block_align - 4 * lavc_actx - > channels ) * 8 / ( 4 * lavc_actx - > channels ) + 1 ;
}
lavc_abuf = malloc ( lavc_actx - > frame_size * 2 * lavc_actx - > channels ) ;
if ( lavc_abuf = = NULL )
{
fprintf ( stderr , " Couldn't allocate %d bytes \n " , lavc_actx - > frame_size * 2 * lavc_actx - > channels ) ;
exit ( 1 ) ;
}
2004-02-18 13:33:16 +00:00
mux_a - > wf = malloc ( sizeof ( WAVEFORMATEX ) + lavc_actx - > extradata_size + 256 ) ;
2003-11-03 16:35:40 +00:00
mux_a - > wf - > wFormatTag = lavc_param_atag ;
mux_a - > wf - > nChannels = lavc_actx - > channels ;
mux_a - > wf - > nSamplesPerSec = lavc_actx - > sample_rate ;
mux_a - > wf - > nAvgBytesPerSec = ( lavc_actx - > bit_rate / 8 ) ;
mux_a - > h . dwRate = mux_a - > wf - > nAvgBytesPerSec ;
if ( lavc_actx - > block_align ) {
mux_a - > h . dwSampleSize = mux_a - > h . dwScale = lavc_actx - > block_align ;
} else {
mux_a - > h . dwScale = ( mux_a - > wf - > nAvgBytesPerSec * lavc_actx - > frame_size ) / mux_a - > wf - > nSamplesPerSec ; /* for cbr */
if ( ( mux_a - > wf - > nAvgBytesPerSec *
lavc_actx - > frame_size ) % mux_a - > wf - > nSamplesPerSec ) {
mux_a - > h . dwScale = lavc_actx - > frame_size ;
mux_a - > h . dwRate = lavc_actx - > sample_rate ;
mux_a - > h . dwSampleSize = 0 ; // Blocksize not constant
} else {
mux_a - > h . dwSampleSize = mux_a - > h . dwScale ;
}
}
mux_a - > wf - > nBlockAlign = mux_a - > h . dwScale ;
mux_a - > h . dwSuggestedBufferSize = audio_preload * mux_a - > wf - > nAvgBytesPerSec ;
mux_a - > h . dwSuggestedBufferSize - = mux_a - > h . dwSuggestedBufferSize % mux_a - > wf - > nBlockAlign ;
switch ( lavc_param_atag ) {
case 0x11 : /* imaadpcm */
mux_a - > wf - > wBitsPerSample = 4 ;
mux_a - > wf - > cbSize = 2 ;
2004-04-07 12:46:14 +00:00
( ( uint16_t * ) mux_a - > wf ) [ sizeof ( WAVEFORMATEX ) ] =
( ( lavc_actx - > block_align - 4 * lavc_actx - > channels ) / ( 4 * lavc_actx - > channels ) ) * 8 + 1 ;
2003-11-03 16:35:40 +00:00
break ;
case 0x55 : /* mp3 */
mux_a - > wf - > cbSize = 12 ;
mux_a - > wf - > wBitsPerSample = 0 ; /* does not apply */
( ( MPEGLAYER3WAVEFORMAT * ) ( mux_a - > wf ) ) - > wID = 1 ;
( ( MPEGLAYER3WAVEFORMAT * ) ( mux_a - > wf ) ) - > fdwFlags = 2 ;
( ( MPEGLAYER3WAVEFORMAT * ) ( mux_a - > wf ) ) - > nBlockSize = mux_a - > wf - > nBlockAlign ;
( ( MPEGLAYER3WAVEFORMAT * ) ( mux_a - > wf ) ) - > nFramesPerBlock = 1 ;
( ( MPEGLAYER3WAVEFORMAT * ) ( mux_a - > wf ) ) - > nCodecDelay = 0 ;
break ;
default :
mux_a - > wf - > wBitsPerSample = 0 ; /* Unknown */
2004-02-18 13:33:16 +00:00
if ( lavc_actx - > extradata & & ( lavc_actx - > extradata_size > 0 ) )
{
memcpy ( mux_a - > wf + sizeof ( WAVEFORMATEX ) , lavc_actx - > extradata ,
lavc_actx - > extradata_size ) ;
mux_a - > wf - > cbSize = lavc_actx - > extradata_size ;
}
else
mux_a - > wf - > cbSize = 0 ;
2003-11-03 16:35:40 +00:00
break ;
}
2004-02-18 13:33:16 +00:00
// Fix allocation
mux_a - > wf = realloc ( mux_a - > wf , sizeof ( WAVEFORMATEX ) + mux_a - > wf - > cbSize ) ;
2003-11-03 16:35:40 +00:00
// setup filter:
if ( ! init_audio_filters (
sh_audio ,
sh_audio - > samplerate , sh_audio - > channels ,
sh_audio - > sample_format , sh_audio - > samplesize ,
mux_a - > wf - > nSamplesPerSec , mux_a - > wf - > nChannels ,
AFMT_S16_NE , 2 ,
mux_a - > h . dwSuggestedBufferSize ,
mux_a - > h . dwSuggestedBufferSize * 2 ) ) {
mp_msg ( MSGT_CPLAYER , MSGL_ERR , " Couldn't find matching filter / ao format! \n " ) ;
exit ( 1 ) ;
}
mp_msg ( MSGT_MENCODER , MSGL_V , " FRAME_SIZE: %d, BUFFER_SIZE: %d, TAG: 0x%x \n " , lavc_actx - > frame_size , lavc_actx - > frame_size * 2 * lavc_actx - > channels , mux_a - > wf - > wFormatTag ) ;
break ;
# endif
2001-10-30 23:17:35 +00:00
}
2002-06-23 17:34:29 +00:00
if ( verbose > 1 ) print_wave_header ( mux_a - > wf ) ;
2002-08-01 08:39:33 +00:00
if ( audio_delay ! = 0.0 ) {
mux_a - > h . dwStart = audio_delay * mux_a - > h . dwRate / mux_a - > h . dwScale ;
printf ( " Setting AUDIO DELAY to %5.3f \n " , mux_a - > h . dwStart * mux_a - > h . dwScale / ( float ) mux_a - > h . dwRate ) ;
}
} // if(sh_audio)
2002-08-07 18:24:25 +00:00
printf ( MSGTR_WritingAVIHeader ) ;
2003-10-22 17:04:39 +00:00
if ( muxer - > cont_write_header ) muxer_write_header ( muxer ) ;
2001-10-29 01:11:18 +00:00
2002-04-11 02:52:03 +00:00
decoded_frameno = 0 ;
2001-10-29 01:11:18 +00:00
2001-10-31 22:59:56 +00:00
if ( sh_audio )
2001-10-31 00:25:28 +00:00
switch ( mux_a - > codec ) {
2001-12-06 22:27:09 +00:00
# ifdef HAVE_MP3LAME
2001-10-31 00:25:28 +00:00
case ACODEC_VBRMP3 :
lame = lame_init ( ) ;
2001-10-31 16:08:01 +00:00
lame_set_bWriteVbrTag ( lame , 0 ) ;
2002-10-05 22:55:45 +00:00
lame_set_in_samplerate ( lame , mux_a - > wf - > nSamplesPerSec ) ;
//lame_set_in_samplerate(lame,sh_audio->samplerate); // if resampling done by lame
2001-10-31 00:25:28 +00:00
lame_set_num_channels ( lame , mux_a - > wf - > nChannels ) ;
2001-11-02 20:05:36 +00:00
lame_set_out_samplerate ( lame , mux_a - > wf - > nSamplesPerSec ) ;
2002-05-01 14:42:42 +00:00
lame_set_quality ( lame , lame_param_algqual ) ; // 0 = best q
2004-05-19 04:33:00 +00:00
if ( lame_param_free_format ) lame_set_free_format ( lame , 1 ) ;
2001-11-02 03:22:33 +00:00
if ( lame_param_vbr ) { // VBR:
lame_set_VBR ( lame , lame_param_vbr ) ; // vbr mode
2004-04-02 03:44:30 +00:00
lame_set_VBR_q ( lame , lame_param_quality ) ; // 0 = best vbr q 5=~128k
2001-11-02 03:22:33 +00:00
if ( lame_param_br > 0 ) lame_set_VBR_mean_bitrate_kbps ( lame , lame_param_br ) ;
2004-05-19 04:33:00 +00:00
if ( lame_param_br_min > 0 ) lame_set_VBR_min_bitrate_kbps ( lame , lame_param_br_min ) ;
if ( lame_param_br_max > 0 ) lame_set_VBR_max_bitrate_kbps ( lame , lame_param_br_max ) ;
2001-11-02 03:22:33 +00:00
} else { // CBR:
if ( lame_param_br > 0 ) lame_set_brate ( lame , lame_param_br ) ;
}
if ( lame_param_mode > = 0 ) lame_set_mode ( lame , lame_param_mode ) ; // j-st
if ( lame_param_ratio > 0 ) lame_set_compression_ratio ( lame , lame_param_ratio ) ;
2002-04-26 20:19:31 +00:00
if ( lame_param_scale > 0 ) {
printf ( " Setting audio input gain to %f \n " , lame_param_scale ) ;
lame_set_scale ( lame , lame_param_scale ) ;
}
2004-01-23 01:13:00 +00:00
if ( lame_param_lowpassfreq > = - 1 ) lame_set_lowpassfreq ( lame , lame_param_lowpassfreq ) ;
if ( lame_param_highpassfreq > = - 1 ) lame_set_highpassfreq ( lame , lame_param_highpassfreq ) ;
2002-12-21 22:16:49 +00:00
# if HAVE_MP3LAME >= 392
if ( lame_param_preset ! = NULL ) {
printf ( " \n preset=%s \n \n " , lame_param_preset ) ;
lame_presets_set ( lame , lame_param_fast , ( lame_param_vbr = = 0 ) , lame_param_preset ) ;
}
# endif
2001-10-31 00:25:28 +00:00
lame_init_params ( lame ) ;
2002-11-01 17:46:45 +00:00
if ( verbose > 0 ) {
2001-11-02 03:22:33 +00:00
lame_print_config ( lame ) ;
lame_print_internals ( lame ) ;
2001-11-02 02:08:00 +00:00
}
2001-12-06 22:27:09 +00:00
break ;
# endif
2001-10-31 00:25:28 +00:00
}
2001-10-29 01:11:18 +00:00
signal ( SIGINT , exit_sighandler ) ; // Interrupt from keyboard
signal ( SIGQUIT , exit_sighandler ) ; // Quit from keyboard
signal ( SIGTERM , exit_sighandler ) ; // kill
2002-01-27 18:29:33 +00:00
timer_start = GetTimerMS ( ) ;
2002-02-10 00:07:34 +00:00
if ( seek_to_sec ) {
int a , b ; float d ;
if ( sscanf ( seek_to_sec , " %d:%d:%f " , & a , & b , & d ) = = 3 )
d + = 3600 * a + 60 * b ;
else if ( sscanf ( seek_to_sec , " %d:%f " , & a , & d ) = = 2 )
d + = 60 * a ;
else
sscanf ( seek_to_sec , " %f " , & d ) ;
demux_seek ( demuxer , d , 1 ) ;
2002-09-14 10:47:34 +00:00
// there is 2 way to handle the -ss option in 3-pass mode:
// > 1. do the first pass for the whole file, and use -ss for 2nd/3rd pases only
// > 2. do all the 3 passes with the same -ss value
// this line enables behaviour 1. (and kills 2. at the same time):
// if(demuxer2) demux_seek(demuxer2, d, 1);
2002-02-10 00:07:34 +00:00
}
2002-12-27 22:43:20 +00:00
if ( out_file_format = = MUXER_TYPE_MPEG )
{
if ( audio_preload > 0.4 ) {
fprintf ( stderr , " Limiting audio preload to 0.4s \n " ) ;
audio_preload = 0.4 ;
}
if ( audio_density < 4 ) {
fprintf ( stderr , " Increasing audio density to 4 \n " ) ;
2003-01-03 11:51:39 +00:00
audio_density = 4 ;
2002-12-27 22:43:20 +00:00
}
}
2003-03-30 17:07:31 +00:00
if ( file_format = = DEMUXER_TYPE_TV )
2002-04-12 10:40:38 +00:00
{
fprintf ( stderr , " Forcing audio preload to 0, max pts correction to 0 \n " ) ;
audio_preload = 0.0 ;
default_max_pts_correction = 0 ;
}
2002-06-28 17:13:18 +00:00
play_n_frames = play_n_frames_mf ;
2002-06-13 21:35:10 +00:00
while ( ! at_eof ) {
2001-10-29 01:11:18 +00:00
2001-10-30 21:22:28 +00:00
float frame_time = 0 ;
2001-10-29 01:11:18 +00:00
int blit_frame = 0 ;
float a_pts = 0 ;
float v_pts = 0 ;
2001-10-30 21:55:28 +00:00
unsigned char * start = NULL ;
int in_size ;
2001-11-01 21:47:28 +00:00
int skip_flag = 0 ; // 1=skip -1=duplicate
2001-10-29 01:11:18 +00:00
2002-04-12 10:40:38 +00:00
if ( ( end_at_type = = END_AT_SIZE & & end_at < = ftello ( muxer_f ) ) | |
2002-01-15 00:20:50 +00:00
( end_at_type = = END_AT_TIME & & end_at < sh_video - > timer ) )
break ;
2001-11-03 00:44:02 +00:00
if ( play_n_frames > = 0 ) {
- - play_n_frames ;
if ( play_n_frames < 0 ) break ;
}
2001-10-30 23:17:35 +00:00
if ( sh_audio ) {
// get audio:
2001-10-31 00:25:28 +00:00
while ( mux_a - > timer - audio_preload < mux_v - > timer ) {
2001-11-03 21:00:04 +00:00
int len = 0 ;
2002-04-12 10:40:38 +00:00
ptimer_start = GetTimerMS ( ) ;
2003-11-03 16:35:40 +00:00
# ifdef USE_LIBAVCODEC
if ( mux_a - > codec = = ACODEC_LAVC ) {
int size , rd_len ;
size = lavc_actx - > frame_size * 2 * mux_a - > wf - > nChannels ;
rd_len = dec_audio ( sh_audio , lavc_abuf , size ) ;
if ( rd_len ! = size )
break ;
// Encode one frame
mux_a - > buffer_len + = avcodec_encode_audio ( lavc_actx , mux_a - > buffer + mux_a - > buffer_len , size , lavc_abuf ) ;
if ( mux_a - > h . dwSampleSize ) { /* CBR */
/*
* work around peculiar lame behaviour
*/
if ( mux_a - > buffer_len < mux_a - > wf - > nBlockAlign ) {
len = 0 ;
} else {
len = mux_a - > wf - > nBlockAlign * ( mux_a - > buffer_len / mux_a - > wf - > nBlockAlign ) ;
}
} else { /* VBR */
len = mux_a - > buffer_len ;
}
if ( mux_v - > timer = = 0 ) mux_a - > h . dwInitialFrames + + ;
}
# endif
2001-10-30 23:17:35 +00:00
if ( mux_a - > h . dwSampleSize ) {
2001-11-01 02:31:23 +00:00
// CBR - copy 0.5 sec of audio
2001-10-31 00:25:28 +00:00
switch ( mux_a - > codec ) {
2001-12-08 13:30:06 +00:00
case ACODEC_COPY : // copy
2002-08-01 08:39:33 +00:00
len = mux_a - > wf - > nAvgBytesPerSec / audio_density ;
2001-10-31 00:25:28 +00:00
len / = mux_a - > h . dwSampleSize ; if ( len < 1 ) len = 1 ;
len * = mux_a - > h . dwSampleSize ;
len = demux_read_data ( sh_audio - > ds , mux_a - > buffer , len ) ;
break ;
case ACODEC_PCM :
2002-08-01 08:39:33 +00:00
len = mux_a - > h . dwSampleSize * ( mux_a - > h . dwRate / audio_density ) ;
2001-10-31 16:08:01 +00:00
len = dec_audio ( sh_audio , mux_a - > buffer , len ) ;
2001-10-31 00:25:28 +00:00
break ;
}
2001-10-30 23:17:35 +00:00
} else {
2001-11-01 02:31:23 +00:00
// VBR - encode/copy an audio frame
switch ( mux_a - > codec ) {
2001-12-08 13:30:06 +00:00
case ACODEC_COPY : // copy
2002-01-26 22:30:02 +00:00
len = ds_get_packet ( sh_audio - > ds , ( unsigned char * * ) & mux_a - > buffer ) ;
// printf("VBR audio framecopy not yet implemented!\n");
2001-11-01 02:31:23 +00:00
break ;
2001-12-06 22:27:09 +00:00
# ifdef HAVE_MP3LAME
2001-11-01 02:31:23 +00:00
case ACODEC_VBRMP3 :
2001-10-31 16:08:01 +00:00
while ( mux_a - > buffer_len < 4 ) {
unsigned char tmp [ 2304 ] ;
int len = dec_audio ( sh_audio , tmp , 2304 ) ;
if ( len < = 0 ) break ; // eof
2002-06-23 17:34:29 +00:00
/* mono encoding, a bit tricky */
if ( mux_a - > wf - > nChannels = = 1 )
{
2002-06-27 19:33:28 +00:00
len = lame_encode_buffer ( lame , ( short * ) tmp , ( short * ) tmp , len / 2 ,
2002-06-23 17:34:29 +00:00
mux_a - > buffer + mux_a - > buffer_len , mux_a - > buffer_size - mux_a - > buffer_len ) ;
}
else
{
len = lame_encode_buffer_interleaved ( lame ,
2002-06-27 19:33:28 +00:00
( short * ) tmp , len / 4 ,
2001-10-31 16:08:01 +00:00
mux_a - > buffer + mux_a - > buffer_len , mux_a - > buffer_size - mux_a - > buffer_len ) ;
2002-06-23 17:34:29 +00:00
}
2001-10-31 16:08:01 +00:00
if ( len < 0 ) break ; // error
mux_a - > buffer_len + = len ;
}
if ( mux_a - > buffer_len < 4 ) break ;
len = mp_decode_mp3_header ( mux_a - > buffer ) ;
2001-11-02 20:05:36 +00:00
//printf("%d\n",len);
2001-10-31 16:08:01 +00:00
if ( len < = 0 ) break ; // bad frame!
2002-04-18 17:28:48 +00:00
// printf("[%d]\n",mp_mp3_get_lsf(mux_a->buffer));
2001-10-31 16:08:01 +00:00
while ( mux_a - > buffer_len < len ) {
unsigned char tmp [ 2304 ] ;
int len = dec_audio ( sh_audio , tmp , 2304 ) ;
if ( len < = 0 ) break ; // eof
2002-06-23 19:09:25 +00:00
/* mono encoding, a bit tricky */
if ( mux_a - > wf - > nChannels = = 1 )
{
2002-06-27 19:33:28 +00:00
len = lame_encode_buffer ( lame , ( short * ) tmp , ( short * ) tmp , len / 2 ,
2002-06-23 19:09:25 +00:00
mux_a - > buffer + mux_a - > buffer_len , mux_a - > buffer_size - mux_a - > buffer_len ) ;
}
else
{
len = lame_encode_buffer_interleaved ( lame ,
2002-06-27 19:33:28 +00:00
( short * ) tmp , len / 4 ,
2001-10-31 16:08:01 +00:00
mux_a - > buffer + mux_a - > buffer_len , mux_a - > buffer_size - mux_a - > buffer_len ) ;
2002-06-23 19:09:25 +00:00
}
2001-10-31 16:08:01 +00:00
if ( len < 0 ) break ; // error
mux_a - > buffer_len + = len ;
}
2001-11-01 02:31:23 +00:00
break ;
2001-12-06 22:27:09 +00:00
# endif
2001-11-01 02:31:23 +00:00
}
2001-10-30 23:17:35 +00:00
}
2001-10-31 00:25:28 +00:00
if ( len < = 0 ) break ; // EOF?
2003-01-19 01:48:52 +00:00
muxer_write_chunk ( mux_a , len , 0x10 ) ;
2001-11-03 21:09:21 +00:00
if ( ! mux_a - > h . dwSampleSize & & mux_a - > timer > 0 )
2001-12-06 21:50:35 +00:00
mux_a - > wf - > nAvgBytesPerSec = 0.5f + ( double ) mux_a - > size / mux_a - > timer ; // avg bps (VBR)
2001-10-31 16:08:01 +00:00
if ( mux_a - > buffer_len > = len ) {
mux_a - > buffer_len - = len ;
memcpy ( mux_a - > buffer , mux_a - > buffer + len , mux_a - > buffer_len ) ;
}
2002-04-12 10:40:38 +00:00
audiosamples + + ;
audiorate + = ( GetTimerMS ( ) - ptimer_start ) ;
2001-10-30 23:17:35 +00:00
}
}
// get video frame!
2002-04-12 10:40:38 +00:00
2001-10-30 23:17:35 +00:00
in_size = video_read_frame ( sh_video , & frame_time , & start , force_fps ) ;
2002-06-13 21:35:10 +00:00
if ( in_size < 0 ) { at_eof = 1 ; break ; }
2001-12-06 23:59:46 +00:00
sh_video - > timer + = frame_time ; + + decoded_frameno ;
2002-04-12 10:40:38 +00:00
2002-12-28 12:51:05 +00:00
v_timer_corr - = frame_time - ( float ) mux_v - > h . dwScale / mux_v - > h . dwRate ;
2002-04-11 02:52:03 +00:00
if ( demuxer2 ) { // 3-pass encoding, read control file (frameno.avi)
2002-01-26 22:30:02 +00:00
// find our frame:
while ( next_frameno < decoded_frameno ) {
int * start ;
int len = ds_get_packet ( demuxer2 - > video , ( unsigned char * * ) & start ) ;
2002-06-13 21:35:10 +00:00
if ( len < 0 ) { at_eof = 1 ; break ; }
2002-01-26 22:30:02 +00:00
if ( len = = 0 ) - - skip_flag ; else // duplicate
if ( len = = 4 ) next_frameno = start [ 0 ] ;
}
2002-06-13 21:35:10 +00:00
if ( at_eof ) break ;
2002-04-12 10:40:38 +00:00
// if(skip_flag) printf("!!!!!!!!!!!!\n");
2002-01-26 22:30:02 +00:00
skip_flag = next_frameno - decoded_frameno ;
// find next frame:
while ( next_frameno < = decoded_frameno ) {
int * start ;
int len = ds_get_packet ( demuxer2 - > video , ( unsigned char * * ) & start ) ;
2002-06-13 21:35:10 +00:00
if ( len < 0 ) { at_eof = 1 ; break ; }
2002-01-26 22:30:02 +00:00
if ( len = = 0 ) - - skip_flag ; else // duplicate
if ( len = = 4 ) next_frameno = start [ 0 ] ;
}
2002-06-13 21:35:10 +00:00
// if(at_eof) break;
2002-01-26 22:30:02 +00:00
// printf("Current fno=%d requested=%d skip=%d \n",decoded_frameno,fno,skip_flag);
} else {
2001-11-01 21:47:28 +00:00
// check frame duplicate/drop:
2002-07-12 18:03:16 +00:00
//printf("\r### %5.3f ###\n",v_timer_corr);
2002-04-15 02:33:05 +00:00
if ( v_timer_corr > = ( float ) mux_v - > h . dwScale / mux_v - > h . dwRate & &
( skip_limit < 0 | | skip_flag < skip_limit ) ) {
2001-11-01 21:47:28 +00:00
v_timer_corr - = ( float ) mux_v - > h . dwScale / mux_v - > h . dwRate ;
+ + skip_flag ; // skip
} else
2002-04-15 02:33:05 +00:00
while ( v_timer_corr < = - ( float ) mux_v - > h . dwScale / mux_v - > h . dwRate & &
( skip_limit < 0 | | ( - skip_flag ) < skip_limit ) ) {
2001-11-01 21:47:28 +00:00
v_timer_corr + = ( float ) mux_v - > h . dwScale / mux_v - > h . dwRate ;
- - skip_flag ; // dup
}
while ( ( v_pts_corr < = - ( float ) mux_v - > h . dwScale / mux_v - > h . dwRate & & skip_flag > 0 )
| | ( v_pts_corr < = - 2 * ( float ) mux_v - > h . dwScale / mux_v - > h . dwRate ) ) {
v_pts_corr + = ( float ) mux_v - > h . dwScale / mux_v - > h . dwRate ;
- - skip_flag ; // dup
}
if ( ( v_pts_corr > = ( float ) mux_v - > h . dwScale / mux_v - > h . dwRate & & skip_flag < 0 )
| | ( v_pts_corr > = 2 * ( float ) mux_v - > h . dwScale / mux_v - > h . dwRate ) )
if ( skip_flag < = 0 ) { // we can't skip more than 1 frame now
v_pts_corr - = ( float ) mux_v - > h . dwScale / mux_v - > h . dwRate ;
+ + skip_flag ; // skip
}
2001-10-29 01:11:18 +00:00
2002-01-26 22:30:02 +00:00
} // demuxer2
2002-04-12 10:40:38 +00:00
ptimer_start = GetTimerMS ( ) ;
2001-10-29 01:11:18 +00:00
switch ( mux_v - > codec ) {
2001-12-08 12:21:23 +00:00
case VCODEC_COPY :
2001-10-30 21:55:28 +00:00
mux_v - > buffer = start ;
2003-01-19 01:48:52 +00:00
if ( skip_flag < = 0 ) muxer_write_chunk ( mux_v , in_size , ( sh_video - > ds - > flags & 1 ) ? 0x10 : 0 ) ;
2001-10-30 21:55:28 +00:00
break ;
2002-04-11 02:52:03 +00:00
case VCODEC_FRAMENO :
2002-06-27 19:33:28 +00:00
mux_v - > buffer = ( unsigned char * ) & decoded_frameno ; // tricky
2003-01-19 01:48:52 +00:00
if ( skip_flag < = 0 ) muxer_write_chunk ( mux_v , sizeof ( int ) , 0x10 ) ;
2002-02-07 20:22:03 +00:00
break ;
2002-04-11 02:52:03 +00:00
default :
// decode_video will callback down to ve_*.c encoders, through the video filters
2004-04-28 04:29:17 +00:00
blit_frame = decode_video ( sh_video , start , in_size ,
2004-05-19 04:38:05 +00:00
skip_flag > 0 & & ( ! sh_video - > vfilter | | ( ( vf_instance_t * ) sh_video - > vfilter ) - > control ( sh_video - > vfilter , VFCTRL_SKIP_NEXT_FRAME , 0 ) ! = CONTROL_TRUE ) ) ;
2002-09-10 23:19:20 +00:00
if ( ! blit_frame ) {
badframes + + ;
if ( skip_flag < = 0 ) {
2002-07-12 18:03:16 +00:00
// unwanted skipping of a frame, what to do?
if ( skip_limit = = 0 ) {
// skipping not allowed -> write empty frame:
2004-05-19 04:38:05 +00:00
if ( ! encode_duplicates | | ! sh_video - > vfilter | | ( ( vf_instance_t * ) sh_video - > vfilter ) - > control ( sh_video - > vfilter , VFCTRL_DUPLICATE_FRAME , 0 ) ! = CONTROL_TRUE )
2004-04-28 04:29:17 +00:00
muxer_write_chunk ( mux_v , 0 , 0 ) ;
2002-07-12 18:03:16 +00:00
} else {
// skipping allowed -> skip it and distriubute timer error:
v_timer_corr - = ( float ) mux_v - > h . dwScale / mux_v - > h . dwRate ;
}
2002-09-10 23:19:20 +00:00
}
2002-07-12 18:03:16 +00:00
}
2001-10-29 01:11:18 +00:00
}
2001-11-01 21:47:28 +00:00
2002-04-12 10:40:38 +00:00
videosamples + + ;
videorate + = ( GetTimerMS ( ) - ptimer_start ) ;
2001-11-01 21:47:28 +00:00
if ( skip_flag < 0 ) {
2001-11-01 02:31:23 +00:00
// duplicate frame
2003-03-30 17:07:31 +00:00
if ( file_format ! = DEMUXER_TYPE_TV & & ! verbose ) printf ( MSGTR_DuplicateFrames , - skip_flag ) ;
2001-11-01 21:47:28 +00:00
while ( skip_flag < 0 ) {
2002-04-12 10:40:38 +00:00
duplicatedframes + + ;
2004-05-19 04:38:05 +00:00
if ( ! encode_duplicates | | ! sh_video - > vfilter | | ( ( vf_instance_t * ) sh_video - > vfilter ) - > control ( sh_video - > vfilter , VFCTRL_DUPLICATE_FRAME , 0 ) ! = CONTROL_TRUE )
2004-04-28 04:02:46 +00:00
muxer_write_chunk ( mux_v , 0 , 0 ) ;
2001-11-01 21:47:28 +00:00
+ + skip_flag ;
}
2001-11-02 20:05:36 +00:00
} else
if ( skip_flag > 0 ) {
2001-11-01 02:31:23 +00:00
// skip frame
2003-03-30 17:07:31 +00:00
if ( file_format ! = DEMUXER_TYPE_TV & & ! verbose ) printf ( MSGTR_SkipFrame ) ;
2002-04-12 10:40:38 +00:00
skippedframes + + ;
2001-11-01 21:47:28 +00:00
- - skip_flag ;
2001-11-01 02:31:23 +00:00
}
2002-01-26 22:30:02 +00:00
if ( sh_audio & & ! demuxer2 ) {
2001-11-01 02:31:23 +00:00
float AV_delay , x ;
// A-V sync!
2002-11-02 00:45:12 +00:00
#if 0
2001-11-01 02:31:23 +00:00
if ( pts_from_bps ) {
unsigned int samples = ( sh_audio - > audio . dwSampleSize ) ?
( ( ds_tell ( d_audio ) - sh_audio - > a_in_buffer_len ) / sh_audio - > audio . dwSampleSize ) :
2002-08-02 17:44:16 +00:00
( d_audio - > block_no ) ; // <- used for VBR audio
2002-01-27 14:35:48 +00:00
// printf("samples=%d \n",samples);
2001-11-01 02:31:23 +00:00
a_pts = samples * ( float ) sh_audio - > audio . dwScale / ( float ) sh_audio - > audio . dwRate ;
delay_corrected = 1 ;
2002-11-02 00:45:12 +00:00
} else
# endif
{
2001-11-01 02:31:23 +00:00
// PTS = (last timestamp) + (bytes after last timestamp)/(bytes per sec)
a_pts = d_audio - > pts ;
if ( ! delay_corrected ) if ( a_pts ) delay_corrected = 1 ;
//printf("*** %5.3f ***\n",a_pts);
a_pts + = ( ds_tell_pts ( d_audio ) - sh_audio - > a_in_buffer_len ) / ( float ) sh_audio - > i_bps ;
}
2003-01-16 23:03:06 +00:00
v_pts = sh_video ? sh_video - > pts : d_video - > pts ;
2001-11-01 02:31:23 +00:00
// av = compensated (with out buffering delay) A-V diff
2001-11-01 21:47:28 +00:00
AV_delay = ( a_pts - v_pts ) ; AV_delay - = mux_a - > timer - ( mux_v - > timer - ( v_timer_corr + v_pts_corr ) ) ;
2001-11-01 02:31:23 +00:00
// compensate input video timer by av:
x = AV_delay * 0.1f ;
if ( x < - max_pts_correction ) x = - max_pts_correction ; else
if ( x > max_pts_correction ) x = max_pts_correction ;
if ( default_max_pts_correction > = 0 )
max_pts_correction = default_max_pts_correction ;
else
max_pts_correction = sh_video - > frametime * 0.10 ; // +-10% of time
// sh_video->timer-=x;
c_total + = x ;
2001-11-01 21:47:28 +00:00
v_pts_corr + = x ;
2001-11-01 02:31:23 +00:00
}
2002-01-27 18:29:33 +00:00
// printf("A:%6.1f V:%6.1f A-V:%7.3f oAV:%7.3f diff:%7.3f ct:%7.3f vpc:%7.3f \r",
// a_pts,v_pts,a_pts-v_pts,
// (float)(mux_a->timer-mux_v->timer),
// AV_delay, c_total, v_pts_corr );
// printf("V:%6.1f \r", d_video->pts );
2001-11-01 02:31:23 +00:00
#if 0
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 " ,
a_pts , v_pts , a_pts - v_pts , c_total ,
( int ) sh_video - > num_frames , ( int ) sh_video - > num_frames_decoded ,
( sh_video - > timer > 0.5 ) ? ( int ) ( 100.0 * video_time_usage / ( double ) sh_video - > timer ) : 0 ,
( sh_video - > timer > 0.5 ) ? ( int ) ( 100.0 * vout_time_usage / ( double ) sh_video - > timer ) : 0 ,
( sh_video - > timer > 0.5 ) ? ( 100.0 * audio_time_usage / ( double ) sh_video - > timer ) : 0
, cache_fill_status
) ;
# endif
2002-01-27 18:29:33 +00:00
{ float t = ( GetTimerMS ( ) - timer_start ) * 0.001f ;
float len = ( demuxer - > movi_end - demuxer - > movi_start ) ;
float p = len > 1000 ? ( float ) ( demuxer - > filepos - demuxer - > movi_start ) / len : 0 ;
2002-11-02 00:45:12 +00:00
#if 0
2002-01-27 21:37:46 +00:00
if ( ! len & & sh_audio & & sh_audio - > audio . dwLength > 100 ) {
2002-08-02 17:44:16 +00:00
p = ( sh_audio - > audio . dwSampleSize ? ds_tell ( sh_audio - > ds ) / sh_audio - > audio . dwSampleSize : sh_audio - > ds - > block_no )
2002-01-27 21:37:46 +00:00
/ ( float ) ( sh_audio - > audio . dwLength ) ;
}
2002-11-02 00:45:12 +00:00
# endif
2002-01-27 20:34:31 +00:00
#if 0
mp_msg ( MSGT_AVSYNC , MSGL_STATUS , " %d < %d < %d \r " ,
( int ) demuxer - > movi_start ,
( int ) demuxer - > filepos ,
( int ) demuxer - > movi_end ) ;
# else
2004-01-29 12:01:26 +00:00
if ( ! quiet ) {
2002-11-01 17:46:45 +00:00
if ( verbose > 0 ) {
2002-09-10 23:19:20 +00:00
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/B/S %d/%d/%d \r " ,
2002-04-12 10:40:38 +00:00
mux_v - > timer , decoded_frameno , ( int ) ( p * 100 ) ,
2002-08-21 21:31:20 +00:00
( t > 1 ) ? ( int ) ( decoded_frameno / t + 0.5 ) : 0 ,
2002-04-12 10:40:38 +00:00
( p > 0.001 ) ? ( int ) ( ( t / p - t ) / 60 ) : 0 ,
( p > 0.001 ) ? ( int ) ( ftello ( muxer_f ) / p / 1024 / 1024 ) : 0 ,
v_pts_corr ,
( mux_v - > timer > 1 ) ? ( int ) ( mux_v - > size / mux_v - > timer / 125 ) : 0 ,
( mux_a & & mux_a - > timer > 1 ) ? ( int ) ( mux_a - > size / mux_a - > timer / 125 ) : 0 ,
audiorate / audiosamples , videorate / videosamples ,
2002-09-10 23:19:20 +00:00
duplicatedframes , badframes , skippedframes
2002-04-12 10:40:38 +00:00
) ;
} else
2002-01-27 21:46:06 +00:00
mp_msg ( MSGT_AVSYNC , MSGL_STATUS , " Pos:%6.1fs %6df (%2d%%) %3dfps Trem:%4dmin %3dmb A-V:%5.3f [%d:%d] \r " ,
2002-01-27 18:29:33 +00:00
mux_v - > timer , decoded_frameno , ( int ) ( p * 100 ) ,
2002-08-21 21:31:20 +00:00
( t > 1 ) ? ( int ) ( decoded_frameno / t + 0.5 ) : 0 ,
2002-01-27 20:34:31 +00:00
( p > 0.001 ) ? ( int ) ( ( t / p - t ) / 60 ) : 0 ,
2002-12-15 19:08:11 +00:00
( p > 0.001 ) ? ( int ) ( ftello ( muxer_f ) / p / 1024 / 1024 ) : 0 ,
2002-01-27 21:46:06 +00:00
v_pts_corr ,
( mux_v - > timer > 1 ) ? ( int ) ( mux_v - > size / mux_v - > timer / 125 ) : 0 ,
2002-01-31 00:38:53 +00:00
( mux_a & & mux_a - > timer > 1 ) ? ( int ) ( mux_a - > size / mux_a - > timer / 125 ) : 0
2002-01-27 18:29:33 +00:00
) ;
2004-01-29 12:01:26 +00:00
}
2002-01-27 20:34:31 +00:00
# endif
2002-01-27 18:29:33 +00:00
}
2001-11-01 02:31:23 +00:00
fflush ( stdout ) ;
2002-04-17 21:51:18 +00:00
# ifdef USE_SUB
// find sub
2003-04-07 16:04:02 +00:00
if ( subdata & & sh_video - > pts > 0 ) {
2003-01-16 23:03:06 +00:00
float pts = sh_video - > pts ;
2002-04-17 21:51:18 +00:00
if ( sub_fps = = 0 ) sub_fps = sh_video - > fps ;
if ( pts > sub_last_pts | | pts < sub_last_pts - 1.0 ) {
2003-04-07 16:04:02 +00:00
find_sub ( subdata , ( pts + sub_delay ) *
( subdata - > sub_uses_time ? 100. : sub_fps ) ) ;
// FIXME! frame counter...
2002-04-17 21:51:18 +00:00
sub_last_pts = pts ;
}
}
# endif
# ifdef USE_DVDREAD
// DVD sub:
2002-07-08 21:44:51 +00:00
if ( vo_spudec | | vobsub_writer ) {
2002-04-17 21:51:18 +00:00
unsigned char * packet = NULL ;
int len ;
while ( ( len = ds_get_packet_sub ( d_dvdsub , & packet ) ) > 0 ) {
2003-01-16 23:03:06 +00:00
mp_msg ( MSGT_MENCODER , MSGL_V , " \r DVD sub: len=%d v_pts=%5.3f s_pts=%5.3f \n " , len , sh_video - > pts , d_dvdsub - > pts ) ;
2002-07-08 21:44:51 +00:00
if ( vo_spudec )
2002-04-17 21:51:18 +00:00
spudec_assemble ( vo_spudec , packet , len , 90000 * d_dvdsub - > pts ) ;
2002-07-08 21:44:51 +00:00
if ( vobsub_writer )
2003-01-16 23:03:06 +00:00
vobsub_out_output ( vobsub_writer , packet , len , mux_v - > timer + d_dvdsub - > pts - sh_video - > pts ) ;
2002-04-17 21:51:18 +00:00
}
2002-07-08 21:44:51 +00:00
if ( vo_spudec ) {
2003-01-16 23:03:06 +00:00
spudec_heartbeat ( vo_spudec , 90000 * sh_video - > pts ) ;
2002-04-17 22:17:32 +00:00
vo_osd_changed ( OSDTYPE_SPU ) ;
2002-07-08 21:44:51 +00:00
}
2002-04-17 21:51:18 +00:00
}
# endif
2001-10-29 01:11:18 +00:00
2002-06-07 22:40:06 +00:00
if ( ferror ( muxer_f ) ) {
2002-08-07 18:24:25 +00:00
mp_msg ( MSGT_MENCODER , MSGL_FATAL , MSGTR_ErrorWritingFile , out_filename ) ;
2002-06-07 22:40:06 +00:00
mencoder_exit ( 1 , NULL ) ;
}
2001-10-29 01:11:18 +00:00
2002-06-13 21:35:10 +00:00
} // while(!at_eof)
2001-10-29 01:11:18 +00:00
2001-12-06 22:27:09 +00:00
# ifdef HAVE_MP3LAME
// fixup CBR mp3 audio header:
2001-12-06 21:50:35 +00:00
if ( sh_audio & & mux_a - > codec = = ACODEC_VBRMP3 & & ! lame_param_vbr ) {
mux_a - > h . dwSampleSize = 1 ;
2002-04-18 14:23:07 +00:00
( ( MPEGLAYER3WAVEFORMAT * ) ( mux_a - > wf ) ) - > nBlockSize =
( mux_a - > size + ( mux_a - > h . dwLength > > 1 ) ) / mux_a - > h . dwLength ;
mux_a - > h . dwLength = mux_a - > size ;
2001-12-06 21:50:35 +00:00
mux_a - > h . dwRate = mux_a - > wf - > nAvgBytesPerSec ;
mux_a - > h . dwScale = 1 ;
2002-04-18 14:23:07 +00:00
mux_a - > wf - > nBlockAlign = 1 ;
2002-11-06 23:54:29 +00:00
printf ( " \n \n CBR audio: %ld bytes/sec, %d bytes/block \n " ,
2002-04-18 14:23:07 +00:00
mux_a - > h . dwRate , ( ( MPEGLAYER3WAVEFORMAT * ) ( mux_a - > wf ) ) - > nBlockSize ) ;
2001-12-06 21:50:35 +00:00
}
2001-12-06 22:27:09 +00:00
# endif
2001-12-06 21:50:35 +00:00
2002-08-07 18:24:25 +00:00
printf ( MSGTR_WritingAVIIndex ) ;
2003-10-22 17:04:39 +00:00
if ( muxer - > cont_write_index ) muxer_write_index ( muxer ) ;
2002-04-12 10:40:38 +00:00
muxer_f_size = ftello ( muxer_f ) ;
2002-08-07 18:24:25 +00:00
printf ( MSGTR_FixupAVIHeader ) ;
2001-10-29 01:11:18 +00:00
fseek ( muxer_f , 0 , SEEK_SET ) ;
2003-10-22 17:04:39 +00:00
if ( muxer - > cont_write_header ) muxer_write_header ( muxer ) ; // update header
2002-06-07 22:40:06 +00:00
if ( ferror ( muxer_f ) | | fclose ( muxer_f ) ! = 0 ) {
2002-08-07 18:24:25 +00:00
mp_msg ( MSGT_MENCODER , MSGL_FATAL , MSGTR_ErrorWritingFile , out_filename ) ;
2002-06-07 22:40:06 +00:00
mencoder_exit ( 1 , NULL ) ;
}
2002-07-08 21:44:51 +00:00
if ( vobsub_writer )
vobsub_out_close ( vobsub_writer ) ;
2002-01-27 00:43:57 +00:00
if ( out_video_codec = = VCODEC_FRAMENO & & mux_v - > timer > 100 ) {
2002-08-07 18:24:25 +00:00
printf ( MSGTR_RecommendedVideoBitrate , " 650MB " , ( int ) ( ( 650 * 1024 * 1024 - muxer_f_size ) / mux_v - > timer / 125 ) ) ;
printf ( MSGTR_RecommendedVideoBitrate , " 700MB " , ( int ) ( ( 700 * 1024 * 1024 - muxer_f_size ) / mux_v - > timer / 125 ) ) ;
printf ( MSGTR_RecommendedVideoBitrate , " 800MB " , ( int ) ( ( 800 * 1024 * 1024 - muxer_f_size ) / mux_v - > timer / 125 ) ) ;
2002-09-22 13:37:11 +00:00
printf ( MSGTR_RecommendedVideoBitrate , " 2 x 650MB " , ( int ) ( ( 2 * 650 * 1024 * 1024 - muxer_f_size ) / mux_v - > timer / 125 ) ) ;
printf ( MSGTR_RecommendedVideoBitrate , " 2 x 700MB " , ( int ) ( ( 2 * 700 * 1024 * 1024 - muxer_f_size ) / mux_v - > timer / 125 ) ) ;
printf ( MSGTR_RecommendedVideoBitrate , " 2 x 800MB " , ( int ) ( ( 2 * 800 * 1024 * 1024 - muxer_f_size ) / mux_v - > timer / 125 ) ) ;
2002-01-27 00:43:57 +00:00
}
2002-08-07 18:24:25 +00:00
printf ( MSGTR_VideoStreamResult ,
2002-04-12 10:40:38 +00:00
( 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 ) ;
2001-12-06 23:59:46 +00:00
if ( sh_audio )
2002-08-07 18:24:25 +00:00
printf ( MSGTR_AudioStreamResult ,
2002-04-12 10:40:38 +00:00
( 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 ) ;
2001-12-06 23:59:46 +00:00
2002-09-25 20:27:34 +00:00
if ( sh_video ) { uninit_video ( sh_video ) ; sh_video = NULL ; }
if ( demuxer ) free_demuxer ( demuxer ) ;
2001-11-02 01:25:13 +00:00
if ( stream ) free_stream ( stream ) ; // kill cache thread
2003-11-03 16:35:40 +00:00
# ifdef USE_LIBAVCODEC
if ( lavc_abuf ! = NULL )
free ( lavc_abuf ) ;
# endif
2001-12-04 20:35:31 +00:00
return interrupted ;
2001-10-29 01:11:18 +00:00
}
2002-01-15 00:20:50 +00:00
2003-08-13 16:29:32 +00:00
static int parse_end_at ( m_option_t * conf , const char * param )
2002-01-15 00:20:50 +00:00
{
end_at_type = END_AT_NONE ;
/* End at size parsing */
{
char unit [ 4 ] ;
end_at_type = END_AT_SIZE ;
2002-12-14 17:56:35 +00:00
if ( sscanf ( param , " %lf%3s " , & end_at , unit ) = = 2 ) {
2002-01-15 00:20:50 +00:00
if ( ! strcasecmp ( unit , " b " ) )
;
else if ( ! strcasecmp ( unit , " kb " ) )
end_at * = 1024 ;
else if ( ! strcasecmp ( unit , " mb " ) )
end_at * = 1024 * 1024 ;
else
end_at_type = END_AT_NONE ;
}
else
end_at_type = END_AT_NONE ;
}
/* End at time parsing. This has to be last because of
* sscanf ( " %f " , . . . ) below */
if ( end_at_type = = END_AT_NONE )
{
int a , b ; float d ;
end_at_type = END_AT_TIME ;
if ( sscanf ( param , " %d:%d:%f " , & a , & b , & d ) = = 3 )
end_at = 3600 * a + 60 * b + d ;
else if ( sscanf ( param , " %d:%f " , & a , & d ) = = 2 )
end_at = 60 * a + d ;
else if ( sscanf ( param , " %f " , & d ) = = 1 )
end_at = d ;
else
end_at_type = END_AT_NONE ;
}
if ( end_at_type = = END_AT_NONE )
return ERR_FUNC_ERR ;
return 1 ;
}
2002-01-31 00:38:53 +00:00
2002-09-20 18:54:22 +00:00
#if 0
2002-01-31 00:38:53 +00:00
/* Flip the image in src and store the result in dst. src and dst may overlap.
width is the size of each line in bytes . */
static uint8_t * flip_upside_down ( uint8_t * dst , const uint8_t * src , int width ,
int height )
{
uint8_t * tmp = malloc ( width ) ;
int i ;
for ( i = 0 ; i < height / 2 ; i + + ) {
memcpy ( tmp , & src [ i * width ] , width ) ;
memcpy ( & dst [ i * width ] , & src [ ( height - i ) * width ] , width ) ;
memcpy ( & dst [ ( height - i ) * width ] , tmp , width ) ;
}
free ( tmp ) ;
return dst ;
}
2002-09-20 18:54:22 +00:00
# endif
2002-12-21 22:16:49 +00:00
# if HAVE_MP3LAME >= 392
/* lame_presets_set
taken out of presets_set in lame - 3.93 .1 / frontend / parse . c and modified */
static int lame_presets_set ( lame_t gfp , int fast , int cbr , const char * preset_name )
{
int mono = 0 ;
if ( strcmp ( preset_name , " help " ) = = 0 ) {
fprintf ( stdout , " LAME version %s (%s) \n \n " , get_lame_version ( ) , get_lame_url ( ) ) ;
lame_presets_longinfo_dm ( stdout ) ;
return - 1 ;
}
//aliases for compatibility with old presets
if ( strcmp ( preset_name , " phone " ) = = 0 ) {
preset_name = " 16 " ;
mono = 1 ;
}
if ( ( strcmp ( preset_name , " phon+ " ) = = 0 ) | |
( strcmp ( preset_name , " lw " ) = = 0 ) | |
( strcmp ( preset_name , " mw-eu " ) = = 0 ) | |
( strcmp ( preset_name , " sw " ) = = 0 ) ) {
preset_name = " 24 " ;
mono = 1 ;
}
if ( strcmp ( preset_name , " mw-us " ) = = 0 ) {
preset_name = " 40 " ;
mono = 1 ;
}
if ( strcmp ( preset_name , " voice " ) = = 0 ) {
preset_name = " 56 " ;
mono = 1 ;
}
if ( strcmp ( preset_name , " fm " ) = = 0 ) {
preset_name = " 112 " ;
}
if ( ( strcmp ( preset_name , " radio " ) = = 0 ) | |
( strcmp ( preset_name , " tape " ) = = 0 ) ) {
preset_name = " 112 " ;
}
if ( strcmp ( preset_name , " hifi " ) = = 0 ) {
preset_name = " 160 " ;
}
if ( strcmp ( preset_name , " cd " ) = = 0 ) {
preset_name = " 192 " ;
}
if ( strcmp ( preset_name , " studio " ) = = 0 ) {
preset_name = " 256 " ;
}
# if HAVE_MP3LAME >= 393
if ( strcmp ( preset_name , " medium " ) = = 0 ) {
if ( fast > 0 )
lame_set_preset ( gfp , MEDIUM_FAST ) ;
else
lame_set_preset ( gfp , MEDIUM ) ;
return 0 ;
}
# endif
if ( strcmp ( preset_name , " standard " ) = = 0 ) {
if ( fast > 0 )
lame_set_preset ( gfp , STANDARD_FAST ) ;
else
lame_set_preset ( gfp , STANDARD ) ;
return 0 ;
}
else if ( strcmp ( preset_name , " extreme " ) = = 0 ) {
if ( fast > 0 )
lame_set_preset ( gfp , EXTREME_FAST ) ;
else
lame_set_preset ( gfp , EXTREME ) ;
return 0 ;
}
else if ( ( ( strcmp ( preset_name , " insane " ) = = 0 ) | |
( strcmp ( preset_name , " 320 " ) = = 0 ) ) & & ( fast < 1 ) ) {
lame_set_preset ( gfp , INSANE ) ;
return 0 ;
}
// Generic ABR Preset
if ( ( ( atoi ( preset_name ) ) > 0 ) & & ( fast < 1 ) ) {
if ( ( atoi ( preset_name ) ) > = 8 & & ( atoi ( preset_name ) ) < = 320 ) {
lame_set_preset ( gfp , atoi ( preset_name ) ) ;
if ( cbr = = 1 )
lame_set_VBR ( gfp , vbr_off ) ;
if ( mono = = 1 ) {
lame_set_mode ( gfp , MONO ) ;
}
return 0 ;
}
else {
fprintf ( stderr , " LAME version %s (%s) \n \n " , get_lame_version ( ) , get_lame_url ( ) ) ;
fprintf ( stderr , " Error: The bitrate specified is out of the valid range for this preset \n "
" \n "
" When using this mode you must enter a value between \" 8 \" and \" 320 \" \n "
" \n "
" For further information try: \" -lameopts preset=help \" \n "
) ;
return - 1 ;
}
}
fprintf ( stderr , " LAME version %s (%s) \n \n " , get_lame_version ( ) , get_lame_url ( ) ) ;
fprintf ( stderr , " Error: You did not enter a valid profile and/or options with preset \n "
" \n "
" Available profiles are: \n "
" \n "
" <fast> standard \n "
" <fast> extreme \n "
" insane \n "
" <cbr> (ABR Mode) - The ABR Mode is implied. To use it, \n "
" simply specify a bitrate. For example: \n "
" \" preset=185 \" activates this \n "
" preset and uses 185 as an average kbps. \n "
" \n "
" Some examples: \n "
" \n "
" \" -lameopts fast:preset=standard \" \n "
" or \" -lameopts cbr:preset=192 \" \n "
" or \" -lameopts preset=172 \" \n "
" or \" -lameopts preset=extreme \" \n "
" \n "
" For further information try: \" -lameopts preset=help \" \n "
) ;
mencoder_exit ( 1 , " error parsing cmdline " ) ;
}
# endif
# if HAVE_MP3LAME >= 392
/* lame_presets_longinfo_dm
taken out of presets_longinfo_dm in lame - 3.93 .1 / frontend / parse . c and modified */
static void lame_presets_longinfo_dm ( FILE * msgfp )
{
fprintf ( msgfp ,
" \n "
" The preset switches are designed to provide the highest possible quality. \n "
" \n "
" They have for the most part been subject to and tuned via rigorous double blind \n "
" listening tests to verify and achieve this objective. \n "
" \n "
" These are continually updated to coincide with the latest developments that \n "
" occur and as a result should provide you with nearly the best quality \n "
" currently possible from LAME. \n "
" \n "
" To activate these presets: \n "
" \n "
" For VBR modes (generally highest quality): \n "
" \n "
" \" preset=standard \" This preset should generally be transparent \n "
" to most people on most music and is already \n "
" quite high in quality. \n "
" \n "
" \" preset=extreme \" If you have extremely good hearing and similar \n "
" equipment, this preset will generally provide \n "
" slightly higher quality than the \" standard \" \n "
" mode. \n "
" \n "
" For CBR 320kbps (highest quality possible from the preset switches): \n "
" \n "
" \" preset=insane \" This preset will usually be overkill for most \n "
" people and most situations, but if you must \n "
" have the absolute highest quality with no \n "
" regard to filesize, this is the way to go. \n "
" \n "
" For ABR modes (high quality per given bitrate but not as high as VBR): \n "
" \n "
" \" preset=<kbps> \" Using this preset will usually give you good \n "
" quality at a specified bitrate. Depending on the \n "
" bitrate entered, this preset will determine the \n "
" optimal settings for that particular situation. \n "
" While this approach works, it is not nearly as \n "
" flexible as VBR, and usually will not attain the \n "
" same level of quality as VBR at higher bitrates. \n "
" \n "
" The following options are also available for the corresponding profiles: \n "
" \n "
" <fast> standard \n "
" <fast> extreme \n "
" insane \n "
" <cbr> (ABR Mode) - The ABR Mode is implied. To use it, \n "
" simply specify a bitrate. For example: \n "
" \" preset=185 \" activates this \n "
" preset and uses 185 as an average kbps. \n "
" \n "
" \" fast \" - Enables the new fast VBR for a particular profile. The \n "
" disadvantage to the speed switch is that often times the \n "
" bitrate will be slightly higher than with the normal mode \n "
" and quality may be slightly lower also. \n "
" Warning: with the current version fast presets might result in too \n "
" high bitrate compared to regular presets. \n "
" \n "
" \" cbr \" - If you use the ABR mode (read above) with a significant \n "
" bitrate such as 80, 96, 112, 128, 160, 192, 224, 256, 320, \n "
" you can use the \" cbr \" option to force CBR mode encoding \n "
" instead of the standard abr mode. ABR does provide higher \n "
" quality but CBR may be useful in situations such as when \n "
" streaming an mp3 over the internet may be important. \n "
" \n "
" For example: \n "
" \n "
" \" -lameopts fast:preset=standard \" \n "
" or \" -lameopts cbr:preset=192 \" \n "
" or \" -lameopts preset=172 \" \n "
" or \" -lameopts preset=extreme \" \n "
" \n "
" \n "
" A few aliases are available for ABR mode: \n "
" phone => 16kbps/mono phon+/lw/mw-eu/sw => 24kbps/mono \n "
" mw-us => 40kbps/mono voice => 56kbps/mono \n "
" fm/radio/tape => 112kbps hifi => 160kbps \n "
" cd => 192kbps studio => 256kbps " ) ;
mencoder_exit ( 0 , NULL ) ;
}
# endif
2003-11-03 16:35:40 +00:00
# ifdef USE_LIBAVCODEC
static uint32_t lavc_find_atag ( char * codec )
{
if ( codec = = NULL )
return 0 ;
if ( ! strcasecmp ( codec , " mp2 " ) )
return 0x50 ;
if ( ! strcasecmp ( codec , " mp3 " ) )
return 0x55 ;
if ( ! strcasecmp ( codec , " ac3 " ) )
return 0x2000 ;
if ( ! strcasecmp ( codec , " adpcm_ima_wav " ) )
return 0x11 ;
2004-02-18 13:33:16 +00:00
if ( ! strncasecmp ( codec , " bonk " , 4 ) )
return 0x2048 ;
2003-11-03 16:35:40 +00:00
return 0 ;
}
# endif