Ffmpeg offset offset (-itsoffset) command not working

I would really appreciate it if someone could give some guidance regarding using itsoffset with ffmpeg. I read several posts on this subject, some of which very clearly explain how to re-sync audio and video with -tsoffset, but I couldn’t get it working. My avi file is encoded using 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 some reason, I end up with a 1 second delay in the video (or sound 1 second earlier). This does not happen too often, but I see it from time to time. Among other attempts, I 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:

  • The sound is distorted and only 5 m 35 with a length against 1x 41 m.
  • (Output.ac3 is the audio component of output.avi) Video and audio are identical to the original, the offset does not work.
  • The audio really moved, but the original encoding parameters were replaced with standard ones (as expected).
  • The sound is distorted and only 9 m 56 s versus 1 h 41 m.

I see that many people explain and apparently use the process described above, but it doesn't seem to work for me. Am I missing something? I would really like to use -tsoffset as it is cleaner than my solution to solve the problem.

FWIW, here is another and longer way to get the desired result:

First, create a file with the modified video using -ss only:

 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 fast enough, but I would prefer to use the one-pass solution -tsoffset.

+8
ffmpeg audio sync
source share
2 answers

Here is what I did and it works for me

The first input parameter is -i and the second input comes from one video file.

1 second delay in the first input video and second input audio just backup

 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" 

1 second delay in second audio input and first video input just backup

 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" 
+4
source share

The problem is on -vcodec copy -acodec copy , because the offset will only work on key frames. I had the same problem.

Just don't copy (audio / video), try the thing with -itsoffset , but use

 -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 

for re-encoding. It should work.

0
source share

All Articles