2

i am having issue, to concat video, it looses the audio sync and audio started from previous video.

i have tried below two link/so answer by Mulvya, but none of them work :(

here is the code i am trying:

1: re-encode file a (1):

ffmpeg.exe -i "f:\1.avi" -af apad -vf scale=1280:720 -crf 15.0 -vcodec libx264 -acodec aac -ar 48000 -b:a 192k -coder 1 -rc_lookahead 60 -threads 0 -shortest -avoid_negative_ts make_zero -fflags +genpts 01.mp4

2: re-encode file b (2):

ffmpeg.exe -i "f:\2.mp4" -af apad -vf scale=1280:720 -crf 15.0 -vcodec libx264 -acodec aac -ar 48000 -b:a 192k -coder 1 -rc_lookahead 60 -threads 0 -shortest -avoid_negative_ts make_zero -fflags +genpts 02.mp4

3: Now contact using following command:

ffmpeg.exe -f concat -safe 0 -i "f:\files.txt" -c copy test.mp4

but audio is not synced with video ;(

i also uploaded both video (and also the output) on dropbox:

Video Sync Issue Source And Result Files

so, any help, how to make audio perfectly sync with video would be great :)

Fabián
  • 565
  • 1
  • 7
  • 30
Zakir_SZH
  • 466
  • 7
  • 21
  • Since you're not trimming the input files, simply perform the encoding in the concat step. So, files.txt should refer to 1.avi and 2.mp4 and instead of copy, use crf 15..etc in the concat step. – Gyan Nov 30 '16 at 04:31
  • @Mulvya, hi thanks, i did even tried that, but that didn't work. However, thanks a lot for your reply. Some one else on another forum helped me out :) – Zakir_SZH Nov 30 '16 at 07:33
  • Yes, that's required for the concat demuxer, – Gyan Nov 30 '16 at 07:44

2 Answers2

2

Some one else on another forum helped me to find the issue. So, i post it as answer here so that someone else may can get help.

I was concerned about same frame size, audio and video codec to concat properly, but i forgot about frame rate.

That first sample video (mentioned in my question) frame rate was 12, while 2nd video frame rate was 25; and that's what make the sync problem.

Now, i have set frame rate 25 to those two video (-r 25) and it's works like charms :)

below is the full conversion code:

ffmpeg.exe -i "f:\1.avi" -r 25 -af apad -vf scale=1280:720 -crf 15.0 -vcodec libx264 -acodec aac -ar 48000 -b:a 192k -coder 1 -rc_lookahead 60 -threads 0 -shortest -avoid_negative_ts make_zero -fflags +genpts 01.mp4

hope it may help some one like me in near future.

best regards

Zakir_SZH
  • 466
  • 7
  • 21
  • This is the only accurate solution I found here till now, but this is creating large output files, have you solved it also? – Rohit Dhiman Jul 31 '19 at 15:29
  • @RohitDhiman, thanks for the feedback.. really appreciate it.. :) – Zakir_SZH Aug 01 '19 at 16:22
  • The crucial part is -vf scale=1280:720 -crf 15.0 because it creates a large image size of 1280x720 pixels, and uses a high bitrate (crf 15). If you encode to a smaller image size of say 640x480 pixels and use a low bitrate of CRF 21 you will end up with a much smaller filesize in your video output file. – Ed999 Apr 11 '20 at 20:56
0

some other solution for syncing audio & video

use -bsf:v h264_mp4toannexb in your input files

ffmpeg.exe -i "1.avi" -af apad -vf scale=1280:720 -crf 15.0 -vcodec libx264 -acodec aac -bsf:v h264_mp4toannexb -ar 48000 -b:a 192k -coder 1 -rc_lookahead 60 -threads 0 -shortest -avoid_negative_ts make_zero -fflags +genpts output1.flv

and same for 2nd file

ffmpeg.exe -i "2.avi" -af apad -vf scale=1280:720 -crf 15.0 -vcodec libx264 -acodec aac -bsf:v h264_mp4toannexb -ar 48000 -b:a 192k -coder 1 -rc_lookahead 60 -threads 0 -shortest -avoid_negative_ts make_zero -fflags +genpts output2.flv

then files can be joined together

ffmpeg -f concat -safe 0 -i concat.txt -c copy -bsf:a aac_adtstoasc final.flv

where concat.txt file contains

file 'output1.flv'
file 'output2.flv'
Mas
  • 1,267
  • 1
  • 14
  • 13