diff -ur main.orig/cfg-mencoder.h main.patchtest/cfg-mencoder.h --- main.orig/cfg-mencoder.h 2006-02-13 12:55:36.000000000 -0800 +++ main.patchtest/cfg-mencoder.h 2006-02-16 19:26:10.000000000 -0800 @@ -221,7 +221,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_GLOBAL, 0, 0, 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}, diff -ur main.orig/DOCS/man/en/mplayer.1 main.patchtest/DOCS/man/en/mplayer.1 --- main.orig/DOCS/man/en/mplayer.1 2006-02-13 12:55:38.000000000 -0800 +++ main.patchtest/DOCS/man/en/mplayer.1 2006-02-16 19:26:10.000000000 -0800 @@ -1098,7 +1098,7 @@ .br .I NOTE: When used with MEncoder, this is not guaranteed to work correctly -with \-ovc copy. +with \-ovc copy; use \-audio-delay instead. . .TP .B \-demuxer <[+]name> @@ -6058,11 +6058,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> diff -ur main.orig/help/help_mp-en.h main.patchtest/help/help_mp-en.h --- main.orig/help/help_mp-en.h 2006-02-13 12:55:41.000000000 -0800 +++ main.patchtest/help/help_mp-en.h 2006-02-16 19:26:10.000000000 -0800 @@ -261,7 +261,8 @@ #define MSGTR_CBRPCMAudioSelected "CBR PCM audio selected\n" #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_SettingAudioDelay "Setting audio delay to %5.3fs\n" +#define MSGTR_SettingVideoDelay "Setting video delay to %5.3fs\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" diff -ur main.orig/libmpdemux/muxer_avi.c main.patchtest/libmpdemux/muxer_avi.c --- main.orig/libmpdemux/muxer_avi.c 2006-02-13 12:55:43.000000000 -0800 +++ main.patchtest/libmpdemux/muxer_avi.c 2006-02-16 19:26:10.000000000 -0800 @@ -285,6 +285,19 @@ mp_msg(MSGT_MUXER, MSGL_INFO, "ODML: vprp aspect is %d:%d.\n", aspect >> 16, aspect & 0xffff); } + /* deal with stream delays */ + for (i = 0; muxer->streams[i] && i < MUXER_MAX_STREAMS; ++i) { + muxer_stream_t *s = muxer->streams[i]; + if (s->type == MUXER_TYPE_AUDIO && muxer->audio_delay_fix > 0.0) { + s->h.dwStart = muxer->audio_delay_fix * s->h.dwRate/s->h.dwScale; + mp_msg(MSGT_MUXER, MSGL_INFO, MSGTR_SettingAudioDelay, (float)s->h.dwStart * s->h.dwScale/s->h.dwRate); + } + if (s->type == MUXER_TYPE_VIDEO && muxer->audio_delay_fix < 0.0) { + s->h.dwStart = -muxer->audio_delay_fix * s->h.dwRate/s->h.dwScale; + mp_msg(MSGT_MUXER, MSGL_INFO, MSGTR_SettingVideoDelay, (float)s->h.dwStart * s->h.dwScale/s->h.dwRate); + } + } + if (isodml) { unsigned int rifflen, movilen; int i; diff -ur main.orig/libmpdemux/muxer.h main.patchtest/libmpdemux/muxer.h --- main.orig/libmpdemux/muxer.h 2006-02-13 12:55:43.000000000 -0800 +++ main.patchtest/libmpdemux/muxer.h 2006-02-16 19:26:10.000000000 -0800 @@ -59,6 +60,7 @@ off_t movi_start; off_t movi_end; off_t file_end; // for MPEG it's system timestamp in 1/90000 s + float audio_delay_fix; // index: AVIINDEXENTRY *idx; int idx_pos; diff -ur main.orig/mencoder.c main.patchtest/mencoder.c --- main.orig/mencoder.c 2006-02-16 18:09:41.000000000 -0800 +++ main.patchtest/mencoder.c 2006-02-16 19:26:10.000000000 -0800 @@ -723,6 +723,8 @@ } if(out_file_format == MUXER_TYPE_MPEG) audio_preload = 0; +muxer->audio_delay_fix = audio_delay_fix; + // ============= VIDEO =============== mux_v=muxer_new_stream(muxer,MUXER_TYPE_VIDEO); @@ -864,6 +866,8 @@ mux_v->bih->biCompression, (char *)&mux_v->bih->biCompression); } + muxer->audio_delay_fix -= sh_video->stream_delay; + //if(demuxer->file_format!=DEMUXER_TYPE_AVI) pts_from_bps=0; // it must be 0 for mpeg/asf! // ============= AUDIO =============== @@ -942,7 +946,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; @@ -958,10 +961,7 @@ if (verbose>1) print_wave_header(mux_a->wf); -if(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); -} + muxer->audio_delay_fix += sh_audio->stream_delay; } // if(sh_audio)