-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextraction.cpp
180 lines (148 loc) · 4.87 KB
/
extraction.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
//
// Created by Yann Holme Nielsen on 18/06/2020.
//
#include <lodepng.h>
#include <string>
#include <fstream>
#include <thread>
#include <iostream>
#include <torasu/mod/imgc/MediaDecoder.hpp>
#include "../example/example_tools.hpp"
void writeFrames(torasu::tstd::Dbimg_sequence* sequence, std::string base_path) {
extools::TaskPool saver(4);
auto& frames = sequence->getFrames();
int i = 0;
for (auto& frame : frames) {
std::string path = base_path + "file-" + std::to_string(i + 1) + ".png";
saver.enqueue([path, frame]() {
unsigned error = lodepng::encode(path,
frame.second->getImageData(), frame.second->getWidth(), frame.second->getHeight());
if (error) {
std::cerr << "LODEPNG ERROR " << error << ": " << lodepng_error_text(error) << " - while writing " << path << std::endl;
}
});
++i;
}
saver.sync();
}
void writeAudio(std::string path, torasu::tstd::Daudio_buffer* audioBuff) {
std::ofstream out(path);
size_t size = 4;
uint8_t* l = audioBuff->getChannels()[0].data;
uint8_t* r = audioBuff->getChannels()[1].data;
for (size_t i = 0; i < audioBuff->getChannels()[0].dataSize/size; i++) {
out.write(reinterpret_cast<const char*>(l), size);
out.write(reinterpret_cast<const char*>(r), size);
l += size;
r += size;
}
out.close();
}
int main() {
imgc::MediaDecoder des("143386147_Superstar W.mp4");
// auto totalLength = des.streams[0]->duration * av_q2d(des.streams[0]->base_time);
torasu::tstd::Dbimg_sequence* videoResult1;
torasu::tstd::Daudio_buffer* audioResult1;
des.getSegment((imgc::SegmentRequest) {
.start = 0.05,
.end = 3,
.videoBuffer = &videoResult1,
.audioBuffer = &audioResult1
});
torasu::tstd::Dbimg_sequence* videoResult2;
torasu::tstd::Daudio_buffer* audioResult2;
des.getSegment((imgc::SegmentRequest) {
.start = 0.04,
.end = 0.12,
.videoBuffer = &videoResult2,
.audioBuffer = &audioResult2
});
torasu::tstd::Dbimg_sequence* videoResult3;
torasu::tstd::Daudio_buffer* audioResult3;
des.getSegment((imgc::SegmentRequest) {
.start = 3.04,
.end = 4.08,
.videoBuffer = &videoResult3,
.audioBuffer = &audioResult3
});
torasu::tstd::Dbimg_sequence* videoResult4;
torasu::tstd::Daudio_buffer* audioResult4;
des.getSegment((imgc::SegmentRequest) {
.start = 4.08,
.end = 5,
.videoBuffer = &videoResult4,
.audioBuffer = &audioResult4
});
torasu::tstd::Dbimg_sequence* videoResult5;
torasu::tstd::Daudio_buffer* audioResult5;
des.getSegment((imgc::SegmentRequest) {
.start = 5.04,
.end = 5.33,
.videoBuffer = &videoResult5,
.audioBuffer = &audioResult5
});
torasu::tstd::Dbimg_sequence* videoResult6;
torasu::tstd::Daudio_buffer* audioResult6;
des.getSegment((imgc::SegmentRequest) {
.start = 5.33,
.end = 6,
.videoBuffer = &videoResult6,
.audioBuffer = &audioResult6
});
/*
torasu::tstd::Dbimg_sequence* videoResultB;
des.getSegment((imgc::SegmentRequest) {
.start = 1,
.end = 1.5,
.videoBuffer = &videoResultB,
.audioBuffer = NULL
});
torasu::tstd::Daudio_buffer* audioBuffer;
des.getSegment((imgc::SegmentRequest) {
.start = 1,
.end = 1.5,
.videoBuffer = NULL,
.audioBuffer = &audioBuffer
});
*/
imgc::MediaDecoder desC("104188354_In Memory of Firestarter.mp4");
torasu::tstd::Dbimg_sequence* videoResultC1;
torasu::tstd::Daudio_buffer* audioResultC1;
desC.getSegment((imgc::SegmentRequest) {
.start = 0,
.end = 10,
.videoBuffer = &videoResultC1,
.audioBuffer = &audioResultC1
});
// std::cout << "B1 Video-Size: " << resultB1->videoFrames.size() << " AudioSize: " << resultB1->audioFrames.size() << std::endl;
//
// std::cout << "B2 Video-Size: " << resultB2->videoFrames.size() << " AudioSize: " << resultB2->audioFrames.size() << std::endl;
writeAudio(std::string("test_files/one/audio.pcm"), audioResult1);
writeFrames(videoResult1, std::string("test_files/one/"));
delete videoResult1;
delete audioResult1;
writeAudio(std::string("test_files/two/audio.pcm"), audioResult2);
writeFrames(videoResult2, std::string("test_files/two/"));
delete videoResult2;
delete audioResult2;
writeAudio(std::string("test_files/three/audio.pcm"), audioResult3);
writeFrames(videoResult3, std::string("test_files/three/"));
delete videoResult3;
delete audioResult3;
writeAudio(std::string("test_files/four/audio.pcm"), audioResult4);
writeFrames(videoResult4, std::string("test_files/four/"));
delete videoResult4;
delete audioResult4;
writeAudio(std::string("test_files/five/audio.pcm"), audioResult5);
writeFrames(videoResult5, std::string("test_files/five/"));
delete videoResult5;
delete audioResult5;
writeAudio(std::string("test_files/six/audio.pcm"), audioResult6);
writeFrames(videoResult6, std::string("test_files/six/"));
delete videoResult6;
delete audioResult6;
writeAudio(std::string("test_files/seven/audio.pcm"), audioResultC1);
writeFrames(videoResultC1, std::string("test_files/seven/"));
delete videoResultC1;
delete audioResultC1;
}