Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++ cannot call data push mode #133

Closed
x850044053wwt opened this issue Oct 15, 2024 · 3 comments · Fixed by #155
Closed

C++ cannot call data push mode #133

x850044053wwt opened this issue Oct 15, 2024 · 3 comments · Fixed by #155
Assignees
Labels
api Application Interface enhancement New feature or request good first issue Good for newcomers

Comments

@x850044053wwt
Copy link

x850044053wwt commented Oct 15, 2024

GraphMode中没有数据推送模式枚举。源码中添加对应枚举后,c++没有对应python中的Graph::run_wo_block。执行Graph::run()之后,线程阻塞,无法继续调用FillPacket

@JackLau1222
Copy link
Collaborator

may you provide the cpp demo code?

@x850044053wwt
Copy link
Author

x850044053wwt commented Oct 21, 2024

nlohmann::json graph_para = { {"dump_graph", 1} };
auto graph = bmf::builder::Graph(bmf::builder::PushdataMode, JsonParam(graph_para));
auto video_stream = graph.InputStream("blob_video", "", "");
nlohmann::json option = { { "video_codec", "h264" },
                          {  "video_time_base", "1,30000" },
                          {  "push_raw_stream", 1 } };
auto decode_stream = video_stream.Decode(JsonParam(option));
option = { { "output_path", "D:/output.mp4" },
           { "video_params", {
           {  "codec", "h264" },
           {  "width", 640 },
           {  "height", 480 },
           {  "crf", "23" },
           {  "preset", "veryfast" } } } };
decode_stream.EncodeAsVideo(JsonParam(option));
graph.Start();

@JackLau1222 JackLau1222 added good first issue Good for newcomers enhancement New feature or request labels Nov 28, 2024
@JackLau1222
Copy link
Collaborator

JackLau1222 commented Dec 2, 2024

nlohmann::json graph_para = { {"dump_graph", 1} };
auto graph = bmf::builder::Graph(bmf::builder::PushdataMode, JsonParam(graph_para));
auto video_stream = graph.InputStream("blob_video", "", "");
nlohmann::json option = { { "video_codec", "h264" },
                          {  "video_time_base", "1,30000" },
                          {  "push_raw_stream", 1 } };
auto decode_stream = video_stream.Decode(JsonParam(option));
option = { { "output_path", "D:/output.mp4" },
           { "video_params", {
           {  "codec", "h264" },
           {  "width", 640 },
           {  "height", 480 },
           {  "crf", "23" },
           {  "preset", "veryfast" } } } };
decode_stream.EncodeAsVideo(JsonParam(option));
graph.Start();

Hi, sorry for being late. I just took some time to fix this bug. I noticed that your code didn’t handle the data push correctly. You can refer to my use case for guidance. If you manage to resolve this issue, feel free to submit a patch. I’ll be happy to review and merge it for you.

Here is the my test case:

#include <builder.hpp>
#include "nlohmann/json.hpp"
#include <bmf/sdk/bmf.h>

int main() {
    std::string output_path = "./push_data_output.mp4";

    auto graph = bmf::builder::Graph(bmf::builder::PushDataMode);
    auto video_stream = graph.InputStream("outside_raw_video", "", "");
    nlohmann::json encode_para = {{"output_path", output_path},
                                  {"video_params",
                                   {{"codec", "h264"},
                                    {"width", 640},
                                    {"height", 480},
                                    {"crf", 23},
                                    {"preset", "veryfast"},
                                    {"vsync", "vfr"}}}};
    auto video = graph.Encode(video_stream, bmf_sdk::JsonParam(encode_para));

    graph.Start();

    int count = 50;
    int pts_ = 0;
    while (count > 0) {
        auto frame = VideoFrame(640, 480, PixelInfo(PixelFormat::PF_YUV420P));
        frame.set_pts(pts_);
        pts_++;
        auto packet = Packet(frame);
        count--;
        graph.FillPacket(video_stream.GetName(), packet);
        std::cout << "push data into inputstream" << std::endl;
    }
    auto packet = Packet::generate_eof_packet();
    graph.FillPacket(video_stream.GetName(), packet);

    // graph.Close();

    return 0;
}

BTW, you may need to modify some APIs in C++ so that you can run this case normally

@JackLau1222 JackLau1222 self-assigned this Dec 2, 2024
@JackLau1222 JackLau1222 changed the title C++无法调用数据推送模式 C++ cannot call data push mode Dec 2, 2024
@JackLau1222 JackLau1222 linked a pull request Dec 5, 2024 that will close this issue
@JackLau1222 JackLau1222 added the api Application Interface label Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Application Interface enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants