dts(Decoding Time Stamp):即解码时间戳,这个时间戳的意义在于告诉播放器该在什么时候解码这一帧的数据。
pts(Presentation Time Stamp):即显示时间戳,这个时间戳用来告诉播放器该在什么时候显示这一帧的数据。
AVFrame的linesize成员:
###代码
#include “common.hpp”
#ifdef __cplusplus // ffmpeg是基于c语言开发的库,所有头文件引入的时候需要 extern "C"
extern "C" {
#endif
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libavcodec/jni.h"
JNIEXPORT jint JNI_OnLoad(JavaVM * vm, void * res) // jni 初始化时会调用此函数
{
// ffmpeg要使用硬解码,需要将java虚拟机环境传给ffmpeg,ffmpeg中通过vm来调用android中mediacodec硬解码的java接口 , 第二个函数为日志,不需要,传0
av_jni_set_java_vm(vm, 0);
return JNI_VERSION_1_4; // 选用jni 1.4 版本
}
#ifdef __cplusplus
}
#endif
// 当前时间戳
static long long getNowMs()
{
/*
struct timeval tv1,tv2;
unsigned long long timeconsumed = 0;
// 获取当前时间:
gettimeofday(&tv1,NULL);
...
gettimeofday(&tv2,NULL);
// 时间统计:
timeconsumed = tv2.tv_sec-tv1.tv_sec +(tv2.tv_usev-tv1.tv_usec)/1000000; // 以秒为单位
*/
struct timeval tv; // timeval结构体的两个成员为 秒 与 微秒
gettimeofday(&tv, NULL); // 获取系统当前时间, 1970到系统时间的秒数? signed long值装不下
int sec = tv.tv_sec%360000; // 100个小时
long long time = sec*1000 + tv.tv_usec/1000; // 将 timeval 时间单位转换为 毫秒
return time;
}
JNIEXPORT void JNICALL Java_hankin_hjmedia_mpeg_Mp5_11Activity_decode(JNIEnv *env, jobject instance, jstring url_, jobject handle)
{
const char * path = env->GetStringUTFChars(url_, NULL); // jstring 2 char*
if (path[0]=='\0')
{
LOGE("path is empty.");
return;
}
av_register_all();
int netInit = avformat_network_init();
LOGD("netInit=%d", netInit);
avcodec_register_all(); // 在4.0 已过时,Register all the codecs, parsers and bitstream filters which were enabled at configuration time. 注释此代码无影响
AVFormatContext * ic = NULL;
int openRet