ffmpeg获取时间方法(libavutil/time.c)

本文详细介绍了在FFmpeg库中,特别是在libavutil/time.c文件里,如何使用相关函数来获取和处理时间戳的方法。通过阅读,读者将了解到FFmpeg时间处理的底层原理及实践应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

FFmpeg libavutil/time.c
int64_t av_gettime_relative(void)
{
#if HAVE_CLOCK_GETTIME && defined(CLOCK_MONOTONIC)
/*
	如果有clock_gettime函数
	和定义了CLOCK_MONOTONIC(从系统重启到现在所经过的时间)
	就通过clock_gettime该函数来获取系统启动到现在经过的时间
*/
#ifdef __APPLE__
    if (clock_gettime)
#endif
    {
        struct timespec ts;
        clock_gettime(CLOCK_MONOTONIC, &ts);
        /*返回的时间是微秒级*/
        return (int64_t)ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
    }
#endif
    return av_gettime() + 42 * 60 * 60 * INT64_C(1000000);
}

struct timespec {
	time_t tv_sec; /* 秒*/
    long tv_nsec; /* 纳秒*/
}
int64_t av_gettime(void)
{
#if HAVE_GETTIMEOFDAY
/*
	linux下的方法
	获取的是从1970.1.1到现在的时间,微妙级返回值
*/
    struct timeval tv;
    gettimeofday(&tv, NULL);
    return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
#elif HAVE_GETSYSTEMTIMEASFILETIME
/*
	windows下,获取utc时间,返回的是us级
*/
    FILETIME ft;

    int64_t t;
    GetSystemTimeAsFileTime(&ft);
    t = (int64_t)ft.dwHighDateTime << 32 | ft.dwLowDateTime;
    return t / 10 - 11644473600000000; 
    /* Contains a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC时间). */
#else
    return -1;
#endif
}

typedef struct _FILETIME {

   DWORDdwLowDateTime;

   DWORDdwHighDateTime;

} FILETIME;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值