裁剪YUV檔案

2021-07-05 06:39:25 字數 1605 閱讀 7231

在進行yuv檔案操作時,經常會遇到需要選取yuv原始檔中的一部分幀,這就需要對原始檔進行裁剪。實現的原理就是根據幀大小讀取原始檔,然後儲存需要的幀。下面的**給出實現的主要過程:
int cutyuv(char* filename,int width,int height,int startframe,int endframe,int pixfmt)

/*get destination file name*/

sprintf_s(startf_c, "%d", startframe);

sprintf_s(endf_c, "%d", endframe);

strcat(startf_c, "_");

strcat(startf_c, endf_c);

strcat(startf_c, "cutted.yuv");

len = strlen(filename);

strncat(dstfilename, filename,(len-4));

strcat(dstfilename, "_");

strcat(dstfilename, startf_c);

cutfile = fopen(dstfilename, "wb");/*open destination file(cutted file)*/

if (!cutfile)

ysize = width* height; /*the size of y component*/

switch (pixfmt) /*pixel format*/

framesize = ysize + uvsize; /*size of a frame*/

_fseeki64(srcfile, 0, seek_set); /*file start point,when file larger than 2g,we must use _fseeki64,not fseek*/

_fseeki64(srcfile,0,seek_end);

framenum = _ftelli64(srcfile) / framesize; /*calculate frame number*/

_fseeki64(srcfile,0,seek_set);

/*frame check*/

if (framenum < startframe)

else if (framenum < (endframe - startframe))

else

framebuffer = (char*)malloc(sizeof(char)*framesize);

while (1) /*file read,while end*/ }

printf("process successfully\n");

free(framebuffer);

fclose(srcfile);

fclose(cutfile);

return 0;

}

工程源**:

可執行程式:

Matlab 讀寫yuv檔案

clear all clc fid fopen data testing down.yuv r 讀入檔案 fod fopen data testing test.yuv w 輸出檔案 row 768 2 col 1024 2 影象的高 寬 frames 97 total 97 序列的幀數 for f...

Python讀取YUV檔案,並顯示

opencv可以讀取的型別比較多,但大多是比較常見的型別,比如 jpg 和 png 但它不能直接讀取yuv格式的檔案,需要通過python讀取yuv檔案,並進行相應的轉換後,才能被opencv讀取,並進行後續相應的處理.話不多說,直接上程式.import cv2 from numpy import ...

裁剪Matlab生成的eps檔案

1 matlab生成含有subplot的eps檔案總是四周留白,造成過寬過長無法插入文章,嘗試了很多方法,終於測試出了能用且比較方便的方法。2 其實gsview中的 pstoeps 功能可以做到這件事 ref1 就是自己點來點去發現right和top點不准,不是所見即所得的,而且在win64下,gs...