4

I have very strange video file. It has audio/video synchronization problems. The video is going to fast, and audio is good. Video has strange frame rate: 26.07 fps.

How can I fix the video stream using ffmpeg. At the start of the video the sync is ok but at the end of the video stream there are about 5 min of audio left and it's playing with black screen.

This is the output from ffmpeg -i video.avi

ffmpeg version git-2011-10-15-1d0afec, Copyright (c) 2000-2011 the FFmpeg developers
  built on Oct 15 2011 14:27:57 with gcc 4.4.5
  configuration: --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libx264 --enable-nonfree --enable-postproc --enable-version3 --enable-x11grab --enable-libxvid
  libavutil    51. 21. 0 / 51. 21. 0
  libavcodec   53. 20. 1 / 53. 20. 1
  libavformat  53. 16. 0 / 53. 16. 0
  libavdevice  53.  4. 0 / 53.  4. 0
  libavfilter   2. 43. 6 /  2. 43. 6
  libswscale    2.  1. 0 /  2.  1. 0
  libpostproc  51.  2. 0 / 51.  2. 0
[mpeg4 @ 0xa585420] Invalid and inefficient vfw-avi packed B frames detected
Input #0, matroska,webm, from 'video.avi':
  Duration: 02:03:46.01, start: 0.000000, bitrate: 103 kb/s
    Stream #0:0: Video: mpeg4 (Advanced Simple Profile) (XVID / 0x44495658), yuv420p, 704x288 [SAR 1:1 DAR 22:9], 26.07 fps, 25 tbr, 1k tbn, 25 tbc (default)
    Stream #0:1(pol): Audio: ac3, 48000 Hz, 5.1(side), s16, 448 kb/s (default)
Marcin Kapusta
  • 5,076
  • 3
  • 38
  • 55

1 Answers1

6

First you might need to separate the audio:

 ffmpeg -i input.avi -vn -ac 2 -ar 48000 -ab 448k -f mp3 audio.mp3

Then you need to divide the whole length of the video file (in seconds) by the actual length of the video stream (the time when the video stops and you can just hear the audio). You should get a number a little above 1 (1.12 or something like that). You take this quotient and:

 ffmpeg -i input.avi -vf "setpts=quotient*PTS" -an output.avi

And then you combine the video and audio.

Daniel Rusev
  • 1,331
  • 2
  • 16
  • 35