zmwangx / rust-ffmpeg

Safe FFmpeg wrapper.
Do What The F*ck You Want To Public License
1.2k stars 195 forks source link

solution for error in Windows: `non-exhaustive patterns` #154

Open altunenes opened 1 year ago

altunenes commented 1 year ago

TL/DR: https://github.com/zmwangx/rust-ffmpeg/pull/155

First of all, thank you for this beautiful contribution. ❤️

I wanted to use rust-ffmpeg in one of my projects and it compiles on MAC without any problem. But when I try it on Windows 11 I get an error: 😢

error[E0004]: non-exhaustive patterns: sys::AVPixelFormat::AV_PIX_FMT_P212BE, sys::AVPixelFormat::AV_PIX_FMT_P212LE, sys::AVPixelFormat::AV_PIX_FMT_P412BE and 1 more not covered

error[E0004]: non-exhaustive patterns: sys::AVCodecID::AV_CODEC_ID_PDV sys::AVCodecID::AV_CODEC_ID_EVC, sys::AVCodecID::AV_CODEC_ID_RTV1 and 3 more not covered

I made the following implementations and my problem was solved: 🥳

src/util/format/pixel.rs https://github.com/zmwangx/rust-ffmpeg/blob/6b84927798dade84037450a2b440139abde3a5ce/src/util/format/pixel.rs#L10

I updated the Pixel enum to include all possible pixel formats like so:

#[derive(Eq, PartialEq, Copy, Clone, Debug)]
pub enum Pixel {
    None,
    P212BE,
    P212LE,
    P412BE,
    P412LE,
    //others...
}

Then, I updated the implementation of From for Pixel and From for AVPixelFormat to include these new enumerations.

impl From<AVPixelFormat> for Pixel {
    #[inline]
    fn from(value: AVPixelFormat) -> Self {
        match value {
            AV_PIX_FMT_NONE => Pixel::None,
            AV_PIX_FMT_P212BE => Pixel::P212BE,
            AV_PIX_FMT_P212LE => Pixel::P212LE,
            AV_PIX_FMT_P412BE => Pixel::P412BE,
            AV_PIX_FMT_P412LE => Pixel::P412LE,
            //others...
        }
    }
}
impl From<Pixel> for AVPixelFormat {
    #[inline]
    fn from(value: Pixel) -> AVPixelFormat {
        match value {
            Pixel::None => AV_PIX_FMT_NONE,
            Pixel::P212BE => AV_PIX_FMT_P212BE,
            Pixel::P212LE => AV_PIX_FMT_P212LE,
            Pixel::P412BE => AV_PIX_FMT_P412BE,
            Pixel::P412LE => AV_PIX_FMT_P412LE,
            //others...
        }
    }
}

In the id.rs file, I updated the Id enum and did a similar update for the From for Id and From for AVCodecID implementations: src/codec/id.rs https://github.com/zmwangx/rust-ffmpeg/blob/6b84927798dade84037450a2b440139abde3a5ce/src/codec/id.rs#L10


#[allow(non_camel_case_types)]
#[derive(Eq, PartialEq, Clone, Copy, Debug)]
pub enum Id {
    None,
    PDV,
    EVC,
    RTV1,

    VMIX,
    AC4,
    SMPTE2038,
    //others...
}

impl From<AVCodecID> for Id {
    fn from(value: AVCodecID) -> Self {
        match value {
            AV_CODEC_ID_NONE => Id::None,
            AV_CODEC_ID_PDV => Id::PDV,
            AV_CODEC_ID_EVC => Id::EVC,
            AV_CODEC_ID_RTV1 => Id::RTV1,

            AV_CODEC_ID_VMIX => Id::VMIX,
            AV_CODEC_ID_AC4 => Id::AC4,
            AV_CODEC_ID_SMPTE_2038 => Id::SMPTE2038,
            //others...
        }
    }
}

impl From<Id> for AVCodecID {
    fn from(value: Id) -> AVCodecID {
        match value {
            Id::None => AV_CODEC_ID_NONE,
            Id::PDV => AV_CODEC_ID_PDV,
            Id::EVC => AV_CODEC_ID_EVC,
            Id::RTV1 => AV_CODEC_ID_RTV1,

            Id::VMIX => AV_CODEC_ID_VMIX,
            Id::AC4 => AV_CODEC_ID_AC4,
            Id::SMPTE2038 => AV_CODEC_ID_SMPTE_2038,
            //others...
        }
    }
}

after these implementations, all is okay now
happy coding. 😸

thewh1teagle commented 6 months ago

It's related to what version of ffmpeg library you use. Currently ffmpeg-next supported FFmpeg versions: 3.4.x through 4.4.x.

Polochon-street commented 6 months ago

Hi!

We just merged some things for ffmpeg 6.1 support - this should work for you now :)

We're always lagging behind a bit for new releases, so that explains why windows (whose build downloads automatically the latest ffmpeg version) sometimes fails to compile. Hopefully we fixed it!

thewh1teagle commented 6 months ago

@Polochon-street Do you know if it's possible to statically link ffmpeg for windows in msys2 when using this library? I have static libraries installed but it doesn't link them statically

Polochon-street commented 6 months ago

@thewh1teagle I remember it was a pain, and I'm not even sure I managed. It seems possible, but given that there all whole projects dedicated to that, I'm thinking shipping the dlls might be the easiest

thewh1teagle commented 6 months ago

@Polochon-street It has to be something with bindgen (build.rs) I have the static build files of ffmpeg already, just need to make rust use them

thewh1teagle commented 6 months ago

@Polochon-street As I thought the problem with rust-ffmpeg-sys in this line build.rs#L654C52-L654C63. It looks for .a files to link them but in windows it's .dll.a. maybe related?

altunenes commented 3 months ago

Thank you to both of you! <3 We migrated to GStreamer after encountering this specific issue, so I'm not certain if updating the version could resolve the error. :-(

Again, thank you for this beautiful repo and your time ❤️ (you can close this issue if you want: because I can't confirm if the latest update fix the issue :(( )