This commit is contained in:
PodmogilnyjIvan
2021-12-03 03:34:31 -08:00
commit ff4acf84be
542 changed files with 136810 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
# Find Pangolin (https://github.com/stevenlovegrove/Pangolin)
find_package(Pangolin 0.4 REQUIRED)
include_directories(${Pangolin_INCLUDE_DIRS})
add_executable(VideoJsonPrint main-print.cpp)
target_link_libraries(VideoJsonPrint ${Pangolin_LIBRARIES})
add_executable(VideoJsonTransform main-transform.cpp)
target_link_libraries(VideoJsonTransform ${Pangolin_LIBRARIES})
#######################################################
## Install
install(TARGETS VideoJsonPrint VideoJsonTransform
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
)

View File

@@ -0,0 +1,36 @@
#include <pangolin/pangolin.h>
#include <pangolin/log/packetstream_reader.h>
#include <pangolin/log/packetstream_writer.h>
#include <pangolin/video/video.h>
int main( int argc, char* argv[] )
{
if( argc == 2) {
const std::string filename = std::string(argv[1]);
pangolin::PacketStreamReader reader(filename);
// Extract JSON
picojson::value all_properties;
for(size_t i=0; i < reader.Sources().size(); ++i) {
picojson::value source_props;
const pangolin::PacketStreamSource& src = reader.Sources()[i];
source_props["device_properties"] = src.info["device"];
// Seek through index, loading frame properties
for(size_t framenum=0; framenum < src.index.size(); ++framenum) {
reader.Seek(src.id, framenum);
pangolin::Packet pkt = reader.NextFrame();
source_props["frame_properties"].push_back(pkt.meta);
}
all_properties.push_back(source_props);
}
std::cout << all_properties.serialize(true) << std::endl;
}else{
std::cout << "Usage: \n\tPangoJsonPrint filename.pango" << std::endl;
}
}

View File

@@ -0,0 +1,63 @@
#include <pangolin/pangolin.h>
#include <pangolin/log/packetstream_reader.h>
#include <pangolin/log/packetstream_writer.h>
#include <pangolin/video/video.h>
int main( int argc, char* argv[] )
{
if( argc == 3) {
const std::string filein = std::string(argv[1]);
const std::string fileout = std::string(argv[2]);
PANGO_ASSERT(filein != fileout);
pangolin::PacketStreamReader reader(filein);
pangolin::PacketStreamWriter writer(fileout);
// Read new JSON from command line
picojson::value all_properties;
std::cout << "Reading JSON from input" << std::endl;
std::cin >> all_properties;
std::cout << "+ done" << std::endl;
PANGO_ASSERT(all_properties.size() == reader.Sources().size());
for(size_t i=0; i < reader.Sources().size(); ++i) {
const picojson::value& src_json = all_properties[i];
pangolin::PacketStreamSource src = reader.Sources()[i];
PANGO_ASSERT(src_json.contains("frame_properties"));
PANGO_ASSERT(src_json.contains("device_properties"));
PANGO_ASSERT(src_json["frame_properties"].size() == src.index.size());
// Ensure the index gets rewritten, and update the device properties.
src.index.clear();
src.info["device"] = src_json["device_properties"];
writer.AddSource(src);
}
std::cout << "Writing video with new JSON to '" << fileout << "'" << std::endl;
try{
std::vector<char> buffer;
while(true)
{
pangolin::Packet pkt = reader.NextFrame();
buffer.resize(pkt.BytesRemaining());
pkt.Stream().read(buffer.data(), buffer.size());
const picojson::value& new_frame_json = all_properties[pkt.src]["frame_properties"][pkt.sequence_num];
writer.WriteSourcePacket(pkt.src, buffer.data(), pkt.time, buffer.size(), new_frame_json);
std::cout << "Frames complete: " << pkt.sequence_num << " / " << reader.Sources()[pkt.src].index.size() << '\r';
std::cout.flush();
}
}catch(const std::runtime_error &)
{
}
std::cout << std::endl << "+ done" << std::endl;
}else{
std::cout << "Usage: \n\tPangoJsonTransform file_in.pango file_out.pango" << std::endl;
}
}