larksuite / rsmpeg

A Rust crate that exposes FFmpeg's power as much as possible.
https://docs.rs/rsmpeg/latest/rsmpeg/
MIT License
677 stars 41 forks source link

Compiliation error after upgrading to 0.15.0 #180

Closed wangjia184 closed 7 months ago

wangjia184 commented 7 months ago

After upgrading to 0.15.0 with ffmpeg 7.0, it fails to complie

[dependencies]
rsmpeg = { version = "0.15.0+ffmpeg.7.0", features = ["ffmpeg7"] }

[package.metadata.vcpkg]
dependencies = [
    "ffmpeg[ffmpeg,x264,avcodec,avdevice,avfilter,avformat]:x64-windows-static",
]
git = "https://github.com/microsoft/vcpkg"
rev = "4a600e9"

The vcpkg is built successfully. But rsmpeg cannot be built

error[E0425]: cannot find function `av_dict_iterate` in module `ffi`
     --> C:\Users\xxx\.cargo\registry\src\mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd\rsmpeg-0.15.0+ffmpeg.7.0\src\avutil\dict.rs:199:34
      |
199   |         self.ptr = unsafe { ffi::av_dict_iterate(self.dict.as_ptr(), self.ptr) };
      |                                  ^^^^^^^^^^^^^^^ help: a function with a similar name exists: `av_bsf_iterate`
      |
     ::: G:\projects\virtual_dealer\target\debug\build\rusty_ffmpeg-f9f43431ec5857d1\out/binding.rs:15869:5
      |
15869 |     pub fn av_bsf_iterate(opaque: *mut *mut ::std::os::raw::c_void) -> *const AVBitStreamFilter;
      |     ------------------------------------------------------------------------------------------- similarly named function `av_bsf_iterate` defined here

error[E0605]: non-primitive cast: `unsafe extern "C" fn(*mut c_void, *const u8, i32) -> i32 {write_c}` as `unsafe extern "C" fn(*mut c_void, *mut u8, i32) -> i32`
   --> C:\Users\xxx\.cargo\registry\src\mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd\rsmpeg-0.15.0+ffmpeg.7.0\src\avformat\avio.rs:125:50
    |
125 |                 write_packet.is_some().then_some(write_c as _),
    |                                                  ^^^^^^^^^^^^ invalid cast

error[E0308]: arguments to this function are incorrect
     --> C:\Users\xxx\.cargo\registry\src\mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd\rsmpeg-0.15.0+ffmpeg.7.0\src\swresample\swresample.rs:37:13
      |
37    |             ffi::swr_alloc_set_opts2(
      |             ^^^^^^^^^^^^^^^^^^^^^^^^
      |
note: types differ in mutability
     --> C:\Users\xxx\.cargo\registry\src\mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd\rsmpeg-0.15.0+ffmpeg.7.0\src\swresample\swresample.rs:39:17
      |
39    |                 out_ch_layout,
      |                 ^^^^^^^^^^^^^
      = note: expected raw pointer `*mut rusty_ffmpeg::ffi::AVChannelLayout`
                   found reference `&rusty_ffmpeg::ffi::AVChannelLayout`
note: types differ in mutability
     --> C:\Users\xxx\.cargo\registry\src\mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd\rsmpeg-0.15.0+ffmpeg.7.0\src\swresample\swresample.rs:42:17
      |
42    |                 in_ch_layout,
      |                 ^^^^^^^^^^^^
      = note: expected raw pointer `*mut rusty_ffmpeg::ffi::AVChannelLayout`
                   found reference `&rusty_ffmpeg::ffi::AVChannelLayout`
note: function defined here
     --> G:\projects\virtual_dealer\target\debug\build\rusty_ffmpeg-f9f43431ec5857d1\out/binding.rs:30751:12
      |
30751 |     pub fn swr_alloc_set_opts2(
      |            ^^^^^^^^^^^^^^^^^^^

Some errors have detailed explanations: E0308, E0425, E0605.
For more information about an error, try `rustc --explain E0308`.
error: could not compile `rsmpeg` (lib) due to 3 previous errors
wangjia184 commented 7 months ago

I tried to clean target folder and rebuild ffmpeg vcpkg, it does not work.

I have to downgrade ffmpeg to 6 to avoid this error

[package.metadata.vcpkg]
dependencies = [
    "ffmpeg[ffmpeg,x264,avcodec,avdevice,avfilter,avformat]:x64-windows-static",
]
git = "https://github.com/microsoft/vcpkg"
rev = "0557210"

[dependencies]
rsmpeg = { version = "0.15.0", default-features = false, features = [
    "ffmpeg6",
] }
ldm0 commented 7 months ago

Yeah, if you see this error message:

error[E0605]: non-primitive cast: `unsafe extern "C" fn(*mut c_void, *const u8, i32) -> i32 {write_c}` as `unsafe extern "C" fn(*mut c_void, *mut u8, i32) -> i32`

It might be that you are not using FFmpeg 7. AFAIK, vcpkg haven't upgraded to FFmpeg 7 yet: https://github.com/microsoft/vcpkg/pull/38011. Therefore you need to specify ffmpeg6 feature.

rsmpeg is a binding crate, if the given library header files(which is provided by vcpkg here) don't match the rsmpeg's feature set, it won't pass compilation.

ldm0 commented 7 months ago

Feel free to reopen if you have more questions. :-)