本文参考:https://blog.csdn.net/JohanMan/article/details/83091706

#include #include #include #include // Android 打印 Log#define LOGE(FORMAT,...) __android_log_print(ANDROID_LOG_ERROR, "player", FORMAT, ##__VA_ARGS__);#ifdef __cplusplusextern "C" {#endif#include "libavformat/avformat.h"#include "libavcodec/avcodec.h"#include "libswscale/swscale.h"#include "libavutil/imgutils.h"    void Java_com_xupt_will_ffmpegtest_FFMPEGPlayer_play(JNIEnv *env,jobject thiz,jstring path_,jobject surface){        // 记录结果        int result;        // R1 Java String -> C String        const char *path = env->GetStringUTFChars(path_,0);        //注册FFMPEG组件        av_register_all();        // R2 初始化 AVFormatContext 上下文        AVFormatContext *formatContext = avformat_alloc_context();        // 打开视频文件        result = avformat_open_input(&formatContext,path,NULL,NULL);        // 如果视频打开错误,退出        if(result < 0){            LOGE("FFMPEG Player Error: Can not open video file");            return;        }        // 查看文件的视频流信息        result = avformat_find_stream_info(formatContext,NULL);        // 如果查看视频流信息失败,退出        if(result < 0){            LOGE("FFMPEG Play Error: Can not find video file stream info");            return;        }        // 查找视频编码器        int video_stream_index = -1;        for(int i = 0 ; i < formatContext->nb_streams ; i++){            if(formatContext->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO){                video_stream_index = i;                break;            }        }        // 如果没有找到视频流,退出        if(video_stream_index == -1){            LOGE("FFMPEG Play Error: Can not find video codec");            return;        }        //初始化视频编码器上下文        AVCodecContext *video_codec_context = avcodec_alloc_context3(NULL);        avcodec_parameters_to_context(video_codec_context, formatContext->streams[video_stream_index]->codec);        //初始化视频编码器    }#ifdef __cplusplus}#endif

更多相关文章

  1. android kernel 初始化 1
  2. android录制更大视频文件的修改
  3. Android使用VideoView全屏播放视频拉伸变形解决办法
  4. Android获取在线视频的缩略图方式对比
  5. Android中的多媒体编程-黄俊东-专题视频课程
  6. 传智播客Android视频教程——第六天

随机推荐

  1. Android(安卓)1.5 1.6 2.0 2.1 2.2 2.3 3
  2. 简单的 Android(安卓)拍照并显示以及获取
  3. Android: Android(安卓)Architecture
  4. Android(安卓)应用程序的结构
  5. 用一个二维码做下载地址,自动区分是 ios
  6. x264在android平台上的编译和使用
  7. 【移动开发】Android中各种xml汇总
  8. android mtk平台默认输入法
  9. Android(安卓)Studio初步使用及HelloWorl
  10. 2011.07.12(2)——— android Messenger 跨