0

Hey guys I've been trying to make this work for a while now and I can't seem to find how to make the audio/video synced after the concatenation, I've searched and tested some solutions but couldn't get it working.

Here is what I do right now, Everything is working but I must be doing something wrong.

So First, I split the videos into the video that I want

System.Diagnostics.Process.Start(ffmpegPath, "-i " + 
video.Path + " -ss " + StartTime + " -t " + Duration + " " + video.Output);

After "cutting/splitting" the videos that I want like I want, I tried concatenating the videos together ( using -safe 0 to use the absolute path, else it wasn't working ) :

System.Diagnostics.Process.Start(ffmpegPath, 
"-f concat -safe 0 -i " + txtFile + " C:\\Downloads\\Build\\" + rdn.Next(0,1000) + ".mp4");

After that , I've noticed the audio/video was sometime out of sync so I searched and found this

so I decided to Pad all the videos after splitting them :

System.Diagnostics.Process.Start(ffmpegPath, 
"-i " + video.Output + " -af apad -c:v libx264 -shortest -avoid_negative_ts make_zero -fflags +genpts -report " + padding);

and then building it again, but it ended up having the same audio desync.

It's my first time working with mp4s and with FFMPEG and I'm sure I'm missing something.

Community
  • 1
  • 1
iamanoob
  • 208
  • 3
  • 13

1 Answers1

0

I feel bad since I seem to have found the answer ( not 100% sure, will have to do some more testing, but I tested a few times and it seems to work so far ) right after making this post, I found a post that was so well hidden that.. I don't even know how I found it, but I did and I'm glad I did.

His answer is here

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

Community
  • 1
  • 1
iamanoob
  • 208
  • 3
  • 13