Insta360Develop / CameraSDK-Cpp

CameraSDK-Cpp is a C++ library to control Insta360 cameras.
https://www.insta360.com
115 stars 16 forks source link

OneRS SDK - Download file not working #24

Open fgeorges56 opened 1 year ago

fgeorges56 commented 1 year ago

I'm working with the OneRS. My computer has Ubuntu 22.04 Firmware version = 2.0.8.4 Settings > USB mode > Android It is connected to my computer via the original cable.

I am trying to dowload a file from the SD card.

    const auto ret = cam->DownloadCameraFile("/DCIM/Camera01/VID_20230417_135746_10_024.insv", "/home/georges/");
    if (ret) {
        std::cout << "Download succeed!!!" << std::endl;
    } else {
        std::cout << "Download failed!!!" << std::endl;
    }

After a while, I get a 200 HTTP status (looks good) followed by an exception (less good), and I cannot find the file locally.

...
[04-17 17:53:28.382]  40406 40406 I camera_impl.cpp:0345:  Download progress: 99(41938742/41943040)
[04-17 17:53:28.382]  40406 40406 I camera_impl.cpp:0345:  Download progress: 99(41942838/41943040)
[04-17 17:53:28.382]  40406 40406 I camera_impl.cpp:0345:  Download progress: 100(41943040/41943040)
[04-17 17:53:28.382]  40406 40406 I camera_impl.cpp:0349:  HTTP response status: 200
Download succeed!!!
[04-17 17:53:28.382]  40406 40417 E http_tunnel_client.cpp:0124:  exception occurred on socket read some: read_some: End of file

How can I download files from the SD card ?

ricardosutana commented 1 year ago

Hi @fgeorges56 did you could be able to download the file?? I'm in same trouble.

ricardosutana commented 1 year ago

@fgeorges56 `#include

include

//includes for SDK

include <camera/camera.h>

include <camera/device_discovery.h>

include <camera/device_discovery.h>

//includes for openCV

include <opencv2/opencv.hpp>

using namespace std; using namespace cv;

int main() { std::cout << "[INFO]:::Begin camera:::[INFO]" << std::endl; ins_camera::DeviceDiscovery discovery; auto list = discovery.GetAvailableDevices();

try {
    for (int i = 0; i < list.size(); ++i) {
        auto desc = list[i];
        cout <<"[INFO]:::Device Found:::[INFO]"<< "\t"
              <<"serial:" << desc.serial_number << "\t"
              << "camera type:" << int(desc.camera_type) << "\t"
              << "lens type:" << int(desc.lens_type) << endl;
    }
}
catch (exception& e) {
    cout<<"[ERROR]::SDK->Device:::[ERROR]"<<endl;
    if (list.size() <= 0) {
        cerr << "[ERROR]:::No device found:::[ERROR]." << endl;
        return -1;
    }
}
std::shared_ptr<ins_camera::Camera> cam = std::make_shared<ins_camera::Camera>(list[0].info);
//ins_camera::Camera cam(list[0].info);
if (!cam->Open()) {
    cerr << "[ERROR]:::Failed to open camera:::[ERROR]" << endl;
    return -1;
}

// VER SE PRECISO DESTAS CHAMADAS
//std::shared_ptr<ins_camera::StreamDelegate> delegate = std::make_shared<TestStreamDelegate>();
//cam->SetStreamDelegate(delegate);

discovery.FreeDeviceDescriptors(list);

cout << "[INFO]:::Succeed to open camera:::[INFO]" << endl;

auto camera_type = cam->GetCameraType();

auto start = time(NULL);
cam->SyncLocalTimeToCamera(start);

//IMPRIMIR LISTA DE ARQUIVOS DENTRO DA CAMERA

cout<<"[INFO]:::List of files recorded:::[INFO]"<<endl;
const auto file_list = cam->GetCameraFilesList();
for (const auto& file : file_list) {
    cout << "File: " << file << endl;
}
auto tam = file_list.size();

cout<<"[INFO]:::Starting recording:::[INFO]"<<endl;

if (!cam->SetVideoCaptureParams(
   //parameters of cam
        {ins_camera::VideoResolution::RES_3040_3040P24,1024 * 1024 * 10},
                 ins_camera::CameraFunctionMode::FUNCTION_MODE_NORMAL_VIDEO)) {
    cout << "failed to set capture settings." << std::endl;
}
else {
      auto ret = cam->StartRecording();
      if (ret) {
        cout << "success!" << endl;
      }
      else {
            cout << "failed to start recording" << endl;
      }
}
cout<<"[INFO]:::Press 's' to stop recording"<<endl;
char s;
cin >> s;
if (s == 's'){
    auto url = cam->StopRecording();
    if (url.Empty()) {
        std::cerr << "stop recording failed" << std::endl;
        return -1;
    }
    auto& origins = url.OriginUrls();
    std::cout << "stop recording success" << std::endl;
    for (auto& origin_url : origins) {
        std::cout << "url:" << origin_url << std::endl;
    }
    //definição do endereco da camera
    const string remote1 = origins[0];
    const string remote2 = origins[1];
    //definicao do local de destino
    const string local_path1 = "/home/ricardo" + remote1;
    const string local_path2 = "/home/ricardo" + remote2;

    const auto result1 = cam->DownloadCameraFile(remote1, local_path1);
    const auto result2 = cam->DownloadCameraFile(remote2, local_path2);
        if (result1 & result2)
            cout << "Download finised" << endl;
        else
            cout << "Download failed" << endl;

}

return 0;

} `

fgeorges56 commented 1 year ago

Hi @fgeorges56 did you could be able to download the file?? I'm in same trouble.

@ricardosutana yes, in the end it worked. here is the function I used. Note that I have to launch the script as root to make it work.

void download_file(std::shared_ptr<ins_camera::Camera> cam) {
    std::string file_to_download;
    std::string file_to_save;
    std::cout << "please input full file path to download: ";
    std::cin >> file_to_download;
    std::cout << "please input full file path to save: ";
    std::cin >> file_to_save;

    const auto ret = cam->DownloadCameraFile(file_to_download, file_to_save);
    if (ret) {
        std::cout << "Download " << file_to_download << " succeed!" << std::endl;
    } else {
        std::cout << "Download " << file_to_download << " failed!" << std::endl;
    }
};
LoveMYChen commented 1 year ago

sorry,I can not understand! How do you make it success?

fgeorges56 commented 1 year ago

Here is how I compile and execute it.

g++ -I ./camerasdk_linux_20220909/include -L ./camerasdk_linux_20220909/lib ./insta_recorder.cc -Wl,-rpath,lib -l CameraSDK -o insta_recorder_compiled_linux -ludev -lcurses
export LD_LIBRARY_PATH=./camerasdk_linux_20220909/lib
./insta_recorder_compiled_linux
Tianweihaihaihai commented 1 year ago

image

need to use full path including file name and suffix like /1.jpg