-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathre-encode.cpp
More file actions
137 lines (105 loc) · 3.7 KB
/
Copy pathre-encode.cpp
File metadata and controls
137 lines (105 loc) · 3.7 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
#include "stdafx.h"
#include "options.h"
using namespace std;
using namespace primo::avblocks;
using namespace primo::codecs;
using namespace primo::error;
void printError(const wchar_t* action, const primo::error::ErrorInfo* e)
{
if (action)
{
wcout << action << L": ";
}
if (ErrorFacility::Success == e->facility())
{
wcout << L"Success" << endl;
return;
}
if (e->message())
{
wcout << e->message() << L", ";
}
wcout << L"facility:" << e->facility() << L", error:" << e->code() << endl;
}
bool reEncode(Options opt)
{
wcout << L"Input file: " << opt.inputFile << endl;
wcout << L"Output file: " << opt.outputFile << endl;
wcout << L"Re-encode audio forced: " << opt.reEncodeAudio << endl;
wcout << L"Re-encode video forced: " << opt.reEncodeVideo << endl;
DeleteFile(opt.outputFile.c_str());
auto transcoder = primo::make_ref(Library::createTranscoder());
// In order to use the production release for testing (without a valid license),
// the demo mode must be enabled.
transcoder->setAllowDemoMode(1);
// configure input
{
auto mediaInfo = primo::make_ref(Library::createMediaInfo());
mediaInfo->inputs()->at(0)->setFile(opt.inputFile.c_str());
if (!mediaInfo->open())
{
printError(L"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(opt.outputFile.c_str());
// 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(L"Open Transcoder", transcoder->error());
if (!res)
return false;
res = transcoder->run();
if (!res)
return false;
printError(L"Run Transcoder", transcoder->error());
transcoder->close();
return true;
}
int _tmain(int argc, wchar_t* argv[])
{
Options opt;
switch(prepareOptions( opt, argc, argv))
{
case Command: return 0;
case Error: return 1;
}
CoInitialize(NULL);
primo::avblocks::Library::initialize();
// set your license string
// primo::avblocks::Library::setLicense("PRIMO-LICENSE");
bool reEncodeResult = reEncode(opt);
primo::avblocks::Library::shutdown();
CoUninitialize();
return reEncodeResult ? 0 : 1;
}