Add mediacodec to decode h264

dev
xufuji456 3 years ago
parent 1fb74254b0
commit 6e52fc3832
  1. 2
      app/src/main/cpp/media_player.cpp
  2. 13
      app/src/main/cpp/video_filter.c

@ -19,6 +19,7 @@ extern "C" {
#include "libswresample/swresample.h"
#include "packet_queue.h"
#include "ffmpeg_jni_define.h"
#include "include/libavcodec/jni.h"
#ifdef __cplusplus
}
#endif
@ -75,6 +76,7 @@ MediaPlayer* player;
jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved){
javaVM = vm;
av_jni_set_java_vm(vm, nullptr);// set JavaVM into FFmpeg
return JNI_VERSION_1_6;
}

@ -17,6 +17,7 @@
#include "ffmpeg_jni_define.h"
#define TAG "VideoFilter"
#define ENABLE_MEDIACODEC 1
AVFormatContext *pFormatCtx;
AVCodecContext *pCodecCtx;
@ -150,7 +151,17 @@ int open_input(JNIEnv *env, const char *file_name, jobject surface) {
}
pCodecCtx = pFormatCtx->streams[video_stream_index]->codec;
AVCodec *pCodec = avcodec_find_decoder(pCodecCtx->codec_id);
AVCodec *pCodec;
if (ENABLE_MEDIACODEC && pCodecCtx->codec_id == AV_CODEC_ID_H264) {
// note: Some devices will bring blurred screen, when using mediacodec
pCodec = avcodec_find_decoder_by_name("h264_mediacodec");
if (pCodec == NULL) {
pCodec = avcodec_find_decoder(pCodecCtx->codec_id);
}
LOGE(TAG, "codec name=%s", pCodec->name);
} else {
pCodec = avcodec_find_decoder(pCodecCtx->codec_id);
}
if (pCodec == NULL) {
LOGE(TAG, "couldn't find Codec.");
return -1;

Loading…
Cancel
Save