【问题标题】:Android how to increase ffmpeg mp4 perfromance?Android如何提高ffmpeg mp4性能?
【发布时间】:2012-12-16 09:30:14
【问题描述】:

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

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_audio3 解码 mp3 帧大约需要 1-2 毫秒,out_size = 4608 但在 mp4 解码中使用相同的帧大小大约需要 6-7 毫秒。我从here 获得了我的构建脚本。

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

【问题讨论】:

  • 它是一个更复杂的编解码器,所以当我得知解码需要更多处理时间时我不会感到震惊。
  • hi.. ffmpeg android 可以在 android 中使用 cygwin 编译吗?我试过了,但无法编译生成.so文件。

标签: android c android-ndk ffmpeg decoding


【解决方案1】:

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

“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 上,您可能能够找到一些提供 GPU 加速方式来访问帧缓冲区的 stagefright API??

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-14
    • 2017-04-05
    相关资源
    最近更新 更多