-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cpp
158 lines (143 loc) · 4.27 KB
/
Main.cpp
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include "stdio.h"
#include "unistd.h"
#include "getopt.h"
#include "KEncoder.h"
#include "KDemuxer.h"
#include "InputParameter.h"
#include "KErrors.h"
const char *ENC = "enc";
const char *DMX = "dmx";
struct option longopts[] =
{
// 选择功能, enc表示编码
{"func", required_argument, NULL, FUNCTION},
// 比特率
{"br", required_argument, NULL, BITRATE},
// 帧率
{"fr", required_argument, NULL, FRAMERATE},
// 帧数
{"fc", required_argument, NULL, FRAMECOUNT},
// 分辨率
{"vr", required_argument, NULL, VIDEO_RESOLUTION},
// 输出视频es流
{"vo", required_argument, NULL, VIDEO_OUTPUT_FILE},
// 输出音频es流
{"ao", required_argument, NULL, AUDIO_OUTPUT_FILE},
};
int main(int argc, char **argv)
{
int oc;
char ec;
char *func = NULL;
InputParameter parameter;
while((oc = getopt_long(argc, argv, "i:o:", longopts, NULL)) != -1)
{
switch(oc)
{
case FUNCTION:
func = optarg;
break;
case INPUT_FILE:
parameter.mInputFileName = optarg;
break;
case OUTPUT_FILE:
parameter.mOutputFileName = optarg;
break;
case BITRATE:
parameter.mBitRate = atoi(optarg);
break;
case FRAMERATE:
parameter.mFrameRate = atoi(optarg);
break;
case FRAMECOUNT:
parameter.mFrameCount = atoi(optarg);
break;
case VIDEO_OUTPUT_FILE:
parameter.mVideoOutputFileName = optarg;
break;
case AUDIO_OUTPUT_FILE:
parameter.mAudioOutputFileName = optarg;
break;
case VIDEO_RESOLUTION:
char *resolution = optarg;
int length = strlen(resolution);
int i;
for (i = 0; i < length; i++)
{
if (resolution[i] == 'x')
{
int widthLength = i;
char width[widthLength + 1];
char height[length - widthLength];
strncpy(width, resolution, widthLength);
width[widthLength] = '\0';
printf("w: %s\n", width);
strncpy(height, resolution + widthLength + 1, length - widthLength - 1);
height[length - widthLength - 1] = '\0';
printf("h: %s\n", height);
parameter.mWidth = atoi(width);
parameter.mHeight = atoi(height);
}
}
break;
}
}
if (!strcmp(ENC, func))
{
printf("启动编码器\n");
KErrors res = NO_ERROR;
KEncoder *encoder = new KEncoder();
res = encoder->configure(¶meter);
if (res == NO_ERROR)
{
printf("配置编码器成功\n");
res = encoder->start();
if (res == NO_ERROR)
{
printf("开启编码器成功\n");
}
else
{
printf("开启编码器失败, error code: %d\n", res);
}
}
else
{
printf("配置编码器失败, error code: %d\n", res);
}
if (encoder != NULL)
{
delete encoder;
encoder = NULL;
}
}
else if (!strcmp(DMX, func))
{
printf("启动解复用器\n");
KErrors res = NO_ERROR;
KDemuxer *demuxer = new KDemuxer();
res = demuxer->configure(¶meter);
if (res == NO_ERROR)
{
printf("配置解复用器成功\n");
res = demuxer->start();
if (res == NO_ERROR)
{
printf("开启解复用器成功\n");
}
else
{
printf("开启解复用器失败, error code: %d\n", res);
}
}
else
{
printf("配置解复用器失败, error code: %d\n", res);
}
if (demuxer != NULL)
{
delete demuxer;
demuxer = NULL;
}
}
}