-
Notifications
You must be signed in to change notification settings - Fork 0
/
goproWhereWhen.cpp
143 lines (115 loc) · 4.31 KB
/
goproWhereWhen.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
//
// System for extracting GoPro GPMETA data from MP4 files
//
// Target is GPS lat, lon, and elevation as well as GPSU UTC time information
//
// System allows for a variety of sampling rates as well as batch file processing
// flexibility.
//
// Export of data can be had as CSV file(s) or GPX files to be imported elsewhere
//
// Initial focus in 2020 was post-processing video taken on motorcycle adventure
// trips to know where I was when certain video files were taken to enable looking
// back at a bit of video and being able to pinpoint a location "post-ride"
//
// Author: Robert M. Wolff - bob dawt wolff 68 aht gmail.com
// Copyright Robert Wolff 2020 with MIT license
//
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
// basename()
#include <libgen.h>
#include "opts.h"
#include "goprometa.h"
#include "exporters.h"
using namespace std;
opts options;
SamplesHandler sHandler;
// Utils
extern void getAllFilesFromPath(const char* inPath, bool bRecurse, vector<string>& files);
extern bool validateFileExts(const char* endingList, vector<string> &destList);
extern void pruneFilesList(vector<string> &filesInOut, vector<string> toKeep);
int main(int argc, const char** argv)
{
vector<string> files;
options.processOpts(argc, argv);
vector<std::string> skippedFiles;
//#define UNITTEST
#ifdef UNITTEST
unittest_ExtValidation();
unittest_PruneFiles();
exit(1);
#endif
// exit(1);
if (options.fileExtRaw != "") {
// Need to validate the input and place it into the options vector
if (!validateFileExts(options.fileExtRaw.c_str(), options.fileExtList)) {
// Invalid.
cout << "ERROR: Option '--fileext' expects to get a comma separated list of" << endl;
cout << " file extensions. No '*' or '.' - just command separated extensions." << endl;
cout << " Upper/Lower case does not matter. Extension comparison will be insensitive." << endl;
cout << " Example: --fileext=MP4,MOV,MPEG" << endl;
exit(-2);
}
// Now we have a good extensions list.
// These will be applied to 'sourcedir' when searching.
}
if (options.sourceDir != "") {
getAllFilesFromPath(options.sourceDir.c_str(), options.sourceDirRecursive, files);
// Now let's apply the fileext results to this list to prune it down to our work items.
pruneFilesList(files, options.fileExtList);
// std::cerr << "Final Files List:" << std::endl;
// for (auto f: files)
// std::cout << f << std::endl;
}
if (options.inFile != "") {
files.clear();
files.push_back(options.inFile);
}
vector<GPSSample> samples;
// At this stage, we have a list of input files that need processed.
// It's time to decide how to rip through that list and what to do with the results.
std::cerr << "Processing: ";
for (auto f: files) {
GoProMeta *pGPM = new GoProMeta();
samples.clear();
std::cerr << basename((char*)f.c_str()) << ", ";
pGPM->setSecondsBetweenSamples(options.timeBetweenSamples);
if (!pGPM->openFile(f.c_str())) {
// std::cerr << "ERROR: Could not open file: " << f << std::endl;
skippedFiles.push_back(f);
delete pGPM;
continue;
// exit(-6);
}
if (!pGPM->processFile()) {
std::cerr << "ERROR: Could not process file properly: " << f << std::endl;
delete pGPM;
continue;
// exit(-7);
}
pGPM->getOutputPoints(samples);
// std::cerr << "For file " << f << " Number of samples is: " << samples.size() << std::endl;
// if (samples.size())
// std::cerr << " First entry: " << samples[0] << std::endl;
// Insert samples into SamplesHandler for safe keeping
if (!sHandler.AddSampleSet(f.c_str(), samples)) {
std::cerr << "Could not add samples for: " << f << std::endl;
// continuing...
}
delete pGPM;
}
std::cerr << std::endl;
// Now that we have all the files processed, what shall we do with them?
//TODO: A --summary might iterate through skippedFiles to list what wasn't done.
std::cerr << "Summary: Of " << files.size() << " files, " << files.size() - skippedFiles.size()
<< " were processed and " << skippedFiles.size() << " were skipped." << std::endl;
// Let's try 'exporting' in groups.
// std::map<std::string, std::map<std::string, std::vector<GPSSample>>> groupedDates;
// sHandler.ExportDataGroupDailySegmented(groupedDates);
GPXExporter gpxOut(&sHandler);
gpxOut.ExportDailySegmented();
return 0;
}