-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathre-encode.cpp
More file actions
141 lines (106 loc) · 3.86 KB
/
re-encode.cpp
File metadata and controls
141 lines (106 loc) · 3.86 KB
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
#include <iostream>
#include <primo/platform/reference++.h>
#include <primo/platform/error_facility.h>
#include <primo/platform/ustring.h>
#include <primo/avblocks/avb.h>
#include "options.h"
using namespace std;
using namespace primo::error;
using namespace primo::avblocks;
using namespace primo::codecs;
void printError(const char* action, const ErrorInfo* e)
{
if (action)
{
cout << action << ": ";
}
if (ErrorFacility::Success == e->facility())
{
cout << "Success" << endl;
return;
}
if (e->message())
{
cout << primo::ustring(e->message()) << " ";
}
cout << "facility:" << e->facility() << " error:" << e->code() << "" << endl;
}
bool reEncode(Options opt)
{
cout << "Input file: " << opt.inputFile << endl;
cout << "Output file: " << opt.outputFile << endl;
cout << "Re-encode audio forced: " << opt.reEncodeAudio << endl;
cout << "Re-encode video forced: " << opt.reEncodeVideo << endl;
remove(opt.outputFile.c_str());
auto transcoder = primo::make_ref(Library::createTranscoder());
// In order to use the OEM release for testing (without a valid license) the transcoder demo mode must be enabled.
transcoder->setAllowDemoMode(1);
// configure input
{
auto mediaInfo = primo::make_ref(Library::createMediaInfo());
mediaInfo->inputs()->at(0)->setFile(primo::ustring(opt.inputFile));
if (!mediaInfo->open())
{
printError("Open Info", mediaInfo->error());
return false;
}
// Add Inputs
{
auto socket = primo::make_ref(Library::createMediaSocket(mediaInfo.get()));
transcoder->inputs()->add(socket.get());
}
}
// Add Outputs
{
// Add output socket
auto socket = primo::make_ref(Library::createMediaSocket());
socket->setStreamType(transcoder->inputs()->at(0)->streamType());
socket->setFile(primo::ustring(opt.outputFile));
// Add output pins and set the ReEncode parameter to Use::On
for (int i = 0; i < transcoder->inputs()->count(); i++)
{
auto inSocket = transcoder->inputs()->at(i);
for (int j = 0; j < inSocket->pins()->count(); j++)
{
auto psi = primo::make_ref(inSocket->pins()->at(j)->streamInfo()->clone());
auto pin = primo::make_ref(Library::createMediaPin());
pin->setStreamInfo(psi.get());
if ((MediaType::Video == psi->mediaType()) && opt.reEncodeVideo)
{
pin->params()->addInt(Param::ReEncode, Use::On);
}
if ((MediaType::Audio == psi->mediaType()) && opt.reEncodeAudio)
{
pin->params()->addInt(Param::ReEncode, Use::On);
}
socket->pins()->add(pin.get());
}
}
transcoder->outputs()->add(socket.get());
}
bool_t res = transcoder->open();
printError("Open Transcoder", transcoder->error());
if (!res)
return false;
res = transcoder->run();
if (!res)
return false;
printError("Run Transcoder", transcoder->error());
transcoder->close();
return true;
}
int main(int argc, char* argv[])
{
Options opt;
switch(prepareOptions( opt, argc, argv))
{
case Command: return 0;
case Error: return 1;
}
primo::avblocks::Library::initialize();
// set your license string
// primo::avblocks::Library::setLicense("PRIMO-LICENSE");
bool reEncodeResult = reEncode(opt);
primo::avblocks::Library::shutdown();
return reEncodeResult ? 0 : 1;
}