Android FFMPEG音视频开发(四)

本文参考:https://blog.youkuaiyun.com/JohanMan/article/details/83091706

#include <jni.h>
#include <android/native_window.h>
#include <android/native_window_jni.h>
#include <android/log.h>

// Android 打印 Log
#define LOGE(FORMAT,...) __android_log_print(ANDROID_LOG_ERROR, "player", FORMAT, ##__VA_ARGS__);

#ifdef __cplusplus
extern "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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值