(四) FFmpeg软硬解码和多线程解码(C++ NDK)

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
  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值