1
votes

How does recording a 1080P, H264 encoded video in android camera application is realtime fast but encoding a video in android using FFMPEG is slow at the same video size?

I know FFMPEG is a software level encoder and it wont support any hardware features.

I know camera applications directly get buffer data from camera driver.

But actually where the difference happens??

Why camera application is Realtime fast???

Does it use GPU and OpenGL features of the phone to encode the video so that its so realtime fast??

Because both Camera Application and FFMPEG runs on same mobile but still camera encodes H264 realtime ???

4

4 Answers

2
votes

I know FFMPEG is a software level encoder and it wont support any hardware features.

You have basically answered this question for yourself. Many devices have hardware codecs that don't rely on the usual CPU instructions for any encoding. FFmpeg won't take advantage of these. (I believe there are hardware optimizations you can build into FFmpeg, though I am not sure of their availability on Android.)

1
votes

FFMPEG does support NEON optimisations by default on ARM platforms hence differences are not likely visible at resolutions like QVGA or VGA. But on-chip HW for encoding video is much faster at higher resolutions like 1080P, minimally utilising ARM MHz. Note that encoders use different HW than the OpenGL HW engines.

1
votes

ffmpeg may use optional x264 encoder if configured this way; note that this has dire licensing implications.x264 is very good and efficient, and when it is built to use sliced multithreading, it can achieve 25FPS for WVGA video on modern devices, like Samsung S4.

ffmpeg can be compiled with libstagefrihht which makes use of the built-in hardware decoder, but unfortunately does not include an encoder.

0
votes

I also met this problem,Bothering me for a long time.I solved the problem through this:

AVDictionary *param = 0;
//H.264
if (pCodecCtx->codec_id == AV_CODEC_ID_H264) {
//        av_dict_set(&param, "preset", "slow", 0);
    /**
    * 
    * ultrafast,superfast, veryfast, faster, fast, medium
    * slow, slower, veryslow, placebo. This is x264 encoding speed parameter
    */
    av_dict_set(&param, "preset", "superfast", 0);
    av_dict_set(&param, "tune", "zerolatency", 0);
}

if (avcodec_open2(pCodecCtx, pCodec, &param) < 0) {
    loge("Failed to open encoder!\n");
    return -1;
}

you need set preset superfast or ultrafast