larksuite / rsmpeg

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

cannot find value `AVPixelFormat_AV_PIX_FMT_P012LE` in this scope #187

Open Ryu2u opened 3 months ago

Ryu2u commented 3 months ago

Cargo cargo 1.80.0 (376290515 2024-07-16) vcpkg vcpkg package management program version 2024-07-10-d2dfc73769081bdd9b782d08d27794780b7a99b9 toolchain stable-x86_64-pc-windows-gnu stable-x86_64-pc-windows-msvc (default) nightly-x86_64-pc-windows-msvc

Cargo.toml

[package]
name = "rsmpeg-vcpkg-demo"
version = "0.1.0"
edition = "2021"

[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"] }

build

error[E0425]: cannot find value `AVPixelFormat_AV_PIX_FMT_P012LE` in this scope                                                                                    
    --> C:\Users\Ryu2u\.cargo\registry\src\mirrors.ustc.edu.cn-61ef6e0cd06fb9b8\rusty_ffmpeg-0.13.3+ffmpeg.6.1\src\avutil\pixfmt.rs:90:80
     |
90   | AV_PIX_FMT_NE!(AVPixelFormat_AV_PIX_FMT_P012, AVPixelFormat_AV_PIX_FMT_P012BE, AVPixelFormat_AV_PIX_FMT_P012LE);
     |                                                                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: a constant with a similar name exists: `AVPixelFormat_AV_PIX_FMT_P010LE`
     |
    ::: H:\Project\rsmpeg-vcpkg-demo\./target/debug\build\rusty_ffmpeg-a9a97921f7d9f709\out/binding.rs:8363:1
     |
8363 | pub const AVPixelFormat_AV_PIX_FMT_P010LE: AVPixelFormat = 159;
     | --------------------------------------------------------------- similarly named constant `AVPixelFormat_AV_PIX_FMT_P010LE` defined here

error[E0425]: cannot find value `AVPixelFormat_AV_PIX_FMT_Y212LE` in this scope
    --> C:\Users\Ryu2u\.cargo\registry\src\mirrors.ustc.edu.cn-61ef6e0cd06fb9b8\rusty_ffmpeg-0.13.3+ffmpeg.6.1\src\avutil\pixfmt.rs:96:81
     |
96   | AV_PIX_FMT_NE!(AVPixelFormat_AV_PIX_FMT_Y212, AVPixelFormat_AV_PIX_FMT_Y212BE,  AVPixelFormat_AV_PIX_FMT_Y212LE);
     |                                                                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: a constant with a similar name exists: `AVPixelFormat_AV_PIX_FMT_Y210LE`
     |
    ::: H:\Project\rsmpeg-vcpkg-demo\./target/debug\build\rusty_ffmpeg-a9a97921f7d9f709\out/binding.rs:8431:1
     |
8431 | pub const AVPixelFormat_AV_PIX_FMT_Y210LE: AVPixelFormat = 193;
     | --------------------------------------------------------------- similarly named constant `AVPixelFormat_AV_PIX_FMT_Y210LE` defined here

error[E0425]: cannot find value `AVPixelFormat_AV_PIX_FMT_XV30LE` in this scope
    --> C:\Users\Ryu2u\.cargo\registry\src\mirrors.ustc.edu.cn-61ef6e0cd06fb9b8\rusty_ffmpeg-0.13.3+ffmpeg.6.1\src\avutil\pixfmt.rs:98:81
     |
98   | AV_PIX_FMT_NE!(AVPixelFormat_AV_PIX_FMT_XV30, AVPixelFormat_AV_PIX_FMT_XV30BE,  AVPixelFormat_AV_PIX_FMT_XV30LE);
     |                                                                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: a constant with a similar name exists: `AVPixelFormat_AV_PIX_FMT_NV20LE`
     |
    ::: H:\Project\rsmpeg-vcpkg-demo\./target/debug\build\rusty_ffmpeg-a9a97921f7d9f709\out/binding.rs:8249:1
     |
8249 | pub const AVPixelFormat_AV_PIX_FMT_NV20LE: AVPixelFormat = 102;
     | --------------------------------------------------------------- similarly named constant `AVPixelFormat_AV_PIX_FMT_NV20LE` defined here

error[E0425]: cannot find value `AVPixelFormat_AV_PIX_FMT_XV36LE` in this scope
   --> C:\Users\Ryu2u\.cargo\registry\src\mirrors.ustc.edu.cn-61ef6e0cd06fb9b8\rusty_ffmpeg-0.13.3+ffmpeg.6.1\src\avutil\pixfmt.rs:100:81
    |
11  |         pub const $def: AVPixelFormat = $le;
    |         ------------------------------------ similarly named constant `AVPixelFormat_AV_PIX_FMT_XV36` defined here
...
100 | AV_PIX_FMT_NE!(AVPixelFormat_AV_PIX_FMT_XV36, AVPixelFormat_AV_PIX_FMT_XV36BE,  AVPixelFormat_AV_PIX_FMT_XV36LE);
    |                                                                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: a constant with a similar name exists: `AVPixelFormat_AV_PIX_FMT_XV36`

error[E0425]: cannot find value `AVPixelFormat_AV_PIX_FMT_RGBAF16LE` in this scope
   --> C:\Users\Ryu2u\.cargo\registry\src\mirrors.ustc.edu.cn-61ef6e0cd06fb9b8\rusty_ffmpeg-0.13.3+ffmpeg.6.1\src\avutil\pixfmt.rs:116:86
    |
11  |         pub const $def: AVPixelFormat = $le;
    |         ------------------------------------ similarly named constant `AVPixelFormat_AV_PIX_FMT_RGBAF16` defined here
...
116 | AV_PIX_FMT_NE!(AVPixelFormat_AV_PIX_FMT_RGBAF16, AVPixelFormat_AV_PIX_FMT_RGBAF16BE, AVPixelFormat_AV_PIX_FMT_RGBAF16LE);
    |                                                                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: a constant with a similar name exists: `AVPixelFormat_AV_PIX_FMT_RGBAF16`

error[E0425]: cannot find value `AVPixelFormat_AV_PIX_FMT_RGBF32LE` in this scope
   --> C:\Users\Ryu2u\.cargo\registry\src\mirrors.ustc.edu.cn-61ef6e0cd06fb9b8\rusty_ffmpeg-0.13.3+ffmpeg.6.1\src\avutil\pixfmt.rs:119:84
    |
11  |         pub const $def: AVPixelFormat = $le;
    |         ------------------------------------ similarly named constant `AVPixelFormat_AV_PIX_FMT_RGBF32` defined here
...
119 | AV_PIX_FMT_NE!(AVPixelFormat_AV_PIX_FMT_RGBF32, AVPixelFormat_AV_PIX_FMT_RGBF32BE, AVPixelFormat_AV_PIX_FMT_RGBF32LE);
    |                                                                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: a constant with a similar name exists: `AVPixelFormat_AV_PIX_FMT_RGBF32`

error[E0425]: cannot find value `AVPixelFormat_AV_PIX_FMT_RGBAF32LE` in this scope
   --> C:\Users\Ryu2u\.cargo\registry\src\mirrors.ustc.edu.cn-61ef6e0cd06fb9b8\rusty_ffmpeg-0.13.3+ffmpeg.6.1\src\avutil\pixfmt.rs:121:86
    |
11  |         pub const $def: AVPixelFormat = $le;
    |         ------------------------------------ similarly named constant `AVPixelFormat_AV_PIX_FMT_RGBAF32` defined here
...
121 | AV_PIX_FMT_NE!(AVPixelFormat_AV_PIX_FMT_RGBAF32, AVPixelFormat_AV_PIX_FMT_RGBAF32BE, AVPixelFormat_AV_PIX_FMT_RGBAF32LE);
    |                                                                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: a constant with a similar name exists: `AVPixelFormat_AV_PIX_FMT_RGBAF32`

For more information about this error, try `rustc --explain E0425`.                                                                                                
error: could not compile `rusty_ffmpeg` (lib) due to 7 previous errors
ldm0 commented 3 months ago

vcpkg with commit 0557210 tracks FFmpeg 6.1, which does contain AV_PIX_FMT_P010LE. The vcpkg crate links x64-windows-static-md packages by default: https://docs.rs/vcpkg/latest/vcpkg/#windows, but the configuration you specified in Cargo.toml is x64-windows-static. So I think the build failure is caused by a previously installed old(version < 6.0) FFmpeg x64-windows-static-md package.

Therefore, you can replace x64-windows-static with x64-windows-static-md in your Cargo.toml, or add RUSTFLAGS=-Ctarget-feature=+crt-static before building. Both will solve your problem(I've locally verified).

Ryu2u commented 3 months ago

vcpkg with commit 0557210 tracks FFmpeg 6.1, which does contain AV_PIX_FMT_P010LE. The vcpkg crate links x64-windows-static-md packages by default: https://docs.rs/vcpkg/latest/vcpkg/#windows, but the configuration you specified in Cargo.toml is x64-windows-static. So I think the build failure is caused by a previously installed old(version < 6.0) FFmpeg x64-windows-static-md package.

Therefore, you can replace x64-windows-static with x64-windows-static-md in your Cargo.toml, or add RUSTFLAGS=-Ctarget-feature=+crt-static before building. Both will solve your problem(I've locally verified).

i changed the x64-windows-static to x64-windows-static-md and execute cargo clean & cargo vcpkg --verbose build & cargo build . It still doesn't work

error[E0308]: mismatched types
     --> C:\Users\Ryu2u\.cargo\registry\src\mirrors.ustc.edu.cn-61ef6e0cd06fb9b8\rsmpeg-0.15.1+ffmpeg.7.0\src\avcodec\parser.rs:17:38
      |
17    |         unsafe { ffi::av_parser_init(codec_id) }
      |                  ------------------- ^^^^^^^^ expected `i32`, found `u32`
      |                  |
      |                  arguments to this function are incorrect
      |
note: function defined here
     --> H:\Project\rsmpeg-vcpkg-demo\./target/debug\build\rusty_ffmpeg-a9d5a95fbcb34fc0\out/binding.rs:16221:12
      |
16221 |     pub fn av_parser_init(codec_id: ::std::os::raw::c_int) -> *mut AVCodecParserContext;
      |            ^^^^^^^^^^^^^^
help: you can convert a `u32` to an `i32` and panic if the converted value doesn't fit
      |
17    |         unsafe { ffi::av_parser_init(codec_id.try_into().unwrap()) }
      |                                              ++++++++++++++++++++

For more information about this error, try `rustc --explain E0308`.                                                                                     
error: could not compile `rsmpeg` (lib) due to 1 previous error
ldm0 commented 3 months ago

That's another issue.

It's strange that AVCodecID's binding was generated as u32. enums should share the same layout with i32 on Windows(https://github.com/rust-lang/rust-bindgen/issues/1244). Could you create a minimal repo which can reproduce this problem?

The crate I created with such Cargo.toml compiled successfully with cargo clean & cargo vcpkg --verbose build & cargo build:

[package]
name = "rust_test"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

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

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

That's another issue.

It's strange that AVCodecID's binding was generated as u32. enums should share the same layout with i32 on Windows(rust-lang/rust-bindgen#1244). Could you create a minimal repo which can reproduce this problem?

The crate I created with such Cargo.toml compiled successfully with cargo clean & cargo vcpkg --verbose build & cargo build:

[package]
name = "rust_test"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

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

[dependencies]
rsmpeg = { version = "0.15.0", default-features = false, features = ["ffmpeg6"] }

i use this https://github.com/aegroto/rsmpeg-vcpkg-demo demo and change the Cargo.toml


[package]
name = "rsmpeg-vcpkg-demo"
version = "0.1.0"
edition = "2021"

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

[dependencies]
rsmpeg = { version = "0.15.1", default-features = false, features = ["ffmpeg6"] }

``
aegroto commented 3 months ago

@Ryu2u the example repository was created quite some time ago so I believe some things in the binding have changed. Please let me know if something could be updated to make the example more coherent with the last released versions of ffmpeg and rsmpeg.