Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ffmpeg stream offset command (-itsoffset) not working

Tags:

ffmpeg

sync

audio

I would really appreciate if someone could give some pointers regarding the use of itsoffset with ffmpeg. I have read a number of posts on this subject, some of them explain very clearly how to re-synchronize audio and video with -itsoffset, but I haven't been able to make it work. My avi file is encoded with ffmpeg, in two passes, using the following command for the second pass:

ffmpeg -i whole-vts_01.avs -pass 2 -y -vcodec libxvid -vtag XVID -b:v 1300K -g 240 -trellis 2 -mbd rd -flags +mv4+aic -acodec ac3 -ac 2 -ar 48000 -b:a 128k output.avi

For whatever reason, I end up with a 1 sec delay in the video (or the audio is 1 sec early). It doesn't happen too often but I see it from time to time. Among other attempts, I have tried the following:

(1) ffmpeg -i output.avi -itsoffset 00:00:01.0 -i output.avi -vcodec copy -acodec copy -map 0:0 -map 1:1 output-resynched.avi
(2) ffmpeg -i output.avi -itsoffset 00:00:01.0 -i output.ac3 -vcodec copy -acodec copy -map 0:0 -map 1:0 output-resynched2.avi
(3) ffmpeg -itsoffset -00:00:01.00 -i output.avi output-resynched8.avi
(4) ffmpeg -i output.avi -itsoffset -1.0 -i output.avi -vcodec copy -acodec copy -map 0:1 -map 1:0 output-resynched13.avi

Here are the results:

  1. Audio garbled and only 5m 35 s long vs. 1h 41m.
  2. (Output.ac3 is audio component of output.avi) Video and audio identical to original, offset didn't work
  3. Audio did get shifted, but original encoding parameters replaced with default ones (as expected).
  4. Audio garbled and only 9m 56s long vs. 1h 41m.

I see that many people explain, and apparently use the process described above, but it doesn't seem to be working for me. Am I missing something obvious? I would very much like to be able to use -itsoffset as it is cleaner than my workaround solution.

FWIW, here is a different, and longer way of obtaining the desired result:

First create a shifted video only file using -ss:

ffmpeg -i output.avi -ss 1.0 -vcodec copy -an oupput_videoshifted.avi

Then extract the audio:

ffmpeg -i output.avi -vn -acodec copy outputaudioonly.ac3

And finally remux both components:

ffmpeg -i output_videoshifted.avi -i output_audioonly.ac3 -vcodec copy -acodec copy -map 0:0 -map 1:0 output-resynched14.avi

The process works, is fast enough, but I would really prefer to use the one pass -itsoffset solution.

like image 292
jen Avatar asked Apr 12 '12 01:04

jen


1 Answers

Here is what I did and it work for me

The first input setting -i and the second input is come from the same one video file.

Delay 1 second in first input video and the second input audio just make a copy

ffmpeg -y -itsoffset 00:00:01.000 -i "d:\Video1.mp4" -i "d:\Video1.mp4"
 -map 0:v -map 1:a -vcodec copy -acodec copy
 -f mp4 -threads 2 -v warning "Video2.mp4"

Delay 1 second in second input audio and the first input video just make a copy

ffmpeg -y -i "d:\Video1.mp4" -itsoffset 00:00:01.000 -i "d:\Video1.mp4"
 -map 0:v -map 1:a -vcodec copy -acodec copy
 -f mp4 -threads 2 -v warning "Video2.mp4"
like image 135
johnrock Avatar answered Sep 23 '22 06:09

johnrock