Android FFMPEG音视频开发(四)
16lz
2021-01-23
本文参考: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
更多相关文章
- android kernel 初始化 1
- android录制更大视频文件的修改
- Android使用VideoView全屏播放视频拉伸变形解决办法
- Android获取在线视频的缩略图方式对比
- Android中的多媒体编程-黄俊东-专题视频课程
- 传智播客Android视频教程——第六天