From 4ca3256865b7d9f37de0eddbcce6b18ab70a20fc Mon Sep 17 00:00:00 2001 From: JackLau1222 <2366536135@qq.com> Date: Tue, 31 Dec 2024 08:24:30 +0800 Subject: [PATCH 01/17] * add activate environment sh * update .gitignore * optimize transcode.py for callback develop --- .gitignore | 4 ++++ activate_env.sh | 7 +++++++ bmf/demo/transcode/transcode.py | 17 +++++++++-------- 3 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 activate_env.sh diff --git a/.gitignore b/.gitignore index ec59f314..2b002712 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,10 @@ *.so *.sym /build*/ +CMakeFiles +_deps +bmf/files* +bmf/demo/transcode/*.mp4 !build.gradle bmf/c_module_sdk/build bmf/c_module_sdk/cmake-build-debug diff --git a/activate_env.sh b/activate_env.sh new file mode 100644 index 00000000..457d4081 --- /dev/null +++ b/activate_env.sh @@ -0,0 +1,7 @@ +export C_INCLUDE_PATH=${C_INCLUDE_PATH}:$(pwd)/output/bmf/include +export CPLUS_INCLUDE_PATH=${CPLUS_INCLUDE_PATH}:$(pwd)/output/bmf/include +export LIBRARY_PATH=${LIBRARY_PATH}:$(pwd)/output/bmf/lib +export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$(pwd)/output/bmf/lib + +# only set if you want to use BMF in python +export PYTHONPATH=$(pwd)/output/bmf/lib:$(pwd)/output diff --git a/bmf/demo/transcode/transcode.py b/bmf/demo/transcode/transcode.py index d6b94c45..adbe653e 100644 --- a/bmf/demo/transcode/transcode.py +++ b/bmf/demo/transcode/transcode.py @@ -148,7 +148,7 @@ def test_video(): def test_cb(): - input_video_path = "../../files/img.mp4" + input_video_path = "../../files/big_bunny_10s_30fps.mp4" output_path = "./cb.mp4" expect_result = '../transcode/cb.mp4|240|320|7.615000|MOV,MP4,M4A,3GP,3G2,MJ2|366635|348991|h264|' \ '{"fps": "30.0662251656"}' @@ -156,14 +156,13 @@ def test_cb(): graph = bmf.graph() def cb(para): - print(para) - - graph.add_user_callback(bmf.BmfCallBackType.LATEST_TIMESTAMP, cb) + print("====CallBack====", para) + return bytes("OK", "ASCII") # decode video = graph.decode({"input_path": input_video_path}) - (bmf.encode( + bmf.encode( video['video'], video['audio'], { "output_path": output_path, "video_params": { @@ -173,7 +172,9 @@ def cb(para): "crf": "23", "preset": "veryfast" } - }).run()) + }).node_.add_user_callback(bmf.BmfCallBackType.LATEST_TIMESTAMP, cb) + + graph.run() def compareProfile(graph_file): @@ -235,5 +236,5 @@ def compare(): # test_simple() # test_audio() # test_video() - # test_cb() - compare() + test_cb() + # compare() From 0a39a59b8e0fac4442bc3d0bf27f27e97eb2a335 Mon Sep 17 00:00:00 2001 From: JackLau1222 <2366536135@qq.com> Date: Tue, 31 Dec 2024 11:51:36 +0800 Subject: [PATCH 02/17] * update callback function of builtin decoder and encoder --- .gitignore | 1 + bmf/c_modules/include/ffmpeg_decoder.h | 5 +++++ bmf/c_modules/include/ffmpeg_encoder.h | 2 ++ bmf/c_modules/src/ffmpeg_decoder.cpp | 11 +++++++++++ bmf/c_modules/src/ffmpeg_encoder.cpp | 16 +++++++++------- bmf/demo/transcode/transcode.py | 4 +++- 6 files changed, 31 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 2b002712..1f06c008 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ CMakeFiles _deps bmf/files* bmf/demo/transcode/*.mp4 +bmf/test/distributed_node/build/* !build.gradle bmf/c_module_sdk/build bmf/c_module_sdk/cmake-build-debug diff --git a/bmf/c_modules/include/ffmpeg_decoder.h b/bmf/c_modules/include/ffmpeg_decoder.h index f0e17ae6..21191ff5 100644 --- a/bmf/c_modules/include/ffmpeg_decoder.h +++ b/bmf/c_modules/include/ffmpeg_decoder.h @@ -173,6 +173,8 @@ class CFFDecoder : public Module { int orig_pts_time_ = 0; + std::function callback_endpoint_; + int process_raw_stream_packet(Task &task, BMFAVPacket &bmf_pkt, bool eof); int process_input_bmf_av_packet(Task &task); @@ -234,6 +236,9 @@ class CFFDecoder : public Module { int read_packet(uint8_t *buf, int buf_size); int pkt_ts(AVPacket *pkt, int index); + + void set_callback( + std::function callback_endpoint) override; }; /** @page ModuleDecoder Build-in Decode Module * @ingroup DecM diff --git a/bmf/c_modules/include/ffmpeg_encoder.h b/bmf/c_modules/include/ffmpeg_encoder.h index 603c26c5..a3ed6116 100644 --- a/bmf/c_modules/include/ffmpeg_encoder.h +++ b/bmf/c_modules/include/ffmpeg_encoder.h @@ -138,6 +138,8 @@ class CFFEncoder : public Module { CurrentImage2Buffer current_image_buffer_ = {0}; bool copy_ts_ = false; bool has_complex_filtergraph_ = false; + // use for callback to get the frame number + int frame_number = 0; public: CFFEncoder(int node_id, JsonParam option); diff --git a/bmf/c_modules/src/ffmpeg_decoder.cpp b/bmf/c_modules/src/ffmpeg_decoder.cpp index fe2de016..79726cf6 100644 --- a/bmf/c_modules/src/ffmpeg_decoder.cpp +++ b/bmf/c_modules/src/ffmpeg_decoder.cpp @@ -2468,6 +2468,12 @@ int CFFDecoder::process(Task &task) { init_input(dec_opts_); } + if (callback_endpoint_ != NULL) { + std::string info = "total frame number: " + std::to_string(video_stream_->nb_frames); + auto para = CBytes::make((uint8_t *)info.c_str(), info.size()); + callback_endpoint_(0, para); + } + if (!input_fmt_ctx_) { BMFLOG_NODE(BMF_WARNING, node_id_) << "decoder input_fmt_ctx_ is not ready or might be free"; @@ -2524,6 +2530,11 @@ int CFFDecoder::process(Task &task) { return PROCESS_OK; } +void CFFDecoder::set_callback( + std::function callback_endpoint) { + callback_endpoint_ = callback_endpoint; +} + REGISTER_MODULE_CLASS(CFFDecoder) REGISTER_MODULE_INFO(CFFDecoder, info) { info.module_description = "Builtin FFmpeg-based decoding module."; diff --git a/bmf/c_modules/src/ffmpeg_encoder.cpp b/bmf/c_modules/src/ffmpeg_encoder.cpp index f1cfb314..b63a15ff 100644 --- a/bmf/c_modules/src/ffmpeg_encoder.cpp +++ b/bmf/c_modules/src/ffmpeg_encoder.cpp @@ -412,13 +412,15 @@ int CFFEncoder::handle_output(AVPacket *hpkt, int idx) { if (idx == 0) { if (callback_endpoint_ != NULL) { - float curr_time = - (in_stream_tbs_[0].den > 0 && in_stream_tbs_[0].num > 0) - ? float(pkt->pts * in_stream_tbs_[0].num / - in_stream_tbs_[0].den) - : 0; - - std::string info = "pts: " + std::to_string(curr_time); + // float curr_time = + // (in_stream_tbs_[0].den > 0 && in_stream_tbs_[0].num > 0) + // ? float(pkt->pts * in_stream_tbs_[0].num / + // in_stream_tbs_[0].den) + // : 0; + + // std::string info = "pts: " + std::to_string(curr_time); + std::string info = "pts: " + std::to_string(pkt->pts) + " dts: " + std::to_string(pkt->dts) + +" frame number: "+ std::to_string(++frame_number); auto para = CBytes::make((uint8_t *)info.c_str(), info.size()); callback_endpoint_(0, para); } diff --git a/bmf/demo/transcode/transcode.py b/bmf/demo/transcode/transcode.py index adbe653e..025a2e06 100644 --- a/bmf/demo/transcode/transcode.py +++ b/bmf/demo/transcode/transcode.py @@ -156,12 +156,14 @@ def test_cb(): graph = bmf.graph() def cb(para): - print("====CallBack====", para) + print("====CallBack====", para.decode('UTF-8')) return bytes("OK", "ASCII") # decode video = graph.decode({"input_path": input_video_path}) + video.node_.add_user_callback(bmf.BmfCallBackType.LATEST_TIMESTAMP, cb) + bmf.encode( video['video'], video['audio'], { "output_path": output_path, From 1e1b7ee05921c4da3785c8edb28543f31779155b Mon Sep 17 00:00:00 2001 From: JackLau1222 <2366536135@qq.com> Date: Tue, 31 Dec 2024 11:54:17 +0800 Subject: [PATCH 03/17] * update activate_env.sh for macos * update distributed_node cmake --- activate_env.sh | 1 + bmf/test/distributed_node/CMakeLists.txt | 13 ++----------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/activate_env.sh b/activate_env.sh index 457d4081..2b829bbb 100644 --- a/activate_env.sh +++ b/activate_env.sh @@ -5,3 +5,4 @@ export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$(pwd)/output/bmf/lib # only set if you want to use BMF in python export PYTHONPATH=$(pwd)/output/bmf/lib:$(pwd)/output +export DYLD_LIBRARY_PATH=~/Documents/Programs/Git/Github/bmf/output/bmf/lib diff --git a/bmf/test/distributed_node/CMakeLists.txt b/bmf/test/distributed_node/CMakeLists.txt index 21de6d95..0111cf2e 100644 --- a/bmf/test/distributed_node/CMakeLists.txt +++ b/bmf/test/distributed_node/CMakeLists.txt @@ -5,15 +5,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED True) # Set compiler flags set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -fPIC") -# Include directories -include_directories( - /root/workspace/bmf_OSPP/output/bmf/include - . -) - -# Link directories -link_directories(/root/workspace/bmf_OSPP/output/bmf/lib) - # Source files # set(LIB_SRCS_SPLIT split_module.cpp) set(LIB_SRCS_COPY copy_module.cpp) @@ -27,12 +18,12 @@ add_library(copy_module SHARED ${LIB_SRCS_COPY}) # Link the external libraries to the modules # target_link_libraries(split_module engine bmf_module_sdk) -target_link_libraries(copy_module engine bmf_module_sdk) +target_link_libraries(copy_module engine bmf_module_sdk hmp) # target_link_libraries(assemble_module engine bmf_module_sdk) # Create the executable and link the shared libraries add_executable(cpp_demo ${MAIN_SRCS}) -target_link_libraries(cpp_demo copy_module engine bmf_module_sdk) +target_link_libraries(cpp_demo copy_module engine bmf_module_sdk hmp) # Clean up build files set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "cpp_demo") From 62a0009ad60f2e3f9ffc643ab7a01ecd0aca544b Mon Sep 17 00:00:00 2001 From: JackLau1222 <2366536135@qq.com> Date: Sat, 4 Jan 2025 08:56:26 +0800 Subject: [PATCH 04/17] fix module callback in cpp --- .gitignore | 3 + bmf/builder/bmf_graph.py | 1 + bmf/demo/transcode/build.sh | 1 + bmf/demo/transcode/test_cb.cpp | 53 +++++++++++++ bmf/demo/transcode/transcode.py | 1 + bmf/engine/connector/include/builder.hpp | 6 ++ bmf/engine/connector/src/builder.cpp | 19 ++++- bmf/test/cpp_builder/cpp_transcode.cpp | 94 ++++++++++++------------ 8 files changed, 129 insertions(+), 49 deletions(-) create mode 100644 bmf/demo/transcode/build.sh create mode 100644 bmf/demo/transcode/test_cb.cpp diff --git a/.gitignore b/.gitignore index 1f06c008..23358c51 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,9 @@ _deps bmf/files* bmf/demo/transcode/*.mp4 bmf/test/distributed_node/build/* +bmf/demo/transcode/*.json +bmf/demo/transcode/test_cb +bmf/demo/transcode/test_cb.d* !build.gradle bmf/c_module_sdk/build bmf/c_module_sdk/cmake-build-debug diff --git a/bmf/builder/bmf_graph.py b/bmf/builder/bmf_graph.py index 749b2985..b6c71d68 100644 --- a/bmf/builder/bmf_graph.py +++ b/bmf/builder/bmf_graph.py @@ -511,6 +511,7 @@ def generate_meta_info_config(pre_module, callback_dict): # set callback function for key, callback in callback_dict.items(): callback_binding = "{}:{}".format(key, callback[0]) + print(callback_binding) meta_info_config.add_callback_binding(callback_binding) return meta_info_config diff --git a/bmf/demo/transcode/build.sh b/bmf/demo/transcode/build.sh new file mode 100644 index 00000000..e41e1260 --- /dev/null +++ b/bmf/demo/transcode/build.sh @@ -0,0 +1 @@ +g++ -std=c++17 -g -o test_cb test_cb.cpp -L/Users/jacklau/Documents/Programs/Git/Github/bmf/output/bmf/lib -lengine -lbmf_module_sdk -lhmp diff --git a/bmf/demo/transcode/test_cb.cpp b/bmf/demo/transcode/test_cb.cpp new file mode 100644 index 00000000..7f38624d --- /dev/null +++ b/bmf/demo/transcode/test_cb.cpp @@ -0,0 +1,53 @@ +#include "builder.hpp" +#include "nlohmann/json.hpp" +#include "connector.hpp" +// #include "../../engine/c_engine/include/callback_layer.h" + +bmf_sdk::CBytes my_callback_function(bmf_sdk::CBytes input) { + std::string strInfo; + strInfo.assign(reinterpret_cast(input.buffer), input.size); + BMFLOG(BMF_INFO) << "====Callback==== " << strInfo; + uint8_t bytes[] = {97, 98, 99, 100, 101, 0}; + return bmf_sdk::CBytes{bytes, 6}; +} + +int main() { + std::string output_file = "./cb.mp4"; + + nlohmann::json graph_para = { + {"dump_graph", 0} + }; + auto graph = bmf::builder::Graph(bmf::builder::NormalMode, + bmf_sdk::JsonParam(graph_para)); + + nlohmann::json decode_para = { + {"input_path", "../../files/big_bunny_10s_30fps.mp4"}, + }; + auto video = graph.Decode(bmf_sdk::JsonParam(decode_para)); + nlohmann::json encode_para = { + {"output_path", output_file}, + {"video_params", { + {"codec", "h264"}, + {"width", 320}, + {"height", 240}, + {"crf", 23}, + {"preset", "veryfast"} + }}, + {"audio_params", { + {"codec", "aac"}, + {"bit_rate", 128000}, + {"sample_rate", 44100}, + {"channels", 2} + }} + }; + + std::function callback = my_callback_function; + + auto node = graph.Encode(video["video"], video["audio"], + bmf_sdk::JsonParam(encode_para)); + + node.AddCallback(0, callback); + + graph.Run(); + +} \ No newline at end of file diff --git a/bmf/demo/transcode/transcode.py b/bmf/demo/transcode/transcode.py index 025a2e06..c2fe6ced 100644 --- a/bmf/demo/transcode/transcode.py +++ b/bmf/demo/transcode/transcode.py @@ -176,6 +176,7 @@ def cb(para): } }).node_.add_user_callback(bmf.BmfCallBackType.LATEST_TIMESTAMP, cb) + graph.option_["dump_graph"] = 1 graph.run() diff --git a/bmf/engine/connector/include/builder.hpp b/bmf/engine/connector/include/builder.hpp index a141a026..0eb06a62 100644 --- a/bmf/engine/connector/include/builder.hpp +++ b/bmf/engine/connector/include/builder.hpp @@ -141,6 +141,9 @@ class RealNode : public std::enable_shared_from_this { void AddCallback(long long key, bmf::BMFCallback callbackInstance); + void AddCallback(long long key, + std::function callback); + nlohmann::json Dump(); std::shared_ptr @@ -451,6 +454,9 @@ class BMF_ENGINE_API Node { void AddCallback(long long key, const bmf::BMFCallback &callbackInstance); + void AddCallback(long long key, + std::function callback); + void Start(); Node Module( diff --git a/bmf/engine/connector/src/builder.cpp b/bmf/engine/connector/src/builder.cpp index 06f0ae82..35e48950 100644 --- a/bmf/engine/connector/src/builder.cpp +++ b/bmf/engine/connector/src/builder.cpp @@ -133,9 +133,12 @@ nlohmann::json RealNode::NodeMetaInfo::Dump() { nlohmann::json info; info["premodule_id"] = preModuleUID_; - info["callback_bindings"] = nlohmann::json::object(); + info["callback_binding"] = + nlohmann::json(std::vector()); for (auto &kv : callbackBinding_) { - info["callback_bindings"][kv.first] = kv.second; + info["callback_binding"].push_back( + std::to_string(kv.first) + ":" + std::to_string(kv.second) + ); } return info; @@ -228,6 +231,12 @@ void RealNode::AddCallback(long long key, bmf::BMFCallback callbackInstance) { std::make_shared(callbackInstance); metaInfo_.callbackBinding_[key] = callbackInstance.uid(); } +void RealNode::AddCallback(long long key, std::function callback) { + auto cb = bmf::BMFCallback(callback); + metaInfo_.callbackInstances_[key] = + std::make_shared(cb); + metaInfo_.callbackBinding_[key] = cb.uid(); +} std::shared_ptr RealNode::AddModule(std::string const &alias, const bmf_sdk::JsonParam &option, @@ -666,6 +675,12 @@ void Node::AddCallback(long long key, baseP_->AddCallback(key, callbackInstance); } +void Node::AddCallback(long long key, + std::function callback) { + std::cout << "===CallBack==== Node::AddCallback" << &callback << std::endl; + baseP_->AddCallback(key, callback); +} + void Node::Start() { Stream(0).Start(); } Node Node::Module(const std::vector &inStreams, diff --git a/bmf/test/cpp_builder/cpp_transcode.cpp b/bmf/test/cpp_builder/cpp_transcode.cpp index 7d24d6bb..d59423c2 100644 --- a/bmf/test/cpp_builder/cpp_transcode.cpp +++ b/bmf/test/cpp_builder/cpp_transcode.cpp @@ -318,53 +318,53 @@ TEST(cpp_transcode, transcode_with_null_audio) { " \"30.0662251656\"}"); } -// TEST(cpp_transcode, transcode_cb) { -// std::string output_file = "./cb.mp4"; -// BMF_CPP_FILE_REMOVE(output_file); - -// nlohmann::json graph_para = { -// {"dump_graph", 0} -// }; -// auto graph = bmf::builder::Graph(bmf::builder::NormalMode, -// bmf_sdk::JsonParam(graph_para)); - -// nlohmann::json decode_para = { -// {"input_path", "../../files/big_bunny_10s_30fps.mp4"}, -// }; -// auto video = graph.Decode(bmf_sdk::JsonParam(decode_para)); -// nlohmann::json encode_para = { -// {"output_path", output_file}, -// {"video_params", { -// {"codec", "h264"}, -// {"width", 320}, -// {"height", 240}, -// {"crf", 23}, -// {"preset", "veryfast"} -// }}, -// {"audio_params", { -// {"codec", "aac"}, -// {"bit_rate", 128000}, -// {"sample_rate", 44100}, -// {"channels", 2} -// }} -// }; -// auto cb = [](void *, BMFCBytes) -> BMFCBytes { -// BMFLOG(BMF_INFO) << "test cb cpp"; -// uint8_t bytes[] = {97, 98, 99, 100, 101, 0}; -// return BMFCBytes{bytes, 6}; -// }; -// BMFCallbackInstance cb_ = nullptr; -// create_callback(cb, nullptr, &cb_); -// graph.Encode(video["video"], video["audio"], -// bmf_sdk::JsonParam(encode_para)).AddCallback(0, *cb_); -// //std::cout << testing::internal::GetCapturedStdout(); -// graph.Run(); -// BMF_CPP_FILE_CHECK( -// output_file, -// "../transcode/cb.mp4|240|320|7.615000|MOV,MP4,M4A,3GP,3G2,MJ2|366635|348991|h264|{\"fps\": -// \"30.0662251656\"}" -// ); -// } +TEST(cpp_transcode, transcode_cb) { + std::string output_file = "./cb.mp4"; + BMF_CPP_FILE_REMOVE(output_file); + + nlohmann::json graph_para = { + {"dump_graph", 0} + }; + auto graph = bmf::builder::Graph(bmf::builder::NormalMode, + bmf_sdk::JsonParam(graph_para)); + + nlohmann::json decode_para = { + {"input_path", "../../files/big_bunny_10s_30fps.mp4"}, + }; + auto video = graph.Decode(bmf_sdk::JsonParam(decode_para)); + nlohmann::json encode_para = { + {"output_path", output_file}, + {"video_params", { + {"codec", "h264"}, + {"width", 320}, + {"height", 240}, + {"crf", 23}, + {"preset", "veryfast"} + }}, + {"audio_params", { + {"codec", "aac"}, + {"bit_rate", 128000}, + {"sample_rate", 44100}, + {"channels", 2} + }} + }; + auto cb = [](void *, BMFCBytes) -> BMFCBytes { + BMFLOG(BMF_INFO) << "test cb cpp"; + uint8_t bytes[] = {97, 98, 99, 100, 101, 0}; + return BMFCBytes{bytes, 6}; + }; + BMFCallbackInstance cb_ = nullptr; + create_callback(cb, nullptr, &cb_); + graph.Encode(video["video"], video["audio"], + bmf_sdk::JsonParam(encode_para)).AddCallback(0, *cb_); + //std::cout << testing::internal::GetCapturedStdout(); + graph.Run(); + BMF_CPP_FILE_CHECK( + output_file, + "../transcode/cb.mp4|240|320|7.615000|MOV,MP4,M4A,3GP,3G2,MJ2|366635|348991|h264|{\"fps\": + \"30.0662251656\"}" + ); +} TEST(cpp_transcode, transcode_hls) { std::string output_file = "./file000.ts"; From e239d8630ae77eca739e0c67a2e085c968941db7 Mon Sep 17 00:00:00 2001 From: JackLau1222 <2366536135@qq.com> Date: Sat, 4 Jan 2025 09:00:37 +0800 Subject: [PATCH 05/17] fix typo --- bmf/demo/transcode/test_cb.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/bmf/demo/transcode/test_cb.cpp b/bmf/demo/transcode/test_cb.cpp index 7f38624d..2e538c86 100644 --- a/bmf/demo/transcode/test_cb.cpp +++ b/bmf/demo/transcode/test_cb.cpp @@ -1,7 +1,6 @@ #include "builder.hpp" #include "nlohmann/json.hpp" #include "connector.hpp" -// #include "../../engine/c_engine/include/callback_layer.h" bmf_sdk::CBytes my_callback_function(bmf_sdk::CBytes input) { std::string strInfo; From d4a6065a622ac1e5a8d38948f6646fb83e7cb318 Mon Sep 17 00:00:00 2001 From: JackLau1222 <2366536135@qq.com> Date: Sun, 5 Jan 2025 13:44:07 +0800 Subject: [PATCH 06/17] update test case --- bmf/demo/transcode/test_cb.cpp | 108 +++++++++++++++++++++++-- bmf/test/cpp_builder/cpp_transcode.cpp | 94 ++++++++++----------- build_osx.sh | 2 + 3 files changed, 150 insertions(+), 54 deletions(-) diff --git a/bmf/demo/transcode/test_cb.cpp b/bmf/demo/transcode/test_cb.cpp index 2e538c86..debbe318 100644 --- a/bmf/demo/transcode/test_cb.cpp +++ b/bmf/demo/transcode/test_cb.cpp @@ -2,10 +2,101 @@ #include "nlohmann/json.hpp" #include "connector.hpp" -bmf_sdk::CBytes my_callback_function(bmf_sdk::CBytes input) { +#include + +// Global variable or pass-by-reference as needed +int frame_number_total = 0; +int frame_number_global = 0; + +int process_number = 0; +double rest_time = 0; + +std::chrono::system_clock::time_point last_encoder_call; // Track last call time +bool first_encoder_call = true; // Flag for first call + +std::vector duration_history; // Store recent durations for averaging +constexpr size_t max_history_size = 20; // Limit for the number of durations tracked +constexpr double min_duration_threshold = 10.0; // Ignore durations < 10 ms + +double compute_smooth_duration(double new_duration) { + if (new_duration >= min_duration_threshold) { + duration_history.push_back(new_duration); + if (duration_history.size() > max_history_size) { + duration_history.erase(duration_history.begin()); + } + } + return duration_history.empty() ? 0.0 : + std::accumulate(duration_history.begin(), duration_history.end(), 0.0) / duration_history.size(); +} + +// std::string format_time(const std::tm& tm) { +// char buffer[20]; // Buffer to hold formatted time string +// std::snprintf(buffer, sizeof(buffer), "%04d-%02d-%02d %02d:%02d:%02d", +// tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, +// tm.tm_hour, tm.tm_min, tm.tm_sec); +// return std::string(buffer); +// } + +bmf_sdk::CBytes decoder_callback(bmf_sdk::CBytes input) { std::string strInfo; strInfo.assign(reinterpret_cast(input.buffer), input.size); - BMFLOG(BMF_INFO) << "====Callback==== " << strInfo; + // BMFLOG(BMF_INFO) << "====Callback==== " << strInfo; + + + std::regex frame_regex(R"(\btotal frame number:\s*(\d+))"); + std::smatch match; + + if (std::regex_search(strInfo, match, frame_regex) && match.size() > 1) { + std::istringstream(match[1]) >> frame_number_total; // Convert to int + BMFLOG(BMF_DEBUG) << "Extracted Frame Number: " << frame_number_total; + } else { + BMFLOG(BMF_WARNING) << "Failed to extract frame number"; + } + + uint8_t bytes[] = {97, 98, 99, 100, 101, 0}; + return bmf_sdk::CBytes{bytes, 6}; +} + +bmf_sdk::CBytes encoder_callback(bmf_sdk::CBytes input) { + std::string strInfo; + strInfo.assign(reinterpret_cast(input.buffer), input.size); + // BMFLOG(BMF_INFO) << "====Callback==== " << strInfo; + + std::regex frame_regex(R"(\bframe number:\s*(\d+))"); + std::smatch match; + + if (std::regex_search(strInfo, match, frame_regex) && match.size() > 1) { + std::istringstream(match[1]) >> frame_number_global; // Convert to int + BMFLOG(BMF_DEBUG) << "Extracted Total Frame Number: " << frame_number_global; + process_number = frame_number_global * 100 / frame_number_total; + + static auto last_encoder_call_time = std::chrono::system_clock::now(); + auto now = std::chrono::system_clock::now(); + + auto duration = std::chrono::duration_cast(now - last_encoder_call_time).count(); + last_encoder_call_time = now; + + double smooth_duration = compute_smooth_duration(duration); + if (frame_number_global > 0 && frame_number_total > 0) { + // double progress = static_cast(frame_number_global) / frame_number_total; + rest_time = smooth_duration * (frame_number_total-frame_number_global) / 1000; + } + + BMFLOG(BMF_INFO) << "Process Number (percentage): " << process_number << "%\t" + << "Current duration (milliseconds): " << duration << "\t" + << "Smoothed Duration: " << smooth_duration << " ms\t" + << "Estimated Rest Time (seconds): " << rest_time; + + + + if (frame_number_global == frame_number_total) { + BMFLOG(BMF_INFO) << "====Callback==== Finish"; + } + + } else { + BMFLOG(BMF_WARNING) << "Failed to extract frame number"; + } + uint8_t bytes[] = {97, 98, 99, 100, 101, 0}; return bmf_sdk::CBytes{bytes, 6}; } @@ -13,6 +104,9 @@ bmf_sdk::CBytes my_callback_function(bmf_sdk::CBytes input) { int main() { std::string output_file = "./cb.mp4"; + std::function de_callback = decoder_callback; + std::function en_callback = encoder_callback; + nlohmann::json graph_para = { {"dump_graph", 0} }; @@ -23,14 +117,14 @@ int main() { {"input_path", "../../files/big_bunny_10s_30fps.mp4"}, }; auto video = graph.Decode(bmf_sdk::JsonParam(decode_para)); + video.AddCallback(0, std::function(decoder_callback)); + nlohmann::json encode_para = { {"output_path", output_file}, {"video_params", { {"codec", "h264"}, - {"width", 320}, - {"height", 240}, {"crf", 23}, - {"preset", "veryfast"} + {"preset", "veryslow"} }}, {"audio_params", { {"codec", "aac"}, @@ -40,12 +134,12 @@ int main() { }} }; - std::function callback = my_callback_function; + auto node = graph.Encode(video["video"], video["audio"], bmf_sdk::JsonParam(encode_para)); - node.AddCallback(0, callback); + node.AddCallback(0, en_callback); graph.Run(); diff --git a/bmf/test/cpp_builder/cpp_transcode.cpp b/bmf/test/cpp_builder/cpp_transcode.cpp index d59423c2..7d24d6bb 100644 --- a/bmf/test/cpp_builder/cpp_transcode.cpp +++ b/bmf/test/cpp_builder/cpp_transcode.cpp @@ -318,53 +318,53 @@ TEST(cpp_transcode, transcode_with_null_audio) { " \"30.0662251656\"}"); } -TEST(cpp_transcode, transcode_cb) { - std::string output_file = "./cb.mp4"; - BMF_CPP_FILE_REMOVE(output_file); - - nlohmann::json graph_para = { - {"dump_graph", 0} - }; - auto graph = bmf::builder::Graph(bmf::builder::NormalMode, - bmf_sdk::JsonParam(graph_para)); - - nlohmann::json decode_para = { - {"input_path", "../../files/big_bunny_10s_30fps.mp4"}, - }; - auto video = graph.Decode(bmf_sdk::JsonParam(decode_para)); - nlohmann::json encode_para = { - {"output_path", output_file}, - {"video_params", { - {"codec", "h264"}, - {"width", 320}, - {"height", 240}, - {"crf", 23}, - {"preset", "veryfast"} - }}, - {"audio_params", { - {"codec", "aac"}, - {"bit_rate", 128000}, - {"sample_rate", 44100}, - {"channels", 2} - }} - }; - auto cb = [](void *, BMFCBytes) -> BMFCBytes { - BMFLOG(BMF_INFO) << "test cb cpp"; - uint8_t bytes[] = {97, 98, 99, 100, 101, 0}; - return BMFCBytes{bytes, 6}; - }; - BMFCallbackInstance cb_ = nullptr; - create_callback(cb, nullptr, &cb_); - graph.Encode(video["video"], video["audio"], - bmf_sdk::JsonParam(encode_para)).AddCallback(0, *cb_); - //std::cout << testing::internal::GetCapturedStdout(); - graph.Run(); - BMF_CPP_FILE_CHECK( - output_file, - "../transcode/cb.mp4|240|320|7.615000|MOV,MP4,M4A,3GP,3G2,MJ2|366635|348991|h264|{\"fps\": - \"30.0662251656\"}" - ); -} +// TEST(cpp_transcode, transcode_cb) { +// std::string output_file = "./cb.mp4"; +// BMF_CPP_FILE_REMOVE(output_file); + +// nlohmann::json graph_para = { +// {"dump_graph", 0} +// }; +// auto graph = bmf::builder::Graph(bmf::builder::NormalMode, +// bmf_sdk::JsonParam(graph_para)); + +// nlohmann::json decode_para = { +// {"input_path", "../../files/big_bunny_10s_30fps.mp4"}, +// }; +// auto video = graph.Decode(bmf_sdk::JsonParam(decode_para)); +// nlohmann::json encode_para = { +// {"output_path", output_file}, +// {"video_params", { +// {"codec", "h264"}, +// {"width", 320}, +// {"height", 240}, +// {"crf", 23}, +// {"preset", "veryfast"} +// }}, +// {"audio_params", { +// {"codec", "aac"}, +// {"bit_rate", 128000}, +// {"sample_rate", 44100}, +// {"channels", 2} +// }} +// }; +// auto cb = [](void *, BMFCBytes) -> BMFCBytes { +// BMFLOG(BMF_INFO) << "test cb cpp"; +// uint8_t bytes[] = {97, 98, 99, 100, 101, 0}; +// return BMFCBytes{bytes, 6}; +// }; +// BMFCallbackInstance cb_ = nullptr; +// create_callback(cb, nullptr, &cb_); +// graph.Encode(video["video"], video["audio"], +// bmf_sdk::JsonParam(encode_para)).AddCallback(0, *cb_); +// //std::cout << testing::internal::GetCapturedStdout(); +// graph.Run(); +// BMF_CPP_FILE_CHECK( +// output_file, +// "../transcode/cb.mp4|240|320|7.615000|MOV,MP4,M4A,3GP,3G2,MJ2|366635|348991|h264|{\"fps\": +// \"30.0662251656\"}" +// ); +// } TEST(cpp_transcode, transcode_hls) { std::string output_file = "./file000.ts"; diff --git a/build_osx.sh b/build_osx.sh index 589e9be7..94db2028 100755 --- a/build_osx.sh +++ b/build_osx.sh @@ -17,6 +17,8 @@ then if [ "$1" = "clean" ] then rm -rf build_osx + rm -rf output + rm -rf CMakeFiles exit fi From c35f49399a93465838ead4b8b91969f0543e0495 Mon Sep 17 00:00:00 2001 From: JackLau1222 <2366536135@qq.com> Date: Sun, 5 Jan 2025 13:59:40 +0800 Subject: [PATCH 07/17] update shell info --- activate_env.sh | 2 ++ bmf/demo/transcode/build.sh | 1 + 2 files changed, 3 insertions(+) diff --git a/activate_env.sh b/activate_env.sh index 2b829bbb..73d98a68 100644 --- a/activate_env.sh +++ b/activate_env.sh @@ -1,3 +1,5 @@ +#!/bin/bash +# set the environment variables for bmf export C_INCLUDE_PATH=${C_INCLUDE_PATH}:$(pwd)/output/bmf/include export CPLUS_INCLUDE_PATH=${CPLUS_INCLUDE_PATH}:$(pwd)/output/bmf/include export LIBRARY_PATH=${LIBRARY_PATH}:$(pwd)/output/bmf/lib diff --git a/bmf/demo/transcode/build.sh b/bmf/demo/transcode/build.sh index e41e1260..bc4d571e 100644 --- a/bmf/demo/transcode/build.sh +++ b/bmf/demo/transcode/build.sh @@ -1 +1,2 @@ +#!/bin/bash g++ -std=c++17 -g -o test_cb test_cb.cpp -L/Users/jacklau/Documents/Programs/Git/Github/bmf/output/bmf/lib -lengine -lbmf_module_sdk -lhmp From 8570d37cae4f99cc94a28e9f9b462156960a35bf Mon Sep 17 00:00:00 2001 From: Jack Lau <2366536135@qq.com> Date: Mon, 6 Jan 2025 15:58:06 +0800 Subject: [PATCH 08/17] Update version.sh --- version.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/version.sh b/version.sh index 462ab6a0..32057e05 100644 --- a/version.sh +++ b/version.sh @@ -1,4 +1,5 @@ #!/bin/bash +#!test if [[ $OS == *Windows* ]]; then BMF_BUILD_VERSION=$(python setup.py --version) From b907d59a8bd3de8b9629fb63996e1103514e88c0 Mon Sep 17 00:00:00 2001 From: JackLau1222 <2366536135@qq.com> Date: Tue, 7 Jan 2025 09:44:27 +0800 Subject: [PATCH 09/17] * fix issue of the compare std::function to NULL * change the default ffmpeg build version to 5.1.6 --- bmf/c_modules/src/ffmpeg_decoder.cpp | 2 +- bmf/c_modules/src/ffmpeg_encoder.cpp | 2 +- scripts/build_ffmpeg.sh | 41 ++++++++++++++++++++++------ 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/bmf/c_modules/src/ffmpeg_decoder.cpp b/bmf/c_modules/src/ffmpeg_decoder.cpp index 79726cf6..32774e7e 100644 --- a/bmf/c_modules/src/ffmpeg_decoder.cpp +++ b/bmf/c_modules/src/ffmpeg_decoder.cpp @@ -2468,7 +2468,7 @@ int CFFDecoder::process(Task &task) { init_input(dec_opts_); } - if (callback_endpoint_ != NULL) { + if (callback_endpoint_ != nullptr) { std::string info = "total frame number: " + std::to_string(video_stream_->nb_frames); auto para = CBytes::make((uint8_t *)info.c_str(), info.size()); callback_endpoint_(0, para); diff --git a/bmf/c_modules/src/ffmpeg_encoder.cpp b/bmf/c_modules/src/ffmpeg_encoder.cpp index b63a15ff..39a896eb 100644 --- a/bmf/c_modules/src/ffmpeg_encoder.cpp +++ b/bmf/c_modules/src/ffmpeg_encoder.cpp @@ -411,7 +411,7 @@ int CFFEncoder::handle_output(AVPacket *hpkt, int idx) { AVPacket *pkt = hpkt; if (idx == 0) { - if (callback_endpoint_ != NULL) { + if (callback_endpoint_ != nullptr) { // float curr_time = // (in_stream_tbs_[0].den > 0 && in_stream_tbs_[0].num > 0) // ? float(pkt->pts * in_stream_tbs_[0].num / diff --git a/scripts/build_ffmpeg.sh b/scripts/build_ffmpeg.sh index 9f79fc3c..e971f35a 100755 --- a/scripts/build_ffmpeg.sh +++ b/scripts/build_ffmpeg.sh @@ -124,16 +124,41 @@ function build_vpx_unix() { function build_ffmpeg_unix() { cd $1 - if [ ! -e ffmpeg-4.4.tar.gz2 ] - then - curl -O -L https://ffmpeg.org/releases/ffmpeg-4.4.tar.bz2 + # 默认版本是4 + version=${version:-5} + + # 设置FFmpeg版本的下载链接和目录 + if [ "$version" == "5" ]; then + ffmpeg_version="ffmpeg-5.1.6" + ffmpeg_tar="ffmpeg-5.1.6.tar.bz2" + ffmpeg_url="https://ffmpeg.org/releases/$ffmpeg_tar" + else + ffmpeg_version="ffmpeg-4.4" + ffmpeg_tar="ffmpeg-4.4.tar.bz2" + ffmpeg_url="https://ffmpeg.org/releases/$ffmpeg_tar" fi - if [ -d ffmpeg-4.4 ] - then - rm -rf ffmpeg-4.4 + + + # # 目标目录和并行编译核心数等 + # target_dir=${other_args[0]} # 第一个参数为目标目录 + # num_cores=${other_args[1]} # 第二个参数为并行编译的核心数 + # extra_config_args="${other_args[@]:2}" # 从第三个参数开始为额外的配置选项 + + # # 进入目标目录 + # cd $target_dir + + # 如果没有找到 tar 文件,则下载 + if [ ! -e $ffmpeg_tar ]; then + curl -O -L $ffmpeg_url fi - tar xjvf ffmpeg-4.4.tar.bz2 - cd ffmpeg-4.4 + + # 如果已经存在解压目录,则删除 + if [ -d $ffmpeg_version ]; then + rm -rf $ffmpeg_version + fi + + tar xjvf $ffmpeg_tar + cd $ffmpeg_version if [ ${OS} == "Linux" ] && [[ ${DEVICE} =~ "gpu" ]] && [ $(uname -m) == "x86_64" ] then From 3b25df52f0e89e5ddc2a38e37205ae54c8fda35e Mon Sep 17 00:00:00 2001 From: JackLau1222 <2366536135@qq.com> Date: Tue, 7 Jan 2025 10:47:18 +0800 Subject: [PATCH 10/17] disable all useless option --- CMakeLists.txt | 6 +++--- scripts/build_ffmpeg.sh | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 76f61372..7f1d2a7a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,14 +16,14 @@ set(BMF_BUILD_COMMIT "" CACHE STRING "BMF commit") option(BMF_LOCAL_DEPENDENCIES "Build dependencies locally" ON) option(BMF_ENABLE_BREAKPAD "Enable build with breakpad support" OFF) -option(BMF_ENABLE_CUDA "Enable CUDA support" ON) +option(BMF_ENABLE_CUDA "Enable CUDA support" OFF) option(BMF_ENABLE_TORCH "Enable CUDA support" OFF) -option(BMF_ENABLE_PYTHON "Enable build with python support" ON) +option(BMF_ENABLE_PYTHON "Enable build with python support" OFF) option(BMF_ENABLE_GLOG "Enable build with glog support" OFF) option(BMF_ENABLE_JNI "Enable build with JNI support" OFF) option(BMF_ENABLE_FFMPEG "Enable build with ffmpeg support" ON) option(BMF_ENABLE_MOBILE "Enable build for mobile platform" OFF) -option(BMF_ENABLE_TEST "Compile examples and tests" ON) +option(BMF_ENABLE_TEST "Compile examples and tests" OFF) option(BMF_ENABLE_FUZZTEST "Enable fuzz tests" OFF) option(FUZZTEST_ENABLE_FUZZING_MODE "Enable fuzz tests in fuzzing mode" OFF) option(CMAKE_EXPORT_COMPILE_COMMANDS "Export compiler commands" OFF) diff --git a/scripts/build_ffmpeg.sh b/scripts/build_ffmpeg.sh index e971f35a..1a416c04 100755 --- a/scripts/build_ffmpeg.sh +++ b/scripts/build_ffmpeg.sh @@ -124,7 +124,7 @@ function build_vpx_unix() { function build_ffmpeg_unix() { cd $1 - # 默认版本是4 + # 默认版本是5 version=${version:-5} # 设置FFmpeg版本的下载链接和目录 From f4cff014eef0aeb320af006bba0264c0542175cd Mon Sep 17 00:00:00 2001 From: JackLau1222 <2366536135@qq.com> Date: Fri, 10 Jan 2025 18:11:13 +0800 Subject: [PATCH 11/17] enable the ability with python and test --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7b8ddf1c..87964616 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,6 +33,8 @@ jobs: - name: build id: build run: | + sed -i 's/option(BMF_ENABLE_PYTHON "Enable build with python support" OFF)/option(BMF_ENABLE_PYTHON "Enable build with python support" ON)/' CMakeLists.txt + sed -i 's/option(BMF_ENABLE_TEST "Compile examples and tests" OFF)/option(BMF_ENABLE_TEST "Compile examples and tests" ON)/' CMakeLists.txt ./build.sh debug - name: set envs From 62abfa593d574bbea037fd4cc36edd63d0ddf5ee Mon Sep 17 00:00:00 2001 From: JackLau1222 <2366536135@qq.com> Date: Fri, 10 Jan 2025 18:34:11 +0800 Subject: [PATCH 12/17] github ci debug --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 87964616..62db7ef5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -80,6 +80,10 @@ jobs: # test hmp (cd bmf/hml/tests/data && ./gen.sh $(pwd)/../../../../output/files) (cd bmf/hml/tests && pytest) + + - name: Setup tmate session + if: ${{ failure() }} + uses: mxschmitt/action-tmate@v3 build_and_test_win: name: build and test win From de176bce0f2895fe5c6fe15a8a78821153020b9e Mon Sep 17 00:00:00 2001 From: JackLau1222 <2366536135@qq.com> Date: Mon, 20 Jan 2025 07:56:30 +0800 Subject: [PATCH 13/17] add ffmpeg install prefix --- scripts/build_ffmpeg.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/build_ffmpeg.sh b/scripts/build_ffmpeg.sh index 1a416c04..89adbcdb 100755 --- a/scripts/build_ffmpeg.sh +++ b/scripts/build_ffmpeg.sh @@ -21,6 +21,9 @@ do --arch=*) ARCH=${arg#--arch=} ;; + --install-dir=*) + INSTALL_DIR=${arg#--install-dir=} + ;; *) break ;; @@ -170,6 +173,7 @@ function build_ffmpeg_unix() { case $3 in x86_64) ./configure \ + --prefix=$INSTALL_DIR \ --pkg-config-flags="--static" \ --enable-shared \ --disable-static \ @@ -180,6 +184,7 @@ function build_ffmpeg_unix() { ;; arm64) ./configure \ + --prefix=$INSTALL_DIR \ --pkg-config-flags="--static" \ --enable-shared \ --disable-static \ @@ -190,6 +195,7 @@ function build_ffmpeg_unix() { ;; *) ./configure \ + --prefix=$INSTALL_DIR \ --pkg-config-flags="--static" \ --enable-shared \ --disable-static \ From 5d6c6d41e4d4b0f0c6c6baff199005f69ba56df2 Mon Sep 17 00:00:00 2001 From: JackLau1222 <2366536135@qq.com> Date: Mon, 20 Jan 2025 08:15:32 +0800 Subject: [PATCH 14/17] excule --install-dir from build arguments --- scripts/build_ffmpeg.sh | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/scripts/build_ffmpeg.sh b/scripts/build_ffmpeg.sh index 89adbcdb..2f9ea9bb 100755 --- a/scripts/build_ffmpeg.sh +++ b/scripts/build_ffmpeg.sh @@ -415,19 +415,22 @@ then for arg in $@ do - (build_${arg}_unix $(pwd)/ffmpeg_source ${cores}) - if [ ${arg} == "nasm" ] || [ ${arg} == "yasm" ] + if [[ ${arg} != "--install-dir"* ]] # Exclude --install-dir from build arguments then - disable_asm="" - fi + (build_${arg}_unix $(pwd)/ffmpeg_source ${cores}) + if [ ${arg} == "nasm" ] || [ ${arg} == "yasm" ] + then + disable_asm="" + fi - set +e - (check_lib $(pwd)/ffmpeg_source ${arg}) - if [ $? -eq 0 ] - then - ffmpeg_opts="${ffmpeg_opts} --enable-lib${arg}" + set +e + (check_lib $(pwd)/ffmpeg_source ${arg}) + if [ $? -eq 0 ] + then + ffmpeg_opts="${ffmpeg_opts} --enable-lib${arg}" + fi + set -e fi - set -e done ffmpeg_opts="${ffmpeg_opts} ${disable_asm}" From 2b88690c7c66a952c7b70574196c1749fcd64cac Mon Sep 17 00:00:00 2001 From: JackLau1222 <2366536135@qq.com> Date: Mon, 20 Jan 2025 09:20:14 +0800 Subject: [PATCH 15/17] add prefix for all ffmpeg dependencies --- scripts/build_ffmpeg.sh | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/scripts/build_ffmpeg.sh b/scripts/build_ffmpeg.sh index 2f9ea9bb..9812d776 100755 --- a/scripts/build_ffmpeg.sh +++ b/scripts/build_ffmpeg.sh @@ -10,6 +10,7 @@ then ARCH=$(uname -m) fi +INSTALL_DIR=${INSTALL_DIR:-$(pwd)} while [[ $# -gt 0 ]] do @@ -53,7 +54,7 @@ function build_nasm_unix() { tar xjvf nasm-2.15.05.tar.bz2 cd nasm-2.15.05 ./autogen.sh - ./configure --enable-shared + ./configure --enable-shared --prefix=$INSTALL_DIR make -j $2 make install } @@ -63,7 +64,7 @@ function build_yasm_unix() { curl -O -L https://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz tar xzvf yasm-1.3.0.tar.gz cd yasm-1.3.0 - ./configure + ./configure --prefix=$INSTALL_DIR make -j $2 make install } @@ -72,7 +73,7 @@ function build_x264_unix() { cd $1 git clone --branch stable --depth 1 https://code.videolan.org/videolan/x264.git cd x264 - ./configure --enable-shared + ./configure --enable-shared --prefix=$INSTALL_DIR make -j $2 make install } @@ -81,7 +82,7 @@ function build_x265_unix() { cd $1 git clone --branch stable --depth 7 https://bitbucket.org/multicoreware/x265_git cd $1/x265_git/build/linux - cmake -G "Unix Makefiles" -DENABLE_SHARED:bool=off ../../source + cmake -G "Unix Makefiles" -DENABLE_SHARED:bool=off -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR ../../source make -j $2 make install } @@ -91,7 +92,7 @@ function build_fdk-aac_unix() { git clone --depth 1 https://github.com/mstorsjo/fdk-aac cd fdk-aac autoreconf -fiv - ./configure --enable-shared + ./configure --enable-shared --prefix=$INSTALL_DIR make -j $2 make install } @@ -101,7 +102,7 @@ function build_mp3lame_unix() { curl -O -L https://downloads.sourceforge.net/project/lame/lame/3.100/lame-3.100.tar.gz tar xzvf lame-3.100.tar.gz cd lame-3.100 - ./configure --enable-shared --enable-nasm + ./configure --enable-shared --enable-nasm --prefix=$INSTALL_DIR make -j $2 make install } @@ -111,7 +112,7 @@ function build_opus_unix() { curl -O -L https://archive.mozilla.org/pub/opus/opus-1.3.1.tar.gz tar xzvf opus-1.3.1.tar.gz cd opus-1.3.1 - ./configure --enable-shared + ./configure --enable-shared --prefix=$INSTALL_DIR make -j $2 make install } @@ -120,7 +121,7 @@ function build_vpx_unix() { cd $1 git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git cd libvpx - ./configure --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm + ./configure --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm --prefix=$INSTALL_DIR make -j $2 make install } From f13ba6435f5efac05eab8c1a135db992aaedc2bf Mon Sep 17 00:00:00 2001 From: JackLau1222 <2366536135@qq.com> Date: Mon, 20 Jan 2025 10:26:15 +0800 Subject: [PATCH 16/17] fix the default install dir of ffmpeg --- scripts/build_ffmpeg.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build_ffmpeg.sh b/scripts/build_ffmpeg.sh index 9812d776..d48155e9 100755 --- a/scripts/build_ffmpeg.sh +++ b/scripts/build_ffmpeg.sh @@ -10,7 +10,7 @@ then ARCH=$(uname -m) fi -INSTALL_DIR=${INSTALL_DIR:-$(pwd)} +INSTALL_DIR=${INSTALL_DIR:-/usr/local} while [[ $# -gt 0 ]] do From 6c195d8bebe6756b8f370f3e4ad0ec0c27be93c2 Mon Sep 17 00:00:00 2001 From: JackLau1222 <2366536135@qq.com> Date: Sat, 25 Jan 2025 11:41:43 +0800 Subject: [PATCH 17/17] remove useless comments --- scripts/build_ffmpeg.sh | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/scripts/build_ffmpeg.sh b/scripts/build_ffmpeg.sh index d48155e9..c269d196 100755 --- a/scripts/build_ffmpeg.sh +++ b/scripts/build_ffmpeg.sh @@ -128,10 +128,9 @@ function build_vpx_unix() { function build_ffmpeg_unix() { cd $1 - # 默认版本是5 + version=${version:-5} - # 设置FFmpeg版本的下载链接和目录 if [ "$version" == "5" ]; then ffmpeg_version="ffmpeg-5.1.6" ffmpeg_tar="ffmpeg-5.1.6.tar.bz2" @@ -142,21 +141,10 @@ function build_ffmpeg_unix() { ffmpeg_url="https://ffmpeg.org/releases/$ffmpeg_tar" fi - - # # 目标目录和并行编译核心数等 - # target_dir=${other_args[0]} # 第一个参数为目标目录 - # num_cores=${other_args[1]} # 第二个参数为并行编译的核心数 - # extra_config_args="${other_args[@]:2}" # 从第三个参数开始为额外的配置选项 - - # # 进入目标目录 - # cd $target_dir - - # 如果没有找到 tar 文件,则下载 if [ ! -e $ffmpeg_tar ]; then curl -O -L $ffmpeg_url fi - # 如果已经存在解压目录,则删除 if [ -d $ffmpeg_version ]; then rm -rf $ffmpeg_version fi