Android FFmpeg 视频信息获取及压缩

来源:互联网 发布:教散打的软件 编辑:程序博客网 时间:2024/06/11 04:32


FFmpeg移植到Android:


http://blog.csdn.net/leixiaohua1020/article/details/47056365


获取视频信息:

// java string -> c char* (JNI)
const char* filePath = (*env)->GetStringUTFChars(env,jFilePath,JNI_FALSE);

int angle = -1;
//1.注册所有组件
av_register_all();
//封装格式上下文
AVFormatContext *pFormatCtx = avformat_alloc_context();
    //2.打开输入视频文件
if(avformat_open_input(&pFormatCtx, filePath, NULL,NULL) != 0){
LOGE("%s","无法打开输入视频文件");
return -1;
}
//3.获取视频文件信息
if(avformat_find_stream_info(pFormatCtx, NULL) < 0){
LOGE("%s","无法获取视频信息");
return -1;
}
//获取视频流的索引位置
int v_stream_idx = -1;
int i = 0;
for(i = 0; i < pFormatCtx->nb_streams; i++){
if(pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO){
v_stream_idx = i;
break;
}
}
//获取视频方向数据
AVDictionaryEntry *tag = NULL;
tag = av_dict_get(pFormatCtx->streams[v_stream_idx]->metadata, "rotate", tag, 0);
if(tag != NULL){
angle = atoi(tag->value);
LOGE("%d", angle);
}


//分辨率
LOGE("%d", pFormatCtx->streams[v_stream_idx]->codecpar->width);
LOGE("%d", pFormatCtx->streams[v_stream_idx]->codecpar->height);



avformat_free_context(pFormatCtx);


其他信息看C源码,都有解释.


视频压缩本质是视频转码,将视频码率,帧速,分辨率等降低 视频体积自然下降

使用方法见:http://blog.csdn.net/leixiaohua1020/article/details/47056365


自己调试的结果,满足清晰度效率上最高的执行语句:

ffmpeg -y -i %s  -r 10 -b:v 1280k %s


(降低分辨率会显著增加执行时间)

0 0
原创粉丝点击