I am trying to combine an audio and video file. The length of the audio and video file is the same, but after the complete process of merging into the audio output video file, played only 3-4 seconds, and the length of the audio and video file - 14 seconds. Please help me why the sound does not play fully in the output file.
String OutputPath = path + outputVideo; try { FrameGrabber grabber1 = new FFmpegFrameGrabber(videoFile); FrameGrabber grabber2 = new FFmpegFrameGrabber(audioFile); grabber1.start(); grabber2.start(); FrameRecorder recorder = new FFmpegFrameRecorder(OutputPath, grabber1.getImageWidth(), grabber1.getImageHeight(),2); recorder.setFormat(grabber1.getFormat()); recorder.setVideoQuality(1); recorder.setFrameRate(grabber1.getFrameRate()); recorder.setSampleRate(grabber2.getSampleRate()); recorder.start(); Frame frame1, frame2; while ((frame1 = grabber1.grabFrame()) != null && (frame2 = grabber2.grabFrame()) != null) { recorder.record(frame1); recorder.record(frame2); } recorder.stop(); grabber1.stop(); grabber2.stop(); } catch (FrameGrabber.Exception e) { e.printStackTrace(); } catch (FrameRecorder.Exception e) { e.printStackTrace(); }
source share