您当前的位置: 首页 > 学无止境 > 心得笔记 网站首页心得笔记
4. AVFormatContext结构分析和清理代码示例~1
发布时间:2021-05-30 16:12:15编辑:雪饮阅读()
接著上文,在上文中我們以64位cpu架構給咱們的安卓項目增加了對應動態鏈接庫的支持,並成功的以一個打開視頻文件的實例。
那麽本文简单分析FFmpeg的avformat_close_input()函数。该函数用于关闭一个AVFormatContext,一般情况下是和avformat_open_input()成对使用的。
則對於cpp/native-lib.cpp有:
#include <jni.h>
#include <string>
#include <android/log.h>
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN,"testff",__VA_ARGS__)
extern "C"{
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
}
extern "C" JNIEXPORT jstring JNICALL
Java_com_example_ndk_1and_141_MainActivity_stringFromJNI(JNIEnv* env,jobject) {
std::string hello = "Hello from C++";
hello+=avcodec_configuration();
//初始化解封裝
av_register_all();
//初始化網絡
avformat_network_init();
AVFormatContext *ic=NULL;
char path[]="/sdcard/1080.mp4";
int re=avformat_open_input(&ic,path,0,0);
if(re==0){
LOGW("avformat_open_input %s success!");
avformat_close_input(&ic);
}
else{
LOGW("avformat_open_input failed!:%s",av_err2str(re));
}
return env->NewStringUTF(hello.c_str());
}
#include <string>
#include <android/log.h>
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN,"testff",__VA_ARGS__)
extern "C"{
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
}
extern "C" JNIEXPORT jstring JNICALL
Java_com_example_ndk_1and_141_MainActivity_stringFromJNI(JNIEnv* env,jobject) {
std::string hello = "Hello from C++";
hello+=avcodec_configuration();
//初始化解封裝
av_register_all();
//初始化網絡
avformat_network_init();
AVFormatContext *ic=NULL;
char path[]="/sdcard/1080.mp4";
int re=avformat_open_input(&ic,path,0,0);
if(re==0){
LOGW("avformat_open_input %s success!");
avformat_close_input(&ic);
}
else{
LOGW("avformat_open_input failed!:%s",av_err2str(re));
}
return env->NewStringUTF(hello.c_str());
}
那麽我們再次重新編譯運行,可以看到還是沒有問題的
关键字词:AVFormatContext,清理代碼
相关文章
-
无相关信息