Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaCV is too slow on Android #55

Closed
shuky19 opened this issue Nov 20, 2014 · 1 comment
Closed

JavaCV is too slow on Android #55

shuky19 opened this issue Nov 20, 2014 · 1 comment

Comments

@shuky19
Copy link

shuky19 commented Nov 20, 2014

Hi Samuel,

As I said in my previous issues, I am trying to capture a video directly from the camera,
the only problem is it process the frames to slow, and cause a big frame loss (10 sec video can shrink into a 3-4 seconds video).

If I set the preset vaue to "ultrafast" everything goes smoothly, but the video quality is too low,
I am trying to understand how can I configure ffmpeg to work at the same quality of the native camera's API.

My configs are:
Video size: 720x1280
Codec: H264
FrameRate: 30
Bitrate: 2500000

I am using LG G2 with Android 4.2.2 (which can take even FHD video with the native camera's API), and its true for many other devices I tried.

Here is a sample of my code:

    opencv_core.IplImage mFrame = opencv_core.IplImage.create(videoProfile.width, videoProfile.height, opencv_core.IPL_DEPTH_8U, 2);
    FFmpegFrameRecorder  mFrameRecorder = new FFmpegFrameRecorder(filePath, videoProfile.width, videoProfile.height, 1);
    mFrameRecorder.setFormat(mp4 ? "mp4" : "flv");
    mFrameRecorder.setSampleRate(videoProfile.audioSampleRate);
    mFrameRecorder.setAudioCodec(avcodec.AV_CODEC_ID_AAC);
    mFrameRecorder.setFrameRate(videoProfile.frameRate);
    mFrameRecorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);
    mFrameRecorder.setVideoOption("preset", "ultrafast");
    mFrameRecorder.start();
    long mStartTime = System.currentTimeMillis();

And for each frame I receive from the camera:

    mFrame.getByteBuffer().put(frameBytes);
    long timestamp  = 1000 * (System.currentTimeMillis() - mStartTime);
    if (timestamp > mFrameRecorder.getTimestamp()) {
        mFrameRecorder.setTimestamp(timestamp);
    }

    mFrameRecorder.record(mFrame);

For each frame I get from the audio recorder:

    mFrameRecorder.record(ShortBuffer.wrap(frameBytes, 0, count));

thanks,
Shuky

@saudet
Copy link
Member

saudet commented Nov 24, 2014

If you need something faster than that, you're probably going to have to go with hardware acceleration. Unfortunately, AFAIK, FFmpeg doesn't support that on Android for encoding, so you'll need to either report that issue to the FFmpeg developers, or use the Android API that support hardware acceleration when available on recent devices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants