1
votes

I am trying to cut a video in 2 parts then reassembling with ffmpeg but the final output has a small audio glitch right where the segments meet. I am using the following command to split the video 1.mp4 in 2 parts:

ffmpeg -i 1.mp4 -ss 00:00:00 -t 00:00:02 -async 1 1-1.mp4

and

ffmpeg -i 1.mp4 -ss 00:00:02 -t 00:00:02 -async 1 1-2.mp4

Once I have the 2 parts I am concatening them back together with:

ffmpeg -f concat -i files.txt -c copy output.mp4

files.txt is correctly listing both files. Can anyone point me to where the problem might be?

Thanks

2

2 Answers

2
votes

The glitch is likely due to the audio priming sample showing up in between.

Since you're re-encoding the segments, you can do this in one command:

ffmpeg -i 1.mp4 -filter_complex 
                "[0]trim=duration=2[v1];[0]trim=2:4,setpts=PTS-STARTPTS[v2];
                 [0]atrim=duration=2[a1];[0]atrim=2:4,asetpts=PTS-STARTPTS[a2];
                 [v1][a1][v2][a2]concat=n=2:v=1:a=1[v][a]"
       -map "[v]" -map "[a]" output.mp4
-1
votes

I had the same problem for about 3 weeks. just merge the mp3 files using sox

sox in1.mp3 in2.mp3 in3.mp3 out.mp3

When I used concat with FFMPEG it made 12.5ms (I saw them on using Audacity) audio gaps. (I don't know why)

Maybe for your case it'll be better to extract the audio and video to two separate files using ffmpeg, merge them (video using FFMPEG and audio using sox) then put the files together into one container (mp4) file