transitive-bullshit / ffmpeg-concat

Concats a list of videos together using ffmpeg with sexy OpenGL transitions.
865 stars 113 forks source link

Match audio and video duration before ffmpeg-concat #93

Open tjkcc opened 3 years ago

tjkcc commented 3 years ago

Thanks for this neat tool! Using it to merge multiple UGC videos with audio together (what a surprise!) but ran into audio sync issue with longer output videos. I've already found here that the duration of video and audio should be same, but I have no idea how to do it prior to ffmpeg-concat. Please help.

tjkcc commented 3 years ago

Figured an interesting thing.. when I make transition duration 1000, there is less audio sync issue. With 200 it gets worse and with 0 (you need to run it with 0, otherwise, it's 500 by default) it becomes a complete mess.

transitive-bullshit commented 3 years ago

My guess is this also has to do with different videos having different frame rates. When the output video is merged to only have a single frame rate, then the previous audio won't sync up.

tjkcc commented 3 years ago

I've checked that everything matches prior to concat. The resolution, rates, audio codec sample rate etc: https://imgur.com/a/82VVEuM

Mono sound in some of the clips can't be an issue?

I ran out of ideas 🤦‍♂️

transitive-bullshit commented 3 years ago

If they're not private, can you post the files online and the exact command or script you're running so we can try to reproduce the issue?

tjkcc commented 3 years ago

I've also tried padding audio in segments prior to ffmpeg-concat, but it didn't seem to help. The only thing I know for sure is that audio tracks in some of my videos are longer than video tracks and in some, they are shorter than video track. That's why I started digging this way.

tjkcc commented 3 years ago

Here they are: http://rk2k.com/files/ffmpeg-concat_vids.zip And this is what I am running: ffmpeg-concat -d 200 -t fade -c 4 -C -o ffmpeg-concat200.mp4 v0.mp4 v1.mp4 v2.mp4 v3.mp4 v4.mp4 v5.mp4 v6.mp4 v7.mp4 v8.mp4 v9.mp4 v10.mp4 v11.mp4 v12.mp4 v13.mp4 The issue is best seen after 2nd minute of a compiled video.

Just tried the basic concat without anything and it works well.. but no transitions, of course. ffmpeg -f concat -i ffmpeg-sound.txt -c copy final_output.mp4

ghost commented 3 years ago

My guess is this also has to do with different videos having different frame rates. When the output video is merged to only have a single frame rate, then the previous audio won't sync up.

@transitive-bullshit, I do think that fps is the culprit, I'm also facing this issue where audio isn't synced up to the video and also #98 where the video of different frame rate comes out all weird in the concatenated output. Also i have noticed that if any one of input videos doesn't have an audio, the output video for the entire duration doesn't have any audio.

tjkcc commented 3 years ago

In my case, all videos are 100% the same in terms of fps, codecs, resolution and such. The only problem I see is the difference between video and audio track length. I experimented with trimming that to same length and then used the new xfade filter to concat. And it works.

9xcoder commented 2 years ago

same here