Android how to increase ffmpeg mp4 perfromance?

99封情书 提交于 2019-12-08 11:21:10

问题


I have detected that function avcodec_decode_audio3 works slow with mp4 format, here my code cycle for decoding audio:

while (av_read_frame(av_format_context, &packet) >= 0 && is_play == 1) {
        if (av_codec_context->codec_type == AVMEDIA_TYPE_AUDIO
                && is_play == 1) {
            int out_size = AVCODEC_MAX_AUDIO_FRAME_SIZE;
            int size = packet.size;
            int n;
            int dataLength = size;
            int decoded = 0;
            while (size > 0) {

                //start measure time
                gettimeofday(&tvBegin, NULL);

                int len = avcodec_decode_audio3(av_codec_context,
                        (int16_t *) pAudioBuffer, &out_size, &packet);

                //stop measure time
                gettimeofday(&tvEnd, NULL);
                timeval_subtract(&tvDiff, &tvEnd, &tvBegin);

                LOGI("%d", tvDiff.tv_usec / 1000);
                LOGI("len='%d'", len);
                LOGI("out_size='%d'", out_size);

                if (len < 0) {
                    break;
                    return 1;
                }
                if (out_size > 0) {



                    jbyte *bytes = (*env)->GetByteArrayElements(env, array,
                            NULL);
                    memcpy(bytes, (int16_t *) pAudioBuffer, out_size);
                    (*env)->ReleaseByteArrayElements(env, array, bytes, 0);
                    (*env)->CallVoidMethod(env, obj, play, array, out_size,
                            is_play);

                }
                size -= len;
            }

        }
        if (packet.data)
            av_free_packet(&packet);

    }

But with other formats like flac and mp3 it works fine. avcodec_decode_audio3 take about 1-2 milisecounds for decoding mp3 frame with out_size = 4608 but with the same frame size in mp4 decoding take about 6-7 millisecounds. I got my build script from here.

Does it normal behavior? Is any way to increase performance of decoding mp4?


回答1:


u could search on hardware acceleration...

"H/W Accelerated H.264 Decoding on Android"

for example:

How to use hardware accelerated video decoding on Android?

http://readlist.com/lists/mplayerhq.hu/mplayer-users/5/26751.html

IMO - ffmpeg is still mostly in software but on the newer versions of android, you may be able to find some stagefright API's providing GPU accelerated way to access the framebuffer??



来源:https://stackoverflow.com/questions/14114864/android-how-to-increase-ffmpeg-mp4-perfromance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!