0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

SV3C ビデオカメラ 動画ファイル デコード

Last updated at Posted at 2019-10-31

マイポータル
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;
}

参考
https://oxynotes.com/?p=11912

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?