マイポータル
https://qiita.com/carpenders/items/adb743f0a308f6786c73
sv3c.cpp
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct pack_ {
char code[4];
int len;
int magic1;
int magic2;
};
static void dump(struct pack_ &pack)
{
char code[5];
memcpy(code,pack.code,sizeof(pack.code));
code[4] = 0;
printf("code [%s] len %d(0x%x) magic1 0x%x magic2 0x%x\n",
code,pack.len,pack.len,pack.magic1,pack.magic2);
}
int main(int argc,char *argv[])
{
FILE *ifp,*ofp;
ifp = fopen(argv[1],"rb");
char ofname[4096];
sprintf(ofname,"%s.264",argv[1]);
ofp = fopen(ofname,"wb");
if(ifp != NULL && ofp != NULL){
struct pack_ pack;
int size = sizeof(pack);
int rd,wr;
bool ok = true;
if(ok){
rd = fread(&pack,1,size,ifp);
ok = rd == size;
if(ok){
dump(pack);
}
while(ok){
if(ok){
rd = fread(&pack,1,size,ifp);
ok = rd == size;
if(ok){
dump(pack);
}
}
if(ok){
void *buf;
buf = malloc(pack.len);
rd = fread(buf,1,pack.len,ifp);
ok = rd == pack.len;
if(ok){
wr = fwrite(buf,1,rd,ofp);
ok = wr == rd;
}
free(buf);
}
}
}
if(ifp != NULL){
fclose(ifp);
}
if(ofp != NULL){
fclose(ofp);
}
}
return 0;
}