【Codecs】yuvcut,實現yuv檔案剪下功能
阿新 • • 發佈:2019-02-09
參考:https://stackoverflow.com/questions/17967278/extract-some-yuv-frames-from-large-yuv-file?rq=1
// include libraries #include <fstream> using namespace std; #define P420 1.5 const int IMAGE_SIZE = 1920*1080; // ful HD image size in pixels const double IMAGE_CONVERTION = P420; int n_frames = 300; // set number of frames to copy int skip_frames = 500; // set number of frames to skip from the begining of the input file char in_string[] = "F:\\BigBucksBunny\\yuv\\BigBuckBunny_1920_1080_24fps.yuv"; char out_string[] = "out.yuv"; ////////////////////// // main ////////////////////// int main(int argc, char** argv) { double image_size = IMAGE_SIZE * IMAGE_CONVERTION; long file_size = 0; // IO files ofstream out_file(out_string, ios::out | ios::binary); ifstream in_file(in_string, ios::in | ios::binary); // error cheking, like check n_frames+skip_frames overflow // // TODO // image buffer char* image = new char[(int)image_size]; // skip frames in_file.seekg(skip_frames*image_size); // read/write image buffer one by one for(int i = 0; i < n_frames; i++) { in_file.read(image, image_size); out_file.write(image, image_size); } // close the files out_file.close(); in_file.close(); printf("Copy finished ..."); return 0; }