[ create a new paste ] login | about

Link: http://codepad.org/AIjzS9dV    [ raw code | output | fork ]

C, pasted on Jan 16:
// DumpTS audio hevc to aac
// Audio source only
// by 293

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc,char *argv[])
{
    FILE *fp_src, *fp_dst;

    int i;
    int data[4] = {0, 0, 0, 0};
    long int pos, pos_prev = 0, bytes;
    unsigned int total_frame = 0;

    
    if(argc < 3){
        printf("dt2aac input output\r\n");
        return -1;
    }
    
    if((fp_src = fopen(argv[1], "rb")) == NULL ) {
            perror("input file");
            exit(EXIT_FAILURE);
    }
    
    fseek(fp_src,  0L, SEEK_SET);

    if((fp_dst = fopen(argv[2], "wb")) == NULL ) {
            perror(NULL);
            exit(EXIT_FAILURE);
    }
    
    fseek(fp_dst,  0L, SEEK_SET);
    
    while(!feof(fp_src)){
        if(ferror(fp_src)){
            perror(NULL);
            exit(EXIT_FAILURE);
        }

        if(ferror(fp_dst)){
            perror(NULL);
            exit(EXIT_FAILURE);
        }
        
        data[0] = fgetc(fp_src);
        
        if((data[0] == 0x90) && (data[1] == 0x11) && (data[2] == 0x00) && (data[3] == 0x20)){
            pos = ftell(fp_src);
            bytes = pos - pos_prev;
            if(bytes > 8){
                fputc(0x56, fp_dst);
                fputc((((int)bytes >> 8) & 0x1F) | 0xE0, fp_dst);
                fputc((int)bytes & 0xFF, fp_dst);
                fputc(0x20, fp_dst);
                fputc(0x00, fp_dst);
                fputc(0x11, fp_dst);
                fputc(0x90, fp_dst);
                fseek(fp_src, pos_prev, SEEK_SET);
                for(i = 0;i < (bytes - 4);i++){
                    fputc(fgetc(fp_src), fp_dst);
                }
                printf("offset:%08ld bytes:%04lX\r\n", pos, bytes);
                total_frame++;
            }
            pos_prev = pos;
            memset(data, 0, sizeof(data));
        } else {
            data[3] = data[2];
            data[2] = data[1];
            data[1] = data[0];
        }
    }
    
    printf("Total Frame:%d\r\n", total_frame);

    fclose(fp_src);
    fclose(fp_dst);

    return 0;
}


Output:
1
2
3
dt2aac input output

Exited: ExitFailure 255


Create a new paste based on this one


Comments: