raw
This commit is contained in:
18
Thirdparty/Pangolin/tools/VideoJson/CMakeLists.txt
vendored
Normal file
18
Thirdparty/Pangolin/tools/VideoJson/CMakeLists.txt
vendored
Normal 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
|
||||
)
|
||||
36
Thirdparty/Pangolin/tools/VideoJson/main-print.cpp
vendored
Normal file
36
Thirdparty/Pangolin/tools/VideoJson/main-print.cpp
vendored
Normal 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;
|
||||
}
|
||||
}
|
||||
63
Thirdparty/Pangolin/tools/VideoJson/main-transform.cpp
vendored
Normal file
63
Thirdparty/Pangolin/tools/VideoJson/main-transform.cpp
vendored
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user