Opened 12 years ago

Last modified 5 years ago

#1349 reopened defect

itsoffset doesn't work for second input file (audio)

Reported by: bombo Owned by:
Priority: normal Component: ffmpeg
Version: git-master Keywords: itsoffset
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

this delays the video for 10s:
$ ffmpeg -itsoffset -00:00:10 -i video.avi -i audio.mp3 -codec copy muxed.avi
playing with mplayer shows that its working.

now i need the audio to be delayed 10s so it would be:
$ ffmpeg -i video.avi -itsoffset -00:00:10 -i audio.mp3 -codec copy muxed.avi
the result is no delay at all.

version is: ffmpeg-20120519-git-31dfe20-win32-static.7z

Change History (11)

comment:1 by Carl Eugen Hoyos, 12 years ago

Complete, uncut console output missing.

comment:2 by Mike, 12 years ago

* Edit by mjs973: this information is wrong; see post below *

The -itsoffset option does not work the way you think it does.

Unless something has changed in the code, the behavior is to add (or subtract) a constant value to each *video* timestamp. It never modifies audio timestamps.

So your command will not work: You must shift the video stream, not try to shift the audio stream.

I think this ticket should be closed with resolution of "invalid".

Last edited 12 years ago by Mike (previous) (diff)

comment:3 by Carl Eugen Hoyos, 12 years ago

Keywords: audio mux removed
Resolution: invalid
Status: newclosed

Thank you for the explanation!

in reply to:  2 comment:4 by bombo, 12 years ago

Replying to mjs973:

The -itsoffset option does not work the way you think it does.

‘-itsoffset offset (input)’

    Set the input time offset in seconds. [-]hh:mm:ss[.xxx] syntax is also supported. The offset is added to the timestamps of the input files. Specifying a positive offset means that the corresponding streams are delayed by offset seconds.

(http://ffmpeg.org/ffmpeg.html)

someone should add *video* there, i thought it would modify *any* 'input files'

Unless something has changed in the code, the behavior is to add (or subtract) a constant value to each *video* timestamp. It never modifies audio timestamps.

So your command will not work: You must shift the video stream, not try to shift the audio stream.

well ok, so i need to shift the video stream 10s backwards (audio is 10s early)
it works for positive values (forwards):

Y:\test>ffmpeg -y -itsoffset 00:00:10 -i video.avi -i audio.mp3 -codec copy muxed.avi
ffmpeg version N-40824-g31dfe20 Copyright (c) 2000-2012 the FFmpeg developers built on May 19 2012 00:45:59 with gcc 4.6.3  configuration: --enable-gpl --ena
ble-version3 --disable-w32threads --enable-runtime-cpudetect --enable-avisynth --enable-bzlib --enable-frei0r --enable-libass --enable-libcelt --enable-libop
encore-amrnb --enable-libopencore-amrwb --enable
-libfreetype --enable-libgsm --enable-libmp3lame --enable-libnut --enable-libopenjpeg --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-li
btheora --enable-libutvideo --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-libxv
id --enable-zlib
  libavutil      51. 53.100 / 51. 53.100
  libavcodec     54. 21.101 / 54. 21.101
  libavformat    54.  5.100 / 54.  5.100
  libavdevice    53.  4.100 / 53.  4.100
  libavfilter     2. 74.101 /  2. 74.101
  libswscale      2.  1.100 /  2.  1.100
  libswresample   0. 12.100 /  0. 12.100
  libpostproc    52.  0.100 / 52.  0.100
Input #0, avi, from 'video.avi':
  Metadata:
    encoder         : Lavf54.5.100
  Duration: 00:01:00.00, start: 0.000000, bitrate: 1237 kb/s
    Stream #0:0: Video: mpeg4 (Advanced Simple Profile) (XVID / 0x44495658), yuv420p, 720x416 [SAR 1:1 DAR 45:26], 25 tbr, 25 tbn, 25 tbc
[mp3 @ 0228f040] max_analyze_duration 5000000 reached at 5016000
Input #1, mp3, from 'audio.mp3':
  Metadata:
    encoder         : Lavf54.5.100
  Duration: 00:01:00.00, start: 0.000000, bitrate: 183 kb/s
    Stream #1:0: Audio: mp3, 48000 Hz, stereo, s16, 192 kb/s
Output #0, avi, to 'muxed.avi':
  Metadata:
    ISFT            : Lavf54.5.100
    Stream #0:0: Video: mpeg4 (XVID / 0x44495658), yuv420p, 720x416 [SAR 1:1 DAR 45:26], q=2-31, 25 tbn, 25 tbc
    Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 48000 Hz, stereo, 192 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #1:0 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame= 1500 fps=0.0 q=-1.0 Lsize=   10476kB time=00:01:00.00 bitrate=1430.4kbits/s
video:9020kB audio:1346kB global headers:0kB muxing overhead 1.063745%

result: audio starts at 00:00:00, video starts at 00:00:10 (10s later)

but the problem is actually, the audio is 10s early, so i expect negative values to do the trick:

Y:\test>ffmpeg -y -itsoffset -00:00:10 -i video.avi -i audio.mp3 -codec copy muxed.avi
ffmpeg version N-40824-g31dfe20 Copyright (c) 2000-2012 the FFmpeg developers built on May 19 2012 00:45:59 with gcc 4.6.3
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-runtime-cpudetect --enable-avisynth --enable-bzlib --enable-frei0r --enable-lib
ass --enable-libcelt --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-libnut --enable-
libopenjpeg --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libutvideo --enable-libvo-aacenc --enable-libvo-amrwbenc
--enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
  libavutil      51. 53.100 / 51. 53.100
  libavcodec     54. 21.101 / 54. 21.101
  libavformat    54.  5.100 / 54.  5.100
  libavdevice    53.  4.100 / 53.  4.100
  libavfilter     2. 74.101 /  2. 74.101
  libswscale      2.  1.100 /  2.  1.100
  libswresample   0. 12.100 /  0. 12.100
  libpostproc    52.  0.100 / 52.  0.100
Input #0, avi, from 'video.avi':
  Metadata:
    encoder         : Lavf54.5.100
  Duration: 00:01:00.00, start: 0.000000, bitrate: 1237 kb/s
    Stream #0:0: Video: mpeg4 (Advanced Simple Profile) (XVID / 0x44495658), yuv420p, 720x416 [SAR 1:1 DAR 45:26], 25 tbr, 25 tbn, 25 tbc
[mp3 @ 0228f040] max_analyze_duration 5000000 reached at 5016000
Input #1, mp3, from 'audio.mp3':
  Metadata:
    encoder         : Lavf54.5.100
  Duration: 00:01:00.00, start: 0.000000, bitrate: 183 kb/s
    Stream #1:0: Audio: mp3, 48000 Hz, stereo, s16, 192 kb/s
Output #0, avi, to 'muxed.avi':
  Metadata:
    ISFT            : Lavf54.5.100
    Stream #0:0: Video: mpeg4 (XVID / 0x44495658), yuv420p, 720x416 [SAR 1:1 DAR 45:26], q=2-31, 25 tbn, 25 tbc
    Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 48000 Hz, stereo, 192 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #1:0 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame= 1500 fps=0.0 q=-1.0 Lsize=   10470kB time=00:00:50.00 bitrate=1715.5kbits/s
video:9020kB audio:1346kB global headers:0kB muxing overhead 1.007220%

result: audio + video play at the same time, 00:00:00, no delay at all.

i'm not sure what it is supposed to do with negative values... skip/remove the seconds from the video stream?

Last edited 12 years ago by bombo (previous) (diff)

comment:5 by Mike, 12 years ago

So, are you saying that -10 didn't give the result you wanted?

There are two experiments you could try:

1) the .avi container is fairly dumb: it has no timestamps. Have you tried using a better container (.mp4 or .mkv) for the output file to see if that works any better? I'm not sure which containers know how to handle XVID and mp3.

~2) There could be a bug when two input files are used. The -itsoffset feature is typically used on a single input file. Have you tried muxing the two streams into a single file without using -itsoffset, then doing the time shift by re-muxing that one file with -itsoffset?~

Last edited 12 years ago by Mike (previous) (diff)

comment:6 by Mike, 12 years ago

I've looked into this further. My description in comment 2 doesn't match the behavior of current git, so either I mis-remembered or something changed.

This command should display file1 content one second earlier than file2 content:

ffmpeg -itsoffset -1 -i file1.ts -i file2.ts -vcodec copy -acodec copy -map 0:0 -map 1:1 out.ts

1) What I see is that -itsoffset adds or subtracts from all the timestamps (both the video and audio streams) in a file. So this option is only going to be useful when remuxing from separate input files.

2) outfile has expected playback behavior with .ts and .mkv containers.

3) It does not work with .avi (no timestamps, so not a surprise)

4) It does not work with .mp4 container (a bug?)

comment:7 by Carl Eugen Hoyos, 12 years ago

Resolution: invalid
Status: closedreopened

Reopening as is seems unclear if there is a problem or not.

comment:8 by Selur, 11 years ago

Since I too just ran into this problem, I have another question:

Invert and moving the itsoffset before the video input stream works fine as long as my avi has just one audio stream, but what should I do if I have multiple audio streams with different delays?

comment:9 by Oddthinking, 7 years ago

I believe I have encountered this same problem with ffmpeg version N-82225-gb4e9252.

ffmpeg -y -itsoffset 28.84 -i soundtrack.wav -framerate 30 -i %d.png -r 30 -vcodec mpeg4 generated.mp4

The generated file has a soundtrack that starts immediately, when I expect it to be delayed.

If I change the final extension:

ffmpeg -y -itsoffset 28.84 -i soundtrack.wav -framerate 30 -i %d.png -r 30 -vcodec mpeg4 generated.mkv

the soundtrack is now delayed by 28 and a bit seconds.

comment:10 by Selur, 7 years ago

Since I ran into this problem again.

For testing the effect of itsoffset I took a synch avi(xvid,mp3) file and remuxed it using:

1.

ffmpeg -y -itsoffset 00:00:10.000 -i "test.avi" -i "test.mp3" -vcodec copy -acodec copy -map 0:0 -map 1:0 -vtag XVID -aspect 181818:100000 -r 25 -f avi "test1.avi"

-> Audio starts 10sec before video (this is like I expected)

2.

ffmpeg -y -i "test.avi"  -itsoffset -00:00:10.000 -i "test.mp3" -vcodec copy -acodec copy -map 0:0 -map 1:0 -vtag XVID -aspect 181818:100000 -r 25 -f avi "test3.avi"

-> Audio starts 10sec before video (this is like I expected)

3.

ffmpeg -y -itsoffset -00:00:10.000 -i "test.avi" -i "test.mp3" -vcodec copy -acodec copy -map 0:0 -map 1:0 -vtag XVID -aspect 181818:100000 -r 25 -f avi "test2.avi"

-> Audio and video start at the same time (I expected that the video would start before the audio)
4.

ffmpeg -y -i "test.avi"  -itsoffset 00:00:10.000 -i "test.mp3" -vcodec copy -acodec copy -map 0:0 -map 1:0 -vtag XVID -aspect 181818:100000 -r 25 -f avi "test4.avi"

-> Audio and video start at the same time (I expected that the video would start before the audio)

=> How to handle negative audio delays with ffmpeg and an avi container?

Also all of these calls give me:

[avi @ 000001f1b4b8e280] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly[/quote]

=> How to do it properly to avoid this warning and be save for the future?

Thanks!

comment:11 by Gyan, 5 years ago

For MP4s, ffmpeg's muxer writes an edit list for delaying a stream. Players which honor it, will play as expected e.g. Potplayer does, WMP does not.

Note: See TracTickets for help on using tickets.