BabitMF / bmf

Cross-platform, customizable multimedia/video processing framework. With strong GPU acceleration, heterogeneous design, multi-language support, easy to use, multi-framework compatible and high performance, the framework is ideal for transcoding, AI inference, algorithm integration, live video streaming, and more.
https://babitmf.github.io/
Apache License 2.0
807 stars 71 forks source link

参考文档 同步模式 的demo进行测试,无法成功运行 #125

Closed KkemChen closed 4 months ago

KkemChen commented 4 months ago
#include "bmf/sdk/hmp_import.h"
#include "bmf/sdk/json_param.h"
#include "builder.hpp"
#include "nlohmann/json.hpp"
#include "nlohmann/json_fwd.hpp"
#include <bmf/sdk/video_frame.h>
#include <vector>

// std::string input_video_path = "/d1/jntm.mp4";
std::string input_video_path = "/d1/20240529/20240529_093437_1715751852717_000.jpg";

int main() {
    auto graph = bmf::builder::Graph(bmf::builder::NormalMode);

    nlohmann::json decoder_option = {"input_path", input_video_path};

    auto decoder = graph.Sync(std::vector<int>{}, std::vector<int>{0},
                              bmf_sdk::JsonParam(decoder_option), "c_ffmpeg_decoder");

    nlohmann::json scale_option = {
        {"name", "scale"},
        {"para", "320:240"},
    };

    auto scale = graph.Sync(std::vector<int>{0}, std::vector<int>{0},
                            bmf_sdk::JsonParam(scale_option), "c_ffmpeg_filter");

    nlohmann::json encoder_option = {
        {"output_path", "./videoframe.jpg"},
        {"format", "mjpeg"},
        {"video_params",
         {
             {"codec", "jpg"},
         }},
    };

    auto encoder =
        graph.Sync(std::vector<int>{0}, std::vector<int>{},
                   bmf_sdk::JsonParam(encoder_option), "c_ffmpeg_encoder");

    graph.Init(decoder); // decoder.Init();
    graph.Init(scale);   // scale.Init();
    graph.Init(encoder); // encoder.Init();

    // decode
    auto decoded_frames = decoder.ProcessPkts(); // graph.Process(decoder);

    // scale
    bmf::builder::SyncPackets input_scale;
    input_scale.Insert(0, decoded_frames[0]);
    auto scaled_frames = scale.ProcessPkts(input_scale); // graph. Process(scale, input_scale);

    // encode
    bmf::builder::SyncPackets input_encode;
    input_encode.Insert(0, scaled_frames[0]);
    encoder.ProcessPkts(input_encode); // graph.Process(encoder, input_encode);

    encoder.SendEOF(); // graph.SendEOF(encoder);

    graph.Close(decoder); // decoder.Close();
    graph.Close(scale);   // scale. Close();
    graph.Close(encoder); // encoder.Close();
}

gdb调试发现崩在了 auto decoded_frames = decoder.ProcessPkts();的地方。 image

hulibruce commented 4 months ago

nlohmann::json decoder_option = {"input_path", input_video_path}; 需要调整成 nlohmann::json decoder_option = {{"input_path", input_video_path}};

KkemChen commented 4 months ago

nlohmann::json decoder_option = {"input_path", input_video_path}; 需要调整成 nlohmann::json decoder_option = {{"input_path", input_video_path}};

好的,感谢解答🙏