Insta360Develop / MediaSDK-Cpp

MediaSDK-Cpp is a C++ library to handle stitching, editing of media from Insta360 Cameras.
60 stars 8 forks source link

MediaSDK-Cpp

MediaSDK-Cpp is a C++ library to handle stitching, editing of media from Insta360 Cameras.

Supported cameras

Model Link
ONE X http://insta360.com/product/insta360-onex/
ONE R Dual-Lens Edition http://insta360.com/product/insta360-oner_twin-edition
ONE R Wide Edition http://insta360.com/product/insta360-oner_twin-edition
ONE R 1-inch Edition http://insta360.com/product/insta360-oner_1inch-edition
ONE X2 https://www.insta360.com/cn/product/insta360-onex2
ONE RS https://www.insta360.com/cn/product/insta360-oners
ONE X3 https://www.insta360.com/cn/product/insta360-x3
ONE X4 https://www.insta360.com/cn/product/insta360-x4

Supported platforms

Platform Version
Windows Windows 7 or later, only x64 supported
Linux Ubuntu, other distributions need to be tested

Supported fileformat

filetype import format export format
Video insv mp4
Image insp/jpeg jpg

Table of contents

Running test demo

On Ubuntu, follow the steps below to build and run stitcherSDKDemo.

$ gcc main.cc -o stitcherSDKDemo -I/path/to/libmediaSDK -lMediaSDK
$ sudo chmod +x  stitcherSDKDemo
$ export LD_LIBRARY_PATH=LD_LIBRARY_PATH:/path/to/libMediaSDK.so
$ ./stitcherSDKDemo -h

Get Started

Note

The video stitcher runs asynchronously. Before StartStitch, you can call the function SetStitchProgressCallback to set a callback for receiving the current process during stitching, and call the function SetStitchStateCallback to set an error callback so that you can get the error info if an error occurs during stitching. After running StartStitch function, you must set a blocking state to prevent the program from ending. You can end the blocking state by using the status returned by these two callback functions. It can be referred to main.cc.

The image stitcher runs synchronously.

CUDA Support:

Image Stitcher

#include <stitcher/stitcher.h>
#include <stitcher/common.h>
auto imageStitcher = std::make_shared<ins_media::ImageStitcher>();

//set params
imageStitcher->SetInputPath(input_paths); 
imageStitcher->SetStitchType(stitch_type);
imageStitcher->SetHDRType(hdr_type);
imageStitcher->SetOutputPath(output_path);
imageStitcher->SetOutputSize(output_width, output_height);
imageStitcher->EnableFlowState(bEnableFlowState);

//perform stitch
imageStitcher->Stitch();

Video Stitcher

Create VideoStitcher
#include <stitcher/stitcher.h>
#include <stitcher/common.h>

auto videoStitcher = std::make_shared<ins_media::VideoStitcher>();
Set Parameters

video_stitcher->SetInputPath(input_paths);
video_stitcher->SetOutputPath(output_path);
video_stitcher->SetStitchType(stitch_type);
video_stitcher->EnableCuda(enable_cuda);
video_stitcher->EnableStitchFusion(enalbe_stitchfusion);
video_stitcher->SetCudaDeviceNo(gpu);
video_stitcher->EnableColorPlus(enable_colorplus, colorpuls_model_path);
video_stitcher->SetOutputSize(output_width, output_height);
video_stitcher->SetOutputBitRate(output_bitrate);
video_stitcher->EnableFlowState(enable_flowstate);
video_stitcher->EnableDenoise(enable_denoise);
video_stitcher->EnableDirectionLock(enable_directionlock);
Set process callback function
void process_callback(long lContext, int process, int error) {
    printf("\rprocess = %d%% ", process);
}

...

videoStitcher->SetStitchProgressCallback(process_callback, 0);
Set error callback function
void error_callback(long lContext, int error, const char* errinfo) {
    //you can print the error info 
}
...

videoStitcher->SetStitchStateCallback(error_callback, 0);
Start Stitch
videoStitcher->StartStitch();
Cancel Stitch
videoStitcher->CancelStitch();

Parameters Guidance

InputPaths

On video The maximum size of the vector is 2. For 5.7k separated videos like /path/to/VID_20190123_113402_00_032.insv and /path/to/VID_20190123_113402_10_032.insv, please input urls of both videos with order like this {"/path/to/VID_20190123_113402_00_032.insv","/path/to/VID_20190123_113402_10_032.insv"},xxx_00_xx.insv means the first eye while xxx_10_xx.insv means the second.

On image Generally the size of the vector is 1 , if you enable HDR , there might be multiple paths.

StitchType

StitchType is an enum.

enum class STITCH_TYPE {
    TEMPLATE, //very fast but not good stitching effect
    OPTFLOW,//slow but best stitching effect
    DYNAMICSTITCH,//fast and keeps a relatively good stitching effect
};

HDRType

HDRType is an enum.

enum class HDR_TYPE {
    ImageHdr_NONE = -1, //do not perform HDR, this is the default value.
    SingleImageHdr = 0, //perform HDR on a single image
    MultiImageHdr_mbb = 1,//perform HDR with multiple images with a ev gap.
    MultiImageHdr_mpl = 2,//same as MultiImageHdr_mbb, with a different algorithm and a little faster.
};

EnableFlowState

Bool value indicating whether you want to enable the super flowstate feature of Insta360.

EnableDirectionLock

Bool value indicating whether you want to lock view direction.

EnableStitchFusion

Bool value indicating whether you want to image fusion.

EnableDenoise

Bool value indicating whether you want to remove denoise points.

EnableColorPlus

Bool value indicating whether you want to enable color enhancement