i have cut two videos into multiple segments and i am trying to rearangle them randomly. The problem is that the audio wont sync properly... All the segments have the same frame rate, 30 fps, same resolution, same audio and video codec (AV_CODEC_ID_AAC, AV_CODEC_ID_H264) and same bitrate.
FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(outputFilePath, 1920, 1080);
recorder.setFrameRate(30);
recorder.setFormat("mp4");
recorder.setAudioChannels(2);
recorder.setSampleRate(44100);
recorder.setAudioCodec(avcodec.AV_CODEC_ID_AAC);
recorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);
recorder.setVideoBitrate(10_000_000);
recorder.start();
Frame videoFrame;
for (FFmpegFrameGrabber videoGrabber : videoGrabbers) {
videoGrabber.start();
while ((videoFrame = videoGrabber.grabFrame(true, true, true, false)) != null) {
recorder.record(videoFrame);
}
}
recorder.stop();
recorder.release();
if i enable grabFrame boolean doAudio to true, the video would be 43s, if i disable the audio it would be 34s. Also at the end the video ends at 34s and the audio continues until it finishes.
Any way i can sync this so the audio matches the video perfectly??