I wonder how can I set the frame rate for FFmpegFrameRecorder when merging images and audio file.

226 views
Skip to first unread message

KH. Moon

unread,
Sep 16, 2013, 3:22:44 PM9/16/13
to jav...@googlegroups.com
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 _______________________________________________

private double fps = 40;


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.




Samuel Audet

unread,
Sep 17, 2013, 7:18:10 AM9/17/13
to jav...@googlegroups.com
Hello,

On 09/17/2013 04:22 AM, KH. Moon wrote:
> 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.

This probably means that the audio is longer than the video, no?

Are you sure the original audio file and the video file have the exact
same length?

And you should probably set the audio properties of the recorder to make
sure they are correct.

Samuel
Reply all
Reply to author
Forward
0 new messages