[ create a new paste ] login | about

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

C, pasted on Jan 21:
// DumpTS audio hevc to aac tool
// 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;

    long long input_file_size, pos, pos_prev = 0;
    long total_frame = 0;
    int i;
    int bytes;
    int data[4] = {0, 0, 0, 0};
    
    if(argc < 3){
        printf("dt2aac input output\r\n");
        exit(EXIT_FAILURE);
    }
    
    if((fp_src = fopen(argv[1], "rb")) == NULL ) {
            perror("input file");
            exit(EXIT_FAILURE);
    }

    _fseeki64(fp_src, 0LL, SEEK_END);

    input_file_size = _ftelli64(fp_src);
    
    _fseeki64(fp_src,  0LL, SEEK_SET);

    if((fp_dst = fopen(argv[2], "wb")) == NULL ) {
            perror(NULL);
            exit(EXIT_FAILURE);
    }
    
    _fseeki64(fp_dst,  0LL, SEEK_SET);
    
    printf("dt2aac processing...\r\n0%%");

    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 = _ftelli64(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);
                _fseeki64(fp_src, pos_prev, SEEK_SET);
                for(i = 0;i < (bytes - 4);i++){
                    fputc(fgetc(fp_src), fp_dst);
                }
//                printf("offset:%08lld bytes:%04X\r\n", pos, bytes);
                printf("\r%d%%", (int)((float)_ftelli64(fp_src) / (float)input_file_size * 100));

                total_frame++;
            }
            pos_prev = pos;
            memset(data, 0, sizeof(data));
        } else {
            data[3] = data[2];
            data[2] = data[1];
            data[1] = data[0];
        }
    }
    
    pos = _ftelli64(fp_src);
    bytes = pos - pos_prev + 4;
    if((bytes > 8) && (total_frame > 0)){
        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);
        _fseeki64(fp_src, pos_prev, SEEK_SET);
        for(i = 0;i < (bytes - 4);i++){
            fputc(fgetc(fp_src), fp_dst);
        }
//        printf("offset:%08lld bytes:%04X\r\n", pos, bytes);
        printf("\r%d%%", (int)((float)_ftelli64(fp_src) / (float)input_file_size * 100));

        total_frame++;
    }
    
    printf("\r\nTotal AAC Frames:%ld\r\n", total_frame);

    fclose(fp_src);
    fclose(fp_dst);

    return 0;
}


Output:
1
2
3
4
5
6
7
8
9
10
11
In function `main':
undefined reference to `_fseeki64'
undefined reference to `_ftelli64'
undefined reference to `_fseeki64'
undefined reference to `_fseeki64'
undefined reference to `_ftelli64'
undefined reference to `_fseeki64'
undefined reference to `_ftelli64'
undefined reference to `_ftelli64'
undefined reference to `_fseeki64'
undefined reference to `_ftelli64'


Create a new paste based on this one


Comments: