-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.c
134 lines (107 loc) · 2.58 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//
// main.c
// 420ToNv12
//
// Created by Hank Lee on 5/31/15.
// Copyright (c) 2015 Hank Lee. All rights reserved.
//
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <fcntl.h>
#include <unistd.h>
#include "420ToNv12.h"
#define TIMING 1
#if (TIMING)
struct timeval tv1, tv2;
#endif
int main(int argc, const char * argv[]) {
int fd_rd;
int fd_wr;
uint8_t *y;
uint8_t *u;
uint8_t *v;
ssize_t rd_sz;
uint32_t width;
uint32_t height;
uint32_t wxh;
uint8_t *frame;
uint8_t *dst;
char *cp;
char output_file_name[256];
if (argc < 4)
{
printf("useage: %s [input_file] [width] [height]\n", argv[0]);
return -1;
}
rd_sz = 0;
width = 0;
height = 0;
wxh = 0;
frame = NULL;
dst = NULL;
cp = NULL;
memset(output_file_name, 0, sizeof(output_file_name));
// get input file name from comand line
fd_rd = open(argv[1], O_RDONLY);
// specify output file name
cp = strchr(argv[1], '.');
strncpy(output_file_name, argv[1], cp - argv[1]);
strcat(output_file_name, "_nv12");
strcat(output_file_name, cp);
fd_wr = open
(
output_file_name,
O_WRONLY | O_CREAT | O_TRUNC,
S_IRUSR
);
width = atoi(argv[2]);
height = atoi(argv[3]);
wxh = width * height;
frame = malloc(wxh * 3 / 2);
dst = malloc(wxh / 2);
y = frame;
u = y + wxh;
v = u + wxh / 4;
printf("Processing: ");
while (1)
{
rd_sz = read(fd_rd, frame, wxh * 3 / 2);
if (rd_sz == wxh * 3 / 2)
{
write(fd_wr, y, wxh);
#if (TIMING)
gettimeofday(&tv1, NULL);
#endif
planar_to_interleave
(
wxh,
dst,
u,
v
);
#if (TIMING)
gettimeofday(&tv2, NULL);
printf ("Total time = %f seconds\n",
(double) (tv2.tv_usec - tv1.tv_usec) / 1000000 +
(double) (tv2.tv_sec - tv1.tv_sec));
#endif
write(fd_wr, dst, wxh / 2);
}
else
{
break;
}
fputc('.', stdout);
fflush(stdout);
}
close(fd_rd);
close(fd_wr);
printf("Done\n");
printf("Output file: %s\n", output_file_name);
return 0;
}