首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何提高mp4的性能?

如何提高mp4的性能?
EN

Stack Overflow用户
提问于 2013-01-02 06:35:17
回答 1查看 1.3K关注 0票数 0

我检测到mp4格式的avcodec_decode_audio3函数运行缓慢,下面是我解码音频的代码周期:

代码语言:javascript
复制
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);

    }

但对于其他格式,如flac和mp3,它工作得很好。avcodec_decode_audio3out_size = 4608的mp3帧的解码大约需要1-2毫秒,而在mp4解码相同帧大小的情况下,大约需要6-7毫秒。我从here得到了我的构建脚本。

这是正常行为吗?有什么方法可以提高mp4解码的性能吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-01-04 11:55:38

你可以搜索硬件加速...

“Android上的硬件加速H.264解码”

例如:

How to use hardware accelerated video decoding on Android?

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

IMO - ffmpeg仍然主要是在软件上,但在较新版本的android上,你也许能够找到一些stagefright API提供的GPU加速方式来访问帧缓冲区??

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14114864

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档