Skip to content

Commit bdbaf09

Browse files
cfsmp3claude
andcommitted
Add use_prebuilt_binding feature for consistent FFmpeg 7 API
When the system FFmpeg version doesn't match the expected API (e.g., Ubuntu has FFmpeg 6 but rsmpeg needs FFmpeg 7 signatures), the dynamically generated bindings will have incorrect function signatures like *mut u8 instead of *const u8 for write_packet. This feature allows using the prebuilt binding from src/binding.rs which has correct FFmpeg 7 API signatures, ensuring consistent behavior across all platforms regardless of system FFmpeg version. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent af91025 commit bdbaf09

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ pkg-config = "0.3"
3737
link_system_ffmpeg = []
3838
# Probe and link FFmpeg with vcpkg
3939
link_vcpkg_ffmpeg = ["vcpkg"]
40+
# Use the prebuilt FFmpeg 7 bindings from src/binding.rs instead of generating at build time
41+
# This ensures consistent API signatures across all platforms
42+
use_prebuilt_binding = []
4043
# FFmpeg 5.* support
4144
ffmpeg5 = []
4245
# FFmpeg 6.* support

build.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,15 @@ fn docs_rs_linking(env_vars: EnvVars) {
584584
use_prebuilt_binding(Path::new("src/binding.rs"), binding_file_path);
585585
}
586586

587+
/// When use_prebuilt_binding feature is enabled, use the prebuilt binding
588+
/// from src/binding.rs. This is useful when the system FFmpeg version
589+
/// doesn't match the expected API (e.g., system has FFmpeg 6 but we need FFmpeg 7).
590+
#[cfg(feature = "use_prebuilt_binding")]
591+
fn use_prebuilt_binding_feature(env_vars: &EnvVars) {
592+
let binding_file_path = &env_vars.out_dir.as_ref().unwrap().join("binding.rs");
593+
use_prebuilt_binding(Path::new("src/binding.rs"), binding_file_path);
594+
}
595+
587596
fn main() {
588597
let env_vars = EnvVars::init();
589598
if env_vars.docs_rs.is_some() {
@@ -594,4 +603,9 @@ fn main() {
594603
// fallback to normal linking
595604
linking(env_vars);
596605
}
606+
607+
// If use_prebuilt_binding feature is enabled, overwrite the generated binding
608+
// with our prebuilt one to ensure consistent FFmpeg 7 API signatures
609+
#[cfg(feature = "use_prebuilt_binding")]
610+
use_prebuilt_binding_feature(&EnvVars::init());
597611
}

0 commit comments

Comments
 (0)