Hello, I'm trying to make a video file with FFMPEG on android device.
First of all, I'm not good at english.
If you can't understand what I wrote, please let me know via reply.
Please see codes below.
_______________________________ codes _______________________________________________
recorder = new FFmpegFrameRecorder(GlobalEnv.getOutputPath() + "/"
+ System.currentTimeMillis() + ".mp4", screenWidth,
screenHeight, 2);
recorder.setFormat("mp4");
recorder.setFrameRate(fps);
recorder.setVideoBitrate(2000000);
recorder.setAudioCodec(AV_CODEC_ID_AAC);
recorder.setVideoCodec(AV_CODEC_ID_MPEG4);
recorder.setPixelFormat(AV_PIX_FMT_YUV420P);
recorder.start();
int currentFrame = 0;
while(currentFrame <= (fps * 120)){
recorder.record(image);
currentFrame++;
}
FFmpegFrameGrabber audioGrabber = new FFmpegFrameGrabber(musicFilePath);
audioGrabber.start();
Frame audioFrame = null;
currentFrame = 0;
while ((audioFrame = audioGrabber.grabFrame()) != null && currentFrame <= (fps * 120)) {
audioFrame.image = null;
recorder.record(audioFrame);
currentFrame++;
}
audioGrabber.stop();
audioGrabber.release();
____________________________________________________________________________________
I adjusted frame rate of recorder as 40, and record images 4800 times.
when I didn't record audioFrame, result video's duration is 2minutes.
but when I did, duration is 2minutes and 5 seconds.
I tried another cases, but I couldn't find correct value of frame rate.
Please refer below test cases.
test case 1 : frame rate 40, recording time 1200, video duration 31 seconds. (should be 30 seconds)
test case 2 : frame rate 40, recording time 2400, video duration 62 seconds. (should be 60 seconds)
test case 3 : frame rate 40, recording time 4800, video duration 125 seconds. (should be 120 seconds)
test case 4 : frame rate 38.6235294118, recording time 1200, video duration 30 seconds. test case 5 : frame rate 38.6235294118, recording time 2400, video duration 60 seconds. test case 6 : frame rate 38.6235294118, recording time 4800, video duration 120 seconds.
I finally found familiar value, but I can't use this.
Please help me to know the way to solve this problem.