主程序
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#define BYTE_PER_FILE 1048576
int main()
{
FILE *f = fopen("video.mp4", "rb");
FILE *output_file = NULL;
char buffer;
long file_cnt = 0;
long byte_cnt = BYTE_PER_FILE;
if (f)
{
while (fread(&buffer, 1, 1, f) == 1)
{
if (byte_cnt == BYTE_PER_FILE)
{
byte_cnt = 0;
file_cnt++;
fclose(output_file);
char f_num[100];
char f_path[100] = "./video/split_";
sprintf(f_num, "%d", file_cnt);
strcat(f_path, f_num);
strcat(f_path, ".data");
output_file = fopen(f_path, "wb");
}
fwrite(&buffer,1,1,output_file);
byte_cnt++;
}
fclose(f);
}
else
{
printf("文件打开出错\n");
}
return 0;
}