zeng_aven
阿里路啊
2018-12-07 07:16

ffmpeg解码MediaCodec的h264编码问题

5
  • mediacodec
  • h264
  • ffmpeg

安卓下用MediaCodec的h264编码:

boolean eof = false;
MediaCodec.BufferInfo bufferInfo = new MediaCodec.BufferInfo();
ByteBuffer[] outputBuffers = null;

boolean sendKeyFrame = false;

while (!eof) {

    int bufIndex = codec.dequeueOutputBuffer(bufferInfo, -1);


    eof = (bufferInfo.flags & MediaCodec.BUFFER_FLAG_END_OF_STREAM) != 0;

    try {
        if (bufIndex >= 0) {

            if (outputBuffers == null) {
                outputBuffers = codec.getOutputBuffers();
            }

            ByteBuffer codecBuffer = outputBuffers[bufIndex];

            codecBuffer.position(bufferInfo.offset);
            codecBuffer.limit(bufferInfo.offset + bufferInfo.size);

            byte[] buf = new byte[bufferInfo.size];
            codecBuffer.get(buf, 0, bufferInfo.size);
            Socket.sendVideo(buf); // 发送数据

        } else if (bufIndex == MediaCodec.INFO_OUTPUT_BUFFERS_CHANGED) {
            outputBuffers = null;
        } else if (bufIndex == MediaCodec.INFO_OUTPUT_FORMAT_CHANGED) {
            MediaFormat outputFormat = codec.getOutputFormat();
        }
    } finally {
        if (bufIndex >= 0) {
                      codec.releaseOutputBuffer(bufIndex, false);
        }
    }
}

PC下vc使用ffmpeg参考网上的解码h264流
https://blog.csdn.net/xushan239/article/details/79028111
https://www.cnblogs.com/lidabo/p/3326502.html
参考各种等等,
错误:
avcodec_decode_video2或者avcodec_send_packet返回AVERROR_INVALIDD(-1094995529)
要不就是在avformat_open_input里无限循环read_packet

问:
哪里出问题?
本人对ffmpeg、MediaCodec都不熟悉,谁能帮忙解决一下?

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答