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

[Bug Report] [BuildInModule] [CFFEncoder]Generatormode push_output error when Encode video and audio stream #148

Open
x850044053wwt opened this issue Nov 17, 2024 · 1 comment
Labels
good first issue Good for newcomers

Comments

@x850044053wwt
Copy link

It works fine when encoding one stream separately, but there is a problem when encoding video and audio at the same time

@x850044053wwt
Copy link
Author

std::string input_file = "./big_bunny_1min_30fps.mp4";
std::string output_file = "D:/output.mp4";
nlohmann::json graph_para = { {"dump_graph", 1} };
BMF_CPP_FILE_REMOVE(output_file);
auto graph = bmf::builder::Graph(bmf::builder::GeneratorMode,
bmf_sdk::JsonParam(graph_para));
nlohmann::json decode_para = { {"input_path", input_file} };
auto video = graph.Decode(bmf_sdk::JsonParam(decode_para));
nlohmann::json encode_para = { {"push_output", 1} };
bmf::builder::Stream stream =
graph.Encode(video["video"], video["audio"], bmf_sdk::JsonParam(encode_para));
stream.Start();
std::ofstream outFile(output_file, std::ios::out | std::ios::binary);
while (true) {
Packet pkt = graph.Generate(stream.GetName());
if (pkt.timestamp() == BMF_EOF) {
break;
}
if (pkt.is<BMFAVPacket>() == true) {
BMFAVPacket ppkt = pkt.get<BMFAVPacket>();
int offset = ppkt.get_offset();
int whence = ppkt.get_whence();
void* data = ppkt.data_ptr();
if (offset > 0) {
if (whence == 0) {
outFile.seekp(offset, std::ios_base::beg);
}
else if (whence == 1) {
outFile.seekp(offset, std::ios_base::cur);
}
else if (whence == 2) {
outFile.seekp(offset, std::ios_base::end);
}
}
std::cout << "tby : " << offset << " "
<< " " << whence << " " << ppkt.nbytes() << std::endl;
outFile.write((char*)data, ppkt.nbytes());
}
}
outFile.close();

@x850044053wwt x850044053wwt changed the title Generatormode push_output error when Encode video and audio stream [Bug Report] [BuildInModule] [CFFEncoder]Generatormode push_output error when Encode video and audio stream Nov 17, 2024
@JackLau1222 JackLau1222 added the good first issue Good for newcomers label Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants