前提:编译出ffmpeg.so库文件,或者从某处得到可用so,可依照上一篇配置文件进行配置,裁剪编译。
1 软解码实现:
JNIEXPORT int JNICALL Java_h264_Native_PlayLocalVideo(JNIEnv *env, jobject obj,jstring inputFilePath_,jobject surface) {
const char *path = env->GetStringUTFChars(inputFilePath_, 0);
av_log_set_callback(ffmpeg_android_log_callback);
av_register_all();
int ret;
AVFormatContext *fmt_ctx = avformat_alloc_context();
if (avformat_open_input(&fmt_ctx, path, NULL, NULL) < 0) {
LOGD("can not open file");
return -1;
}
ANativeWindow *nativeWindow = ANativeWindow_fromSurface(env,surface);
if (nativeWindow == NULL) {
LOGD("ANativeWindow_fromSurface error");
return -3;
}
//绘制时候的缓冲区
ANativeWindow_Buffer outBuffer;
//获取视频流解码器
AVCodecContext *codec_ctx = avcodec_alloc_context3(NULL);
codec_ctx->width = 1280;
codec_ctx->height = 720;
codec_ctx->pix_fmt