Skip to content

Commit 053b31d

Browse files
committed
transcoder_bmf: fix the abnormal progress show when ai processing
Use callback data(frame numbder) from AI module when AI enabled. Signed-off-by: Jack Lau <[email protected]>
1 parent fbd41e6 commit 053b31d

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/modules/enhance_module.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ def __init__(self, node=None, option=None):
6565
Log.log_node(LogLevel.ERROR, self._node, "no option")
6666
return
6767

68+
self.frame_number = 0
69+
6870
tile = option.get("tile", 0)
6971
tile_pad = option.get("tile_pad", 10)
7072
pre_pad = option.get("pre_pad", 10)
@@ -140,5 +142,9 @@ def process(self, task):
140142
output_pkt.timestamp = pkt.timestamp
141143
if output_queue is not None:
142144
output_queue.put(output_pkt)
145+
if self.callback_ is not None:
146+
self.frame_number += 1
147+
message = "frame number: " + str(self.frame_number)
148+
self.callback_(0, bytes(message, "utf-8"))
143149

144150
return ProcessResult.OK

src/transcoder/src/transcoder_bmf.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ bmf_sdk::CBytes TranscoderBMF::encoder_callback(bmf_sdk::CBytes input) {
301301
}
302302

303303
} else {
304-
BMFLOG(BMF_WARNING) << "Failed to extract frame number";
304+
BMFLOG(BMF_WARNING) << "Failed to extract frame number from: " << str_info;
305305
}
306306

307307
uint8_t bytes[] = {97, 98, 99, 100, 101, 0};
@@ -448,7 +448,7 @@ bool TranscoderBMF::transcode(std::string input_path, std::string output_path) {
448448
auto graph = bmf::builder::Graph(bmf::builder::NormalMode);
449449

450450
auto decoder =
451-
graph.Decode(bmf_sdk::JsonParam(decoder_para), "", scheduler_cnt++);
451+
graph.Decode(bmf_sdk::JsonParam(decoder_para), "", scheduler_cnt);
452452

453453
if (algo_mode == AlgoMode::Upscale) {
454454
int upscale_factor = encode_parameter->get_upscale_factor();
@@ -467,13 +467,13 @@ bool TranscoderBMF::transcode(std::string input_path, std::string output_path) {
467467
module_path,
468468
"enhance_module.EnhanceModule",
469469
bmf::builder::Immediate,
470-
scheduler_cnt++));
470+
scheduler_cnt));
471471
}
472472

473473
auto encoder =
474474
graph.Encode(algo_mode == AlgoMode::Upscale ? *algo_node : decoder["video"],
475475
decoder["audio"],
476-
bmf_sdk::JsonParam(encoder_para), "", scheduler_cnt++);
476+
bmf_sdk::JsonParam(encoder_para), "", scheduler_cnt);
477477

478478
auto de_callback = std::bind(&TranscoderBMF::decoder_callback, this,
479479
std::placeholders::_1);
@@ -482,8 +482,13 @@ bool TranscoderBMF::transcode(std::string input_path, std::string output_path) {
482482

483483
decoder.AddCallback(
484484
0, std::function<bmf_sdk::CBytes(bmf_sdk::CBytes)>(de_callback));
485-
encoder.AddCallback(
486-
0, std::function<bmf_sdk::CBytes(bmf_sdk::CBytes)>(en_callback));
485+
if (algo_mode != AlgoMode::None) {
486+
algo_node->AddCallback(
487+
0, std::function<bmf_sdk::CBytes(bmf_sdk::CBytes)>(en_callback));
488+
} else {
489+
encoder.AddCallback(
490+
0, std::function<bmf_sdk::CBytes(bmf_sdk::CBytes)>(en_callback));
491+
}
487492

488493
nlohmann::json graph_para = {{"dump_graph", 1}};
489494
graph.SetOption(bmf_sdk::JsonParam(graph_para));

0 commit comments

Comments
 (0)