diff options
Diffstat (limited to 'mencoder.c')
-rw-r--r-- | mencoder.c | 159 |
1 files changed, 87 insertions, 72 deletions
diff --git a/mencoder.c b/mencoder.c index 2d9d037e22..1661722679 100644 --- a/mencoder.c +++ b/mencoder.c @@ -86,9 +86,15 @@ #endif #include "libmpcodecs/ae.h" +#include "options.h" +#include "defaultopts.h" + +MPOpts opts; +struct osd_state *osd; + +const int under_mencoder = 1; int vo_doublebuffering=0; int vo_directrendering=0; -int vo_config_count=1; int forced_subs_only=0; //-------------------------- @@ -104,9 +110,6 @@ float stream_cache_seek_min_percent=50.0; #define cache_fill_status 0 #endif -int audio_id=-1; -int video_id=-1; -int dvdsub_id=-2; int vobsub_id=-1; char* audio_lang=NULL; char* dvdsub_lang=NULL; @@ -156,7 +159,6 @@ static int audio_density=2; double force_fps=0; static double force_ofps=0; // set to 24 for inverse telecine static int skip_limit=-1; -float playback_speed=1.0; static int force_srate=0; static int audio_output_format=0; @@ -203,18 +205,19 @@ char *info_sourceform=NULL; char *info_comment=NULL; // Needed by libmpcodecs vf_vo.c -int config_video_out(const vo_functions_t *vo, uint32_t width, uint32_t height, - uint32_t d_width, uint32_t d_height, uint32_t flags, - char *title, uint32_t format) { - return 1; -} -// Needed by libmpdemux. -int mp_input_check_interrupt(int time) { - usec_sleep(time); - return 0; -} +int vo_config(struct vo *vo, uint32_t width, uint32_t height, + uint32_t d_width, uint32_t d_height, uint32_t flags, + char *title, uint32_t format) { abort(); } +int vo_control(struct vo *vo, uint32_t request, void *data) { abort(); } +int vo_draw_frame(struct vo *vo, uint8_t *src[]) { abort(); } +int vo_draw_slice(struct vo *vo, uint8_t *src[], int stride[], int w, int h, int x, int y) { abort(); } +void vo_draw_osd(struct vo *vo, struct osd_state *osd) { abort(); } +void vo_flip_page(struct vo *vo) { abort(); } +void vo_check_events(struct vo *vo) { abort(); } + // Needed by getch2 -void mplayer_put_key(int code) +struct mp_fifo; +void mplayer_put_key(struct mp_fifo *fifo, int code) { } @@ -404,12 +407,11 @@ ao_data_t ao_data = {0,0,0,0,OUTBURST,-1,0}; audio_encoding_params_t aparams; audio_encoder_t *aencoder = NULL; -user_correct_pts = 0; - mp_msg_init(); // Create the config context and register the options - mconfig = m_config_new(); + set_default_mencoder_options(&opts); + mconfig = m_config_new(&opts, cfg_include); m_config_register_options(mconfig,mencoder_opts); // Preparse the command line @@ -471,7 +473,7 @@ if(!codecs_file || !parse_codec_cfg(codecs_file)){ if (frameno_filename) { stream2=open_stream(frameno_filename,0,&i); if(stream2){ - demuxer2=demux_open(stream2,DEMUXER_TYPE_AVI,-1,-1,-2,NULL); + demuxer2=demux_open(&opts, stream2,DEMUXER_TYPE_AVI,-1,-1,-2,NULL); if(demuxer2) mp_msg(MSGT_MENCODER, MSGL_INFO, MSGTR_UsingPass3ControlFile, frameno_filename); else mp_msg(MSGT_DEMUXER,MSGL_ERR,MSGTR_FormatNotRecognized); } @@ -504,7 +506,7 @@ if (frameno_filename) { } #endif - vo_init_osd(); + osd = osd_create(); /* HACK, for some weird reason, push() has to be called twice, otherwise options are not saved correctly */ @@ -529,15 +531,15 @@ play_next_file: #ifdef CONFIG_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==-2) dvdsub_id=dvd_sid_from_lang(stream,dvdsub_lang); + if(audio_lang && opts.audio_id==-1) opts.audio_id=dvd_aid_from_lang(stream,audio_lang); + if(dvdsub_lang && opts.sub_id==-2) opts.sub_id=dvd_sid_from_lang(stream,dvdsub_lang); } #endif #ifdef CONFIG_DVDNAV if(stream->type==STREAMTYPE_DVDNAV){ - if(audio_lang && audio_id==-1) audio_id=mp_dvdnav_aid_from_lang(stream,audio_lang); - if(dvdsub_lang && dvdsub_id==-2) dvdsub_id=mp_dvdnav_sid_from_lang(stream,dvdsub_lang); + if(audio_lang && opts.audio_id==-1) opts.audio_id=mp_dvdnav_aid_from_lang(stream,audio_lang); + if(dvdsub_lang && opts.sub_id==-2) opts.sub_id=mp_dvdnav_sid_from_lang(stream,dvdsub_lang); } #endif @@ -545,27 +547,27 @@ if(stream->type==STREAMTYPE_DVDNAV){ if(stream_cache_size>0) stream_enable_cache(stream,stream_cache_size*1024,0,0); - if(demuxer2) audio_id=-2; /* do NOT read audio packets... */ + if(demuxer2) opts.audio_id=-2; /* do NOT read audio packets... */ - //demuxer=demux_open(stream,file_format,video_id,audio_id,dvdsub_id); - demuxer=demux_open(stream,file_format,audio_id,video_id,dvdsub_id,filename); + //demuxer=demux_open(stream,file_format,opts.video_id,opts.audio_id,opts.sub_id); + demuxer=demux_open(&opts, stream,file_format,opts.audio_id,opts.video_id,opts.sub_id,filename); if(!demuxer){ mp_msg(MSGT_DEMUXER, MSGL_FATAL, MSGTR_FormatNotRecognized); mp_msg(MSGT_DEMUXER, MSGL_FATAL, MSGTR_CannotOpenDemuxer); mencoder_exit(1,NULL); } - select_audio(demuxer, audio_id, audio_lang); + select_audio(demuxer, opts.audio_id, audio_lang); - if (dvdsub_id < 0 && dvdsub_lang) - dvdsub_id = demuxer_sub_track_by_lang(demuxer, dvdsub_lang); + if (opts.sub_id < 0 && dvdsub_lang) + opts.sub_id = demuxer_sub_track_by_lang(demuxer, dvdsub_lang); - if (dvdsub_id < 0) - dvdsub_id = demuxer_default_sub_track(demuxer); + if (opts.sub_id < 0) + opts.sub_id = demuxer_default_sub_track(demuxer); for (i = 0; i < MAX_S_STREAMS; i++) { sh_sub_t *sh = demuxer->s_streams[i]; - if (sh && sh->sid == dvdsub_id) { + if (sh && sh->sid == opts.sub_id) { demuxer->sub->id = i; demuxer->sub->sh = sh; break; @@ -607,7 +609,7 @@ sh_video=d_video->sh; } if(sh_audio && out_audio_codec<0){ - if(audio_id==-2) + if(opts.audio_id==-2) mp_msg(MSGT_MENCODER,MSGL_ERR,MSGTR_DemuxerDoesntSupportNosound); mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_NoAudioEncoderSelected); mencoder_exit(1,NULL); @@ -617,7 +619,7 @@ sh_video=d_video->sh; mencoder_exit(1,NULL); } -if(sh_audio && (out_audio_codec || seek_to_sec || !sh_audio->wf || playback_speed != 1.0)){ +if(sh_audio && (out_audio_codec || seek_to_sec || !sh_audio->wf || opts.playback_speed != 1.0)){ // Go through the codec.conf and find the best codec... mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n"); if(!init_best_audio_codec(sh_audio,audio_codec_list,audio_fm_list)){ @@ -628,12 +630,12 @@ if(sh_audio && (out_audio_codec || seek_to_sec || !sh_audio->wf || playback_spee if (sh_audio) { new_srate = sh_audio->samplerate; - if (playback_speed != 1.0) { - new_srate *= playback_speed; + if (opts.playback_speed != 1.0) { + new_srate *= opts.playback_speed; // limits are taken from libaf/af_resample.c if (new_srate < 8000) new_srate = 8000; if (new_srate > 192000) new_srate = 192000; - playback_speed = (float)new_srate / (float)sh_audio->samplerate; + opts.playback_speed = (float)new_srate / (float)sh_audio->samplerate; } } @@ -663,7 +665,7 @@ if (!curfile) { // curfile is non zero when a second file is opened 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) + if (spudec_ifo && vobsub_parse_ifo(NULL,spudec_ifo, palette, &width, &height, 1, opts.sub_id, tmp) >= 0) vobsub_writer = vobsub_out_open(vobsub_out, palette, sh_video->disp_w, sh_video->disp_h, vobsub_out_id?vobsub_out_id:(char *)tmp, vobsub_out_index); #ifdef CONFIG_DVDREAD @@ -673,7 +675,7 @@ if (vobsub_out) { 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) { + if (dvd->subtitles[i].id == opts.sub_id) { tmp[0] = (dvd->subtitles[i].language >> 8) & 0xff; tmp[1] = dvd->subtitles[i].language & 0xff; tmp[2] = 0; @@ -730,14 +732,14 @@ mux_v->source=sh_video; mux_v->h.dwSampleSize=0; // VBR #ifdef CONFIG_LIBAVCODEC { - double fps = force_ofps?force_ofps:sh_video->fps*playback_speed; + double fps = force_ofps?force_ofps:sh_video->fps*opts.playback_speed; AVRational q= av_d2q(fps, fps*1001+2); mux_v->h.dwScale= q.den; mux_v->h.dwRate = q.num; } #else mux_v->h.dwScale=10000; -mux_v->h.dwRate=mux_v->h.dwScale*(force_ofps?force_ofps:sh_video->fps*playback_speed); +mux_v->h.dwRate=mux_v->h.dwScale*(force_ofps?force_ofps:sh_video->fps*opts.playback_speed); #endif mux_v->codec=out_video_codec; @@ -811,21 +813,21 @@ default: { if (!ve) { switch(mux_v->codec){ case VCODEC_LIBAVCODEC: - sh_video->vfilter=vf_open_encoder(NULL,"lavc",(char *)mux_v); break; + sh_video->vfilter=vf_open_encoder(&opts, NULL,"lavc",(char *)mux_v); break; case VCODEC_RAW: - sh_video->vfilter=vf_open_encoder(NULL,"raw",(char *)mux_v); break; + sh_video->vfilter=vf_open_encoder(&opts, NULL,"raw",(char *)mux_v); break; case VCODEC_VFW: - sh_video->vfilter=vf_open_encoder(NULL,"vfw",(char *)mux_v); break; + sh_video->vfilter=vf_open_encoder(&opts, NULL,"vfw",(char *)mux_v); break; case VCODEC_LIBDV: - sh_video->vfilter=vf_open_encoder(NULL,"libdv",(char *)mux_v); break; + sh_video->vfilter=vf_open_encoder(&opts, NULL,"libdv",(char *)mux_v); break; case VCODEC_XVID: - sh_video->vfilter=vf_open_encoder(NULL,"xvid",(char *)mux_v); break; + sh_video->vfilter=vf_open_encoder(&opts, NULL,"xvid",(char *)mux_v); break; case VCODEC_QTVIDEO: - sh_video->vfilter=vf_open_encoder(NULL,"qtvideo",(char *)mux_v); break; + sh_video->vfilter=vf_open_encoder(&opts, NULL,"qtvideo",(char *)mux_v); break; case VCODEC_NUV: - sh_video->vfilter=vf_open_encoder(NULL,"nuv",(char *)mux_v); break; + sh_video->vfilter=vf_open_encoder(&opts, NULL,"nuv",(char *)mux_v); break; case VCODEC_X264: - sh_video->vfilter=vf_open_encoder(NULL,"x264",(char *)mux_v); break; + sh_video->vfilter=vf_open_encoder(&opts, NULL,"x264",(char *)mux_v); break; } if(!mux_v->bih || !sh_video->vfilter){ mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_EncoderOpenFailed); @@ -836,9 +838,9 @@ default: { // append 'expand' filter, it fixes stride problems and renders osd: if (auto_expand) { char* vf_args[] = { "osd", "1", NULL }; - sh_video->vfilter=vf_open_filter(sh_video->vfilter,"expand",vf_args); + sh_video->vfilter=vf_open_filter(&opts, sh_video->vfilter,"expand",vf_args); } - sh_video->vfilter=append_filters(sh_video->vfilter); + sh_video->vfilter=append_filters(sh_video->vfilter, opts.vf_settings); mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n"); init_best_video_codec(sh_video,video_codec_list,video_fm_list); @@ -913,7 +915,7 @@ if(mux_a->codec != ACODEC_COPY) { } switch(mux_a->codec){ case ACODEC_COPY: - if (playback_speed != 1.0) mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_NoSpeedWithFrameCopy); + if (opts.playback_speed != 1.0) mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_NoSpeedWithFrameCopy); if (sh_audio->format >= 0x10000) { mp_msg(MSGT_MENCODER,MSGL_ERR,MSGTR_CantCopyAudioFormat, sh_audio->format); mencoder_exit(1,NULL); @@ -941,8 +943,8 @@ case ACODEC_COPY: mux_a->h.dwScale=mux_a->h.dwSampleSize; mux_a->h.dwRate=mux_a->wf->nAvgBytesPerSec; } - mux_a->h.dwRate *= playback_speed; - mux_a->wf->nSamplesPerSec *= playback_speed; + mux_a->h.dwRate *= opts.playback_speed; + mux_a->wf->nSamplesPerSec *= opts.playback_speed; mp_msg(MSGT_MENCODER, MSGL_INFO, MSGTR_ACodecFramecopy, mux_a->wf->wFormatTag, mux_a->wf->nChannels, mux_a->wf->nSamplesPerSec, mux_a->wf->wBitsPerSample, mux_a->wf->nAvgBytesPerSec, mux_a->h.dwSampleSize); @@ -972,17 +974,17 @@ else { mencoder_exit(1,NULL); } if (sh_audio && mux_a->codec == ACODEC_COPY) { - if (playback_speed != 1.0) mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_NoSpeedWithFrameCopy); + if (opts.playback_speed != 1.0) mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_NoSpeedWithFrameCopy); mp_msg(MSGT_MENCODER, MSGL_INFO, MSGTR_ACodecFramecopy, mux_a->wf->wFormatTag, mux_a->wf->nChannels, mux_a->wf->nSamplesPerSec, mux_a->wf->wBitsPerSample, mux_a->wf->nAvgBytesPerSec, mux_a->h.dwSampleSize); if (sh_audio->wf) { if ((mux_a->wf->wFormatTag != sh_audio->wf->wFormatTag) || (mux_a->wf->nChannels != sh_audio->wf->nChannels) || - (mux_a->wf->nSamplesPerSec != sh_audio->wf->nSamplesPerSec * playback_speed)) + (mux_a->wf->nSamplesPerSec != sh_audio->wf->nSamplesPerSec * opts.playback_speed)) { mp_msg(MSGT_MENCODER, MSGL_INFO, MSGTR_ACodecFramecopy, - sh_audio->wf->wFormatTag, sh_audio->wf->nChannels, (int)(sh_audio->wf->nSamplesPerSec * playback_speed), + sh_audio->wf->wFormatTag, sh_audio->wf->nChannels, (int)(sh_audio->wf->nSamplesPerSec * opts.playback_speed), sh_audio->wf->wBitsPerSample, sh_audio->wf->nAvgBytesPerSec, 0); mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_AudioCopyFileMismatch); mencoder_exit(1,NULL); @@ -990,10 +992,10 @@ else { } else { if ((mux_a->wf->wFormatTag != sh_audio->format) || (mux_a->wf->nChannels != sh_audio->channels) || - (mux_a->wf->nSamplesPerSec != sh_audio->samplerate * playback_speed)) + (mux_a->wf->nSamplesPerSec != sh_audio->samplerate * opts.playback_speed)) { mp_msg(MSGT_MENCODER, MSGL_INFO, MSGTR_ACodecFramecopy, - sh_audio->wf->wFormatTag, sh_audio->wf->nChannels, (int)(sh_audio->wf->nSamplesPerSec * playback_speed), + sh_audio->wf->wFormatTag, sh_audio->wf->nChannels, (int)(sh_audio->wf->nSamplesPerSec * opts.playback_speed), sh_audio->wf->wBitsPerSample, sh_audio->wf->nAvgBytesPerSec, 0); mp_msg(MSGT_MENCODER,MSGL_FATAL,MSGTR_AudioCopyFileMismatch); mencoder_exit(1,NULL); @@ -1220,7 +1222,7 @@ if(sh_audio){ frame_data.in_size=video_read_frame(sh_video,&frame_data.frame_time,&frame_data.start,force_fps); sh_video->timer+=frame_data.frame_time; } - frame_data.frame_time /= playback_speed; + frame_data.frame_time /= opts.playback_speed; if(frame_data.in_size<0){ at_eof=1; break; } ++decoded_frameno; @@ -1293,9 +1295,16 @@ case VCODEC_FRAMENO: break; default: // decode_video will callback down to ve_*.c encoders, through the video filters + sh_video->vfilter->control(sh_video->vfilter, VFCTRL_SET_OSD_OBJ, osd); {void *decoded_frame = decode_video(sh_video,frame_data.start,frame_data.in_size, - skip_flag>0 && (!sh_video->vfilter || ((vf_instance_t *)sh_video->vfilter)->control(sh_video->vfilter, VFCTRL_SKIP_NEXT_FRAME, 0) != CONTROL_TRUE), MP_NOPTS_VALUE); - blit_frame = decoded_frame && filter_video(sh_video, decoded_frame, MP_NOPTS_VALUE);} + skip_flag>0 && (!sh_video->vfilter || sh_video->vfilter->control(sh_video->vfilter, VFCTRL_SKIP_NEXT_FRAME, 0) != CONTROL_TRUE), MP_NOPTS_VALUE); + blit_frame = decoded_frame && filter_video(sh_video, decoded_frame, MP_NOPTS_VALUE); + if (blit_frame) { + struct vf_instance *vf = sh_video->vfilter; + vf->control(vf, VFCTRL_DRAW_EOSD, NULL); + vf->control(vf, VFCTRL_DRAW_OSD, osd); + } + } if (sh_video->vf_initialized < 0) mencoder_exit(1, NULL); @@ -1314,7 +1323,7 @@ default: // Eventually this entire block should probably be removed. if(skip_limit==0){ // skipping not allowed -> write empty frame: - if (!encode_duplicates || !sh_video->vfilter || ((vf_instance_t *)sh_video->vfilter)->control(sh_video->vfilter, VFCTRL_DUPLICATE_FRAME, 0) != CONTROL_TRUE) + if (!encode_duplicates || !sh_video->vfilter || sh_video->vfilter->control(sh_video->vfilter, VFCTRL_DUPLICATE_FRAME, 0) != CONTROL_TRUE) muxer_write_chunk(mux_v,0,0, MP_NOPTS_VALUE, MP_NOPTS_VALUE); } else { // skipping allowed -> skip it and distriubute timer error: @@ -1333,7 +1342,7 @@ if(skip_flag<0){ if(!quiet) mp_msg(MSGT_MENCODER, MSGL_WARN, MSGTR_DuplicateFrames,-skip_flag); while(skip_flag<0){ duplicatedframes++; - if (!encode_duplicates || !sh_video->vfilter || ((vf_instance_t *)sh_video->vfilter)->control(sh_video->vfilter, VFCTRL_DUPLICATE_FRAME, 0) != CONTROL_TRUE) + if (!encode_duplicates || !sh_video->vfilter || sh_video->vfilter->control(sh_video->vfilter, VFCTRL_DUPLICATE_FRAME, 0) != CONTROL_TRUE) muxer_write_chunk(mux_v,0,0, MP_NOPTS_VALUE, MP_NOPTS_VALUE); ++skip_flag; } @@ -1369,7 +1378,7 @@ if(sh_audio && !demuxer2){ // av = compensated (with out buffering delay) A-V diff AV_delay=(a_pts-v_pts); AV_delay-=audio_delay; - AV_delay /= playback_speed; + AV_delay /= opts.playback_speed; AV_delay-=mux_a->timer-(mux_v->timer-(v_timer_corr+v_pts_corr)); // adjust for encoder delays AV_delay -= (float) mux_a->encoder_delay * mux_a->h.dwScale/mux_a->h.dwRate; @@ -1379,9 +1388,9 @@ if(sh_audio && !demuxer2){ 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*playback_speed; + max_pts_correction=default_max_pts_correction*opts.playback_speed; else - max_pts_correction=sh_video->frametime*0.10 *playback_speed; // +-10% of time + max_pts_correction=sh_video->frametime*0.10 *opts.playback_speed; // +-10% of time // sh_video->timer-=x; c_total+=x; v_pts_corr+=x; @@ -1497,10 +1506,10 @@ if (!interrupted && filelist[++curfile].name != 0) { /*TODO emit frmaes delayed by decoder lag*/ if(sh_video && sh_video->vfilter){ mp_msg(MSGT_MENCODER, MSGL_INFO, MSGTR_FlushingVideoFrames); - if (!((vf_instance_t *)sh_video->vfilter)->fmt.have_configured) + if (!sh_video->vfilter->fmt.have_configured) mp_msg(MSGT_MENCODER, MSGL_WARN, MSGTR_FiltersHaveNotBeenConfiguredEmptyFile); else - ((vf_instance_t *)sh_video->vfilter)->control(sh_video->vfilter, + sh_video->vfilter->control(sh_video->vfilter, VFCTRL_FLUSH_FRAMES, 0); } @@ -1655,10 +1664,16 @@ static int slowseek(float end_pts, demux_stream_t *d_video, demux_stream_t *d_au if (sh_video->pts >= end_pts) done = 1; if (vfilter) { + sh_video->vfilter->control(sh_video->vfilter, VFCTRL_SET_OSD_OBJ, + osd); int softskip = (vfilter->control(vfilter, VFCTRL_SKIP_NEXT_FRAME, 0) == CONTROL_TRUE); void *decoded_frame = decode_video(sh_video, frame_data->start, frame_data->in_size, !softskip, MP_NOPTS_VALUE); if (decoded_frame) - filter_video(sh_video, decoded_frame, MP_NOPTS_VALUE); + if (filter_video(sh_video, decoded_frame, MP_NOPTS_VALUE)) { + struct vf_instance *vf = sh_video->vfilter; + vf->control(vf, VFCTRL_DRAW_EOSD, NULL); + vf->control(vf, VFCTRL_DRAW_OSD, osd); + } } if (print_info) mp_msg(MSGT_MENCODER, MSGL_STATUS, |