Created
April 9, 2019 23:20
-
-
Save dwbuiten/2bdee1b99ef11fe2769ed2e8d3225aae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* One-off IVF concat */ | |
#include <stdbool.h> | |
#include <stdio.h> | |
#include <stdint.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <libavutil/intreadwrite.h> | |
#define TICKS 1 | |
#define NO_FILES 46 | |
int main() | |
{ | |
uint64_t timestamp = 0; | |
bool first = true; | |
FILE *out; | |
out = fopen("out.ivf", "wb"); | |
if (out == NULL) { | |
printf("Could't open output file.\n"); | |
return 1; | |
} | |
for (int i = 0; i < NO_FILES; i++) { | |
FILE *in; | |
size_t size; | |
char name[100] = {0}; | |
snprintf(&name[0], 100, "out/%d.ivf", i); | |
in = fopen(name, "rb"); | |
if (in == NULL) { | |
printf("Couldn't open %s.\n"); | |
fclose(out); | |
return 1; | |
} | |
fseeko(in, 0, SEEK_END); | |
size = ftello(in); | |
fseeko(in, 0, SEEK_SET); | |
printf("File %s (%zu bytes)\n", name, size); | |
if (first) { | |
uint8_t header[32]; | |
fread(&header[0], 1, 32, in); | |
fwrite(&header[0], 1, 32, out); | |
first = false; | |
} else { | |
fseeko(in, 32, SEEK_SET); | |
} | |
size -= 32; | |
while (size > 0) { | |
uint8_t fheader[12]; | |
uint8_t ftimestamp[8]; | |
uint32_t fsize; | |
uint8_t *buf; | |
fread(&fheader[0], 1, 12, in); | |
size -= 12; | |
fwrite(&fheader[0], 1, 4, out); | |
fsize = AV_RL32(&fheader[0]); | |
AV_WL64(&ftimestamp[0], timestamp); | |
timestamp += TICKS; | |
fwrite(&ftimestamp[0], 1, 8, out); | |
buf = malloc(fsize); | |
if (buf == NULL) { | |
printf("No memory... bailing.\n"); | |
fclose(in); | |
fclose(out); | |
return 1; | |
} | |
fread(buf, 1, fsize, in); | |
size -= fsize; | |
fwrite(buf, 1, fsize, out); | |
free(buf); | |
} | |
if (size < 0) { | |
printf("Something is wrong.\n"); | |
fclose(in); | |
fclose(out); | |
return 1; | |
} | |
fclose(in); | |
} | |
fclose(out); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment