1. 程式人生 > >【PE】YUV檔案分割,幀率擴倍功能

【PE】YUV檔案分割,幀率擴倍功能

Date: 2018.5.30

YUV處理實用小工具:

1、隔幀分割:

功能說明:cutYUV.cpp 實現YUV檔案分割為兩個子YUV,隔幀寫入YUV,實現幀率擴倍功能。

/*****************************************************
//Function: split  a yuv file to two sub yuv file, fps 
// increase twice.
//Date: 2018-5-30
//Author: SoaringLee
//Modified:
*****************************************************/
#include "stdio.h" #include "stdlib.h" #include "string" int main(int argc, char** argv) { unsigned char* y; FILE* fp_input, *fp_out1, *fp_out2; int width, height, picturesize, framenum = 0; printf("Usage: splitYUV.exe srcyuv dstyuv1 dstyuv2 width height\n\n"); if (argc < 5) { return
-1; } width = atoi(argv[4]); height = atoi(argv[5]); fp_input = fopen(argv[1], "rb"); if (NULL == fp_input) { printf("open %s fail!\n", argv[1]); return -1; } fp_out1 = fopen(argv[2], "wb"); if (NULL == fp_out1) { printf("open %s fail!\n", argv[2]); return -1; } fp_out2 = fopen
(argv[3], "wb"); if (NULL == fp_out2) { printf("open %s fail!\n", argv[3]); return -1; } picturesize = width*height * 3 / 2;//++YUV420 y = (unsigned char*)malloc(picturesize*sizeof(unsigned char*)); while (fread(y, 1, picturesize, fp_input) == picturesize) { if (framenum % 2 == 0) { fwrite(y, 1, picturesize, fp_out1); } else { fwrite(y, 1, picturesize, fp_out2); } framenum++; } printf("[SplitYUV] split %s to %s and %s successfully!!!\n", argv[1], argv[2], argv[3]); free(y); y = NULL; fclose(fp_input); fclose(fp_out1); fclose(fp_out2); return 0; }

另外,還可以通過ffmpeg實現隔幀分割的功能:

ffmpeg -r 2 -s WxH -i rawbitstream.yuv -filter:v select="mod(n-1\,2)" \
-c:v rawvideo -r 1 -format rawvideo -pix_fmt yuv420p -an odd.yuv

ffmpeg -r 2 -s WxH -i rawbitstream.yuv -filter:v select="not(mod(n-1\,2))" \
-c:v rawvideo -r 1 -format rawvideo -pix_fmt yuv420p -an even.yuv
2、分段分割:

Extract some YUV frames from large yuv File
從第0幀開始擷取30幀:

ffmpeg -s widthxheight -i input.yuv -c:v rawvideo -filter:v select="gt(n\, -1)" -vframes 30 out30.yuv

或者:

ffmpeg -s widthxheight -i input.yuv -c:v rawvideo -filter:v select="between(n\, 0\, 29)" out30.yuv

或者:

ffmpeg -r 1 -ss 0 -i input.yuv -vcodec copy -vframes 30 output.yuv

更多命令使用參考:

THE END!