FFmpeg
Loading...
Searching...
No Matches
bin2c.c
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 */
22
23#include <string.h>
24#include <stdio.h>
25
26int main(int argc, char **argv)
27{
28 const char *name;
29 FILE *input, *output;
30 unsigned int length = 0;
31 unsigned char data;
32
33 if (argc < 3 || argc > 4)
34 return 1;
35
36 input = fopen(argv[1], "rb");
37 if (!input)
38 return -1;
39
40 output = fopen(argv[2], "wb");
41 if (!output) {
42 fclose(input);
43 return -1;
44 }
45
46 if (argc == 4) {
47 name = argv[3];
48 } else {
49 size_t arglen = strlen(argv[1]);
50 name = argv[1];
51
52 for (int i = 0; i < arglen; i++) {
53 if (argv[1][i] == '.')
54 argv[1][i] = '_';
55 else if (argv[1][i] == '/')
56 name = &argv[1][i+1];
57 }
58 }
59
60 fprintf(output, "const unsigned char ff_%s_data[] = { ", name);
61
62 while (fread(&data, 1, 1, input) > 0) {
63 fprintf(output, "0x%02x, ", data);
64 length++;
65 }
66
67 fprintf(output, "0x00 };\n");
68 fprintf(output, "const unsigned int ff_%s_len = %u;\n", name, length);
69
70 fclose(output);
71
72 if (ferror(input) || !feof(input)) {
73 fclose(input);
74 return -1;
75 }
76
77 fclose(input);
78
79 return 0;
80}
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
int main
Definition dovi_rpuenc.c:38
const char data[16]
Definition mxf.c:149
const char * name
Definition qsvenc.c:142