Index: cfg-mencoder.h =================================================================== RCS file: /cvsroot/mplayer/main/cfg-mencoder.h,v retrieving revision 1.106 diff -u -r1.106 cfg-mencoder.h --- cfg-mencoder.h 9 Jan 2006 19:35:43 -0000 1.106 +++ cfg-mencoder.h 31 Jan 2006 21:33:15 -0000 @@ -4,6 +4,7 @@ */ #include "cfg-common.h" +#include #ifdef USE_FAKE_MONO extern int fakemono; // defined in dec_audio.c @@ -221,7 +222,7 @@ {"audio-density", &audio_density, CONF_TYPE_INT, CONF_RANGE|CONF_GLOBAL, 1, 50, NULL}, {"audio-preload", &audio_preload, CONF_TYPE_FLOAT, CONF_RANGE|CONF_GLOBAL, 0, 2, NULL}, - {"audio-delay", &audio_delay_fix, CONF_TYPE_FLOAT, CONF_MIN|CONF_GLOBAL, 0, 0, NULL}, + {"audio-delay", &audio_delay_fix, CONF_TYPE_FLOAT, CONF_RANGE|CONF_GLOBAL, -FLT_MAX, FLT_MAX, NULL}, {"x", "-x is obsolete, use -vf scale=w:h for scaling.\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL}, {"xsize", "-xsize is obsolete, use -vf crop=w:h:x:y for cropping.\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL}, Index: mencoder.c =================================================================== RCS file: /cvsroot/mplayer/main/mencoder.c,v retrieving revision 1.332 diff -u -r1.332 mencoder.c --- mencoder.c 26 Jan 2006 19:32:05 -0000 1.332 +++ mencoder.c 31 Jan 2006 21:33:16 -0000 @@ -863,6 +863,8 @@ mux_v->bih->biCompression, (char *)&mux_v->bih->biCompression); } +audio_delay_fix -= (float) sh_video->video.dwStart * sh_video->video.dwScale/sh_video->video.dwRate; + //if(demuxer->file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf! // ============= AUDIO =============== @@ -941,7 +943,6 @@ mux_a->h.dwSampleSize=sh_audio->audio.dwSampleSize; mux_a->h.dwScale=sh_audio->audio.dwScale; mux_a->h.dwRate=sh_audio->audio.dwRate; -// mux_a->h.dwStart=sh_audio->audio.dwStart; } else { mux_a->h.dwSampleSize=mux_a->wf->nBlockAlign; mux_a->h.dwScale=mux_a->h.dwSampleSize; @@ -957,13 +958,20 @@ if (verbose>1) print_wave_header(mux_a->wf); -if(audio_delay_fix!=0.0){ +audio_delay_fix += (float) sh_audio->audio.dwStart * sh_audio->audio.dwScale/sh_audio->audio.dwRate; + +} // if(sh_audio) + +/* deal with stream delays */ +if (sh_video && audio_delay_fix < 0.0){ + mux_v->h.dwStart=-audio_delay_fix*mux_v->h.dwRate/mux_v->h.dwScale; + mp_msg(MSGT_MENCODER, MSGL_INFO, MSGTR_SettingVideoDelay,mux_v->h.dwStart*mux_v->h.dwScale/(float)mux_v->h.dwRate); +} +if(sh_audio && audio_delay_fix > 0.0){ mux_a->h.dwStart=audio_delay_fix*mux_a->h.dwRate/mux_a->h.dwScale; mp_msg(MSGT_MENCODER, MSGL_INFO, MSGTR_SettingAudioDelay,mux_a->h.dwStart*mux_a->h.dwScale/(float)mux_a->h.dwRate); } -} // if(sh_audio) - decoded_frameno=0; signal(SIGINT,exit_sighandler); // Interrupt from keyboard Index: mplayer.c =================================================================== RCS file: /cvsroot/mplayer/main/mplayer.c,v retrieving revision 1.904 diff -u -r1.904 mplayer.c --- mplayer.c 13 Jan 2006 20:06:59 -0000 1.904 +++ mplayer.c 31 Jan 2006 21:33:18 -0000 @@ -2522,8 +2522,14 @@ current_module="av_init"; -if(sh_video) sh_video->timer=0; -if(sh_audio) sh_audio->delay=-audio_delay; +if(sh_video){ + sh_video->timer=0; + audio_delay += (float) sh_video->video.dwStart * sh_video->video.dwScale/sh_video->video.dwRate; +} +if(sh_audio){ + audio_delay -= (float) sh_audio->audio.dwStart * sh_audio->audio.dwScale/sh_audio->audio.dwRate; + sh_audio->delay=-audio_delay; +} if(!sh_audio){ mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_NoSound); Index: DOCS/man/en/mplayer.1 =================================================================== RCS file: /cvsroot/mplayer/main/DOCS/man/en/mplayer.1,v retrieving revision 1.1219 diff -u -r1.1219 mplayer.1 --- DOCS/man/en/mplayer.1 29 Jan 2006 19:56:35 -0000 1.1219 +++ DOCS/man/en/mplayer.1 31 Jan 2006 21:33:19 -0000 @@ -6056,11 +6056,15 @@ .SH "GENERAL ENCODING OPTIONS (MENCODER ONLY)" . .TP -.B \-audio-delay <0.0\-...> -Sets the audio delay field in the header. -Default is 0.0, negative values do not work. -This does not delay the audio while encoding, but the player will see the -default audio delay, sparing you the use of the \-delay option. +.B \-audio-delay +Delays either audio or video by setting a delay field in the header +(default: 0.0). +This does not delay either stream while encoding, but the player will +see the delay field and compensate accordingly. +Positive values delay the audio, and negative values delay the video. +Note that this is the exact opposite of the \-delay option. +For example, if a video plays correctly with \-delay 0.2, you can +fix the video with MEncoder by using \-audio-delay -0.2. . .TP .B \-audio-density <1\-50> Index: help/help_mp-en.h =================================================================== RCS file: /cvsroot/mplayer/main/help/help_mp-en.h,v retrieving revision 1.221 diff -u -r1.221 help_mp-en.h --- help/help_mp-en.h 30 Jan 2006 19:37:17 -0000 1.221 +++ help/help_mp-en.h 31 Jan 2006 21:33:20 -0000 @@ -262,6 +262,7 @@ #define MSGTR_MP3AudioSelected "MP3 audio selected\n" #define MSGTR_CannotAllocateBytes "Couldn't allocate %d bytes\n" #define MSGTR_SettingAudioDelay "Setting AUDIO DELAY to %5.3f\n" +#define MSGTR_SettingVideoDelay "Setting VIDEO DELAY to %5.3f\n" #define MSGTR_SettingAudioInputGain "Setting audio input gain to %f\n" #define MSGTR_LamePresetEquals "\npreset=%s\n\n" #define MSGTR_LimitingAudioPreload "Limiting audio preload to 0.4s\n" Index: libmpdemux/demux_avi.c =================================================================== RCS file: /cvsroot/mplayer/main/libmpdemux/demux_avi.c,v retrieving revision 1.70 diff -u -r1.70 demux_avi.c --- libmpdemux/demux_avi.c 12 Jan 2006 20:04:34 -0000 1.70 +++ libmpdemux/demux_avi.c 31 Jan 2006 21:33:20 -0000 @@ -733,7 +733,7 @@ } else { // VBR audio - int chunks=(priv->avi_video_pts)*(float)sh_audio->audio.dwRate/(float)sh_audio->audio.dwScale; + int chunks=(priv->avi_video_pts)*(float)sh_audio->audio.dwRate/(float)sh_audio->audio.dwScale - sh_audio->audio.dwStart; audio_chunk_pos=0; // find audio chunk pos: