两组对比:同样分辨率的文件,通过所消耗的时长判断
1:YUV to RGB
2:YUV 尺寸缩放
结果:(文件有84帧图像) 则每帧耗时如下
libyuv_I420_to_Rgb 623066
ffmpeg_I420_to_Rgb 1815963
libyuv_swscale 996027
ffmpeg_swscale 1387750
可以看出libyuv要更好一点,yuv_to_rgb转换时大概为3倍, 缩放大概为一倍多
#include <stdio.h>
#include <windows.h>
extern "C"
{
#include "libswscale/swscale.h"
#include "libavutil/opt.h"
#include "libavutil/imgutils.h"
};
#include "libyuv.h"
static inline uint64_t get_clockfreq(void)
{
static LARGE_INTEGER clock_freq;
QueryPerformanceFrequency(&clock_freq);
return clock_freq.QuadPart;
}
uint64_t os_gettime_ns(void)
{
LARGE_INTEGER current_time;
double time_val;
QueryPerformanceCounter(¤t_time);
time_val = (double)current_time.QuadPart;
time_val *= 1000000000.0;
time_val /= (double)get_clockfreq();
return (uint64_t)time_val;
}
int libyuv_I420_to_Rgb()
{
const int width = 1280, height = 720;
FILE *src_file = fopen("1280x720.yuv", "rb");
FILE *dst_file = fopen("1280x720.rgb", "wb");
int size_src = width * height * 3 / 2;
int size_dest = width * height * 4;
char *buffer_src = (char *)malloc(size_src);
char *buffer_dest = (char *)malloc(size_dest);
uint64_t start_time = os_gettime_ns();
while (1){
if (fread(buffer_src, 1, size_src, src_file) != size_src){
//fseek(src_file, 0, 0);
//fread(buffer_src, 1, size_src, src_file);