• 【PE/Codecs】YUV文件拼接的方法


    Date: 2018.5.28


    功能说明:YUV文件拼接,可以设置两个YUV文件的帧数,将两个YUV文件的三个分量顺序拼接,只支持YUV420P采样格式。

    2018.9.20

    增加功能:

    1. 输入YUV文件长度检查,需要拼接的文件长度不能超过YUV本身长度;
    2. 可以设置两幅YUV分别重复的次数。
    #include "stdio.h"
    #include "stdlib.h"
    #include "string.h"
    
    int main(int argc, char** argv)
    {
    	unsigned char* y;
    	FILE* fp_yuv1, *fp_yuv2, *fp_yuv3;
    	int width, height, len1, len2, picturesize;
    	int i, yuv_len1, yuv_len2, dup1, dup2, total_frm_num1, total_frm_num2, dup1_b, dup2_b;
    
    	if (argc < 10)
    	{
    	 printf("Usage: connectYUV.exe src2file src2file dstfile width height len1 len2 dup1 dup2
    
    ");
             printf("Notice: the width and height of those two yuv must be same!!!
    ");
             printf("Notice: dup1 is the number of replication for srcfile1, and dup2 is the number of replicaiton for srcfile2.
    ");
             return -1;
    	}
            for(i=0; i<argc;i++)
            {
              printf("%s ", argv[i]);
            }
            printf("
    ");
    
    	fp_yuv1 = fopen(argv[1], "rb");
    	if (NULL == fp_yuv1)
    	{
    		printf("ERROR: open %s fail!
    ", argv[1]);
    		return -1;
    	}
    	fp_yuv2 = fopen(argv[2], "rb");
    	if (NULL == fp_yuv2)
    	{
    		printf("ERROR: open %s fail!
    ", argv[2]);
    		return -1;
    	}
    	fp_yuv3 = fopen(argv[3], "wb");
    	if (NULL == fp_yuv3)
    	{
    		printf("ERROR: open %s fail!
    ", argv[3]);
    		return -1;
    	}
    
        width = atoi(argv[4]);
        height = atoi(argv[5]);
        len1 = atoi(argv[6]);
        len2 = atoi(argv[7]);
        dup1 = atoi(argv[8]);
        dup2 = atoi(argv[9]);
    
        picturesize = width *height * 3 / 2; //++YUV420
    
        // yuv输入长度检查
        fseek(fp_yuv1, 0, SEEK_END);
        yuv_len1 = ftell(fp_yuv1);
        total_frm_num1 = yuv_len1 / picturesize;
        printf("total_frame_num1: %d
    ", total_frm_num1);
        fseek(fp_yuv1, 0, SEEK_SET);
        
        fseek(fp_yuv2, 0, SEEK_END);
        yuv_len2 = ftell(fp_yuv2);
        total_frm_num2 = yuv_len2 / picturesize;
        printf("total_frame_num2: %d
    ", total_frm_num2);
        fseek(fp_yuv2, 0, SEEK_SET);
        
        if( len1 > total_frm_num1 || len2 > total_frm_num2)
        {
            printf("ERROR: len1 > frame_num1 or len2 > frame_num2!
    ");
            return -1;
        }
    	
    	y = (unsigned char*)malloc(picturesize*sizeof(unsigned char*));
    	if (NULL == y)
    	{
    		printf("ERROR: malloc y fail!
    ");
    	}
        do{
    	for (i = 0; i < len1; i++)
    	{
    		if (fread(y, 1, picturesize, fp_yuv1) == picturesize)
    		{
    			fwrite(y, 1, picturesize, fp_yuv3);
    		}
    	}
            fseek(fp_yuv1, 0, SEEK_SET);// 特别注意,每次读取之后需要重置读指针位置。
            dup1--;
           } while(dup1);
    
        do{
    	for (i = 0; i < len2; i++)
    	{
    		if (fread(y, 1, picturesize, fp_yuv2) == picturesize)
    		{
    			fwrite(y, 1, picturesize, fp_yuv3);
    		}
    	}
           fseek(fp_yuv2, 0, SEEK_SET); // 特别注意,每次读取之后需要重置读指针位置。
           dup2--;
        } while(dup2);
    
    	printf("connect yuv %s and %s ==> %s successfully, total frames: %d
    ", argv[1], argv[2], argv[3], len1*dup1_b+len2*dup2_b);
    
    	free(y);
    	y = NULL;
    	fclose(fp_yuv1);
    	fclose(fp_yuv2);
    	fclose(fp_yuv3);
    
    	return 0;
    }
    

    THE END!

  • 相关阅读:
    POJ1185:炮兵阵地(状压dp)
    POJ3254:Corn Fields(状压dp第一发)
    二进制x&(x-1);
    子集和问题(应用--换零钱)POJ2229:Sumsets
    JAVA math包
    UVA+POJ中大数实现的题目,持续更新(JAVA实现)
    HDU中大数实现的题目,持续更新(JAVA实现)
    SDUT中大数实现的题目,持续更新(JAVA实现)
    JAVA与ACM
    HDU3123:GCC(同余模简单题)
  • 原文地址:https://www.cnblogs.com/SoaringLee/p/10532116.html
Copyright © 2020-2023  润新知