计算两个YUV视频序列的PSNR
2017-06-29 15:17
483 查看
/** * Calculate PSNR between 2 YUV420P file * @param url1 Location of first Input YUV file. * @param url2 Location of another Input YUV file. * @param w Width of Input YUV file. * @param h Height of Input YUV file. * @param num Number of frames to process. */ #include<iostream> using namespace std; int simplest_yuv420_psnr(char *url1,char *url2,int w,int h,int num){ FILE *fp1=fopen(url1,"rb+"); FILE *fp2=fopen(url2,"rb+"); FILE *fp=fopen("Video_PSNR.txt","w"); //创建存取PSNR值信息的txt文件 unsigned char *pic1=(unsigned char *)malloc(w*h); unsigned char *pic2=(unsigned char *)malloc(w*h); float Sum_PSNR=0; //定义所有帧的PSNR和 float average_PSNR; //定义平均PSNR for(int i=0;i<num;i++){ fread(pic1,1,w*h,fp1); fread(pic2,1,w*h,fp2); double mse_sum=0,mse=0,psnr=0; for(int j=0;j<w*h;j++){ mse_sum+=pow((double)(pic1[j]-pic2[j]),2); } mse=mse_sum/(w*h); psnr=10*log10(255.0*255.0/mse); printf("the %d frame PSNR is %5.3f\n",i,psnr); fprintf(fp,"the %d frame PSNR is %5.3f\n",i,psnr); //存取每一帧的PSNR值到txt Sum_PSNR+=psnr; fseek(fp1,w*h/2,SEEK_CUR); fseek(fp2,w*h/2,SEEK_CUR); } average_PSNR=Sum_PSNR/num; printf("the average PSNR is %5.3f\n",average_PSNR); fprintf(fp,"the average PSNR is %5.3f\n",average_PSNR); //存取所有帧的平均PSNR值到txt free(pic1); free(pic2); fclose(fp1); fclose(fp2); return 0; } int main() { //参数分别为(原始视频序列,压缩后视频序列,宽,高,帧数); simplest_yuv420_psnr("BasketballDrill_832x480_50.yuv","BQMall_832x480_60.yuv",832,480,5); //注意视频序列所在路径,默认的是跟当前工程在一个目录下,当然也可以自己指定 system("pause"); }
相关文章推荐
- YUV3---- 生成YUV420P格式的灰阶测试图和计算两个YUV420P像素数据的PSNR
- 计算两段yuv格式视频流中每一帧的psnr值
- YUV视频PSNR计算及代码实现
- FFmpeg浅尝辄止(二)——YUV视频序列编码为视频
- 使用FFmpeg类库实现YUV视频序列编码为视频
- FFmpeg浅尝辄止(二)——YUV视频序列编码为视频
- 使用FFmpeg类库实现YUV视频序列编码为视频
- YUV测试序列下载及视频序列的单帧播放工具使用
- YUV Video Sequences (YUV视频序列网址)
- FFmpeg SDK开发课程笔记(一):调用FFmpeg SDK对YUV视频序列进行编码
- matlab 曲线拟合--视频编码中PSNR计算及码率计算
- matlab 曲线拟合--视频编码中PSNR计算及码率计算(2)
- FFmpeg浅尝辄止(二)——YUV视频序列编码为视频
- YT03-递推求解课后题目-1004 计算直线的交点数-(6.7日-烟台大学ACM预备队解题报告)分析: 将n 条直线排成一个序列,两条直线最多只有一个交点,三条直线最多有两个交点,直线n 和其他n
- MATLAB 将YUV格式视频转换为图像帧序列
- 使用FFmpeg类库实现YUV视频序列编码为视频
- matlab 曲线拟合--视频编码中PSNR计算及码率计算(1)
- YUV Video Sequences (YUV视频序列网址)
- C间隔帧读取yuv视频序列并将提取出的帧序列组成新的yuv文件
- 各种视频测试序列(YUV,HEVC,H264等)