(缺陷:切片之后只能第一个可以正常播放)
#include #include #include #define Src_File "/home/yzf/120626/input/Titanic.mp4" void main(void) { FILE *fp1,*fp2; char buf[1024*1024]; int n; if((fp1=fopen(Src_File,"rb"))==NULL) { printf("open failed\n"); exit(1); } else printf("open OK\n"); int clipnum=1; while((n=fread(buf,sizeof(char),1024*1024,fp1))>0) { //Get the clipname char Des_File[100]="/home/yzf/LocalCut/clip"; char tmpclipnum[10]; int len=sprintf(tmpclipnum,"%d",clipnum++); strcat(Des_File,tmpclipnum); strcat(Des_File,".mp4"); printf("read=%d,%s\n",n,Des_File); //write clip if((fp2=fopen(Des_File,"wb+"))==NULL) { printf("open failed\n"); exit(1); } if(fwrite(buf,sizeof(char),n,fp2)==-1) { printf("fail to write\n"); exit(1); } //close fp2 fclose(fp2); } if(n==-1) { printf("fail to read\n"); exit(1); } fclose(fp1); }