Closed lbz303 closed 3 months ago
We can easily accomplish this with the ffmpeg program: http://bytedeco.org/javacpp-presets/ffmpeg/apidocs/org/bytedeco/ffmpeg/ffmpeg.html
I am currently using the following method to merge two videos. The first video has normal audio and video, but the second video only has audio, with the screen being black. The duration and resolution of both videos are correct. Could you please explain the potential cause of this issue?
ProcessBuilder pb = new ProcessBuilder(
ffmpeg, "-f", "concat", "-safe", "0", "-i", FILE_PATH,
"-vf", "scale=" + width + ":" + height, "-r", String.valueOf(maxFrameRate),
"-b:v", String.valueOf(bitrate),
"-c:v", "h264", "-c:a", "aac", "-strict", "experimental", mergedVideoPath);
I've resolved my issue, thank you for your assistance
My video merging code, when merging multiple videos with different bitrates and resolutions, results in the merged video's duration and audio not matching correctly.
The duration of the merged video exceeds the total duration of all the original videos. The audio does not correspond correctly with the video. The temporary files generated before merging are stored locally and appear to be normal, but the final merged video has issues.
`List videoList = Files.readAllLines(Paths.get(tempFileList));
String replaced = videoList.get(0).replace("file '", "").replace("'", "");
FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(replaced);
grabber.start();
FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(mergedVideoPath, width, height);
recorder.setVideoCodec(AV_CODEC_ID_H264);
recorder.setAudioChannels(1);
recorder.setInterleaved(true);
recorder.setFormat("mp4");
recorder.setFrameRate(maxFrameRate);
recorder.setVideoBitrate(16 1000 1000); // 16 Mbps
Could you also provide an example code for merging videos with different resolutions, bitrates, and audio settings into a single unified format?