Skip to content

Commit

Permalink
Fix compilation with serialize feature
Browse files Browse the repository at this point in the history
  • Loading branch information
admin committed Jan 31, 2025
2 parents 30c7f12 + 8fb0f2c commit 7d2f175
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 41 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Version 3.0.1

- Fix compilation with `serialize` feature and newest `bitflags` crate

## Version 3.0.0

- [Breaking] remove support for < ffmpeg 4.2
Expand Down
51 changes: 27 additions & 24 deletions Cargo.lock.MSRV

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ffmpeg-the-third"
version = "3.0.0+ffmpeg-7.1"
version = "3.0.1+ffmpeg-7.1"
edition = "2021"

authors = ["meh. <[email protected]>", "Zhiming Wang <[email protected]>"]
Expand All @@ -20,14 +20,14 @@ rust-version = "1.82.0"

[dependencies]
libc = "0.2"
bitflags = "2.7"
bitflags = "2.8"

[dependencies.image]
version = "0.25"
optional = true

[dependencies.ffmpeg-sys-third]
version = "3.0.0"
version = "3.0.1"
default-features = false
path = "ffmpeg-sys-third"

Expand All @@ -47,7 +47,7 @@ default = [
"non-exhaustive-enums",
]

serialize = ["serde"]
serialize = ["serde", "bitflags/serde"]
static = ["ffmpeg-sys-third/static"]

# mark enums in generated bindings as #[non_exhaustive]
Expand Down
2 changes: 1 addition & 1 deletion examples/transcode-x264.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl Transcoder {
let codec = encoder::find(codec::Id::H264);
let mut ost = octx.add_stream(codec)?;

let mut encoder = codec::context::Context::new(codec).encoder().video()?;
let mut encoder = codec::context::Context::new_with_codec(codec.unwrap()).encoder().video()?;
ost.set_parameters_into(&encoder);
encoder.set_height(decoder.height());
encoder.set_width(decoder.width());
Expand Down
2 changes: 1 addition & 1 deletion examples/video-resize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

// 创建和配置编码器
let codec = codec::encoder::find(codec::Id::H264);
let mut encoder = codec::context::Context::new(codec).encoder().video()?;
let mut encoder = codec::context::Context::new_with_codec(codec.unwrap()).encoder().video()?;

// 设置编码器参数
encoder.set_height(height);
Expand Down
2 changes: 1 addition & 1 deletion ffmpeg-sys-third/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ffmpeg-sys-third"
version = "3.0.0+ffmpeg-7.1"
version = "3.0.1+ffmpeg-7.1"
links = "ffmpeg"
edition = "2021"

Expand Down
22 changes: 14 additions & 8 deletions src/codec/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,26 @@ impl Context {
}

impl Context {
pub fn new(codec: Option<Codec>) -> Self {
pub fn new() -> Self {
unsafe {
Context {
ptr: match codec {
Some(c) => avcodec_alloc_context3(c.as_ptr()),
None => avcodec_alloc_context3(ptr::null()),
},
ptr: avcodec_alloc_context3(ptr::null()),
owner: None,
}
}
}

pub fn new_with_codec(codec: Codec) -> Self {
unsafe {
Context {
ptr: avcodec_alloc_context3(codec.as_ptr()),
owner: None,
}
}
}

pub fn from_parameters<P: AsPtr<AVCodecParameters>>(parameters: P) -> Result<Self, Error> {
let mut context = Self::new(None);
let mut context = Self::new();

unsafe {
match avcodec_parameters_to_context(context.as_mut_ptr(), parameters.as_ptr()) {
Expand Down Expand Up @@ -131,7 +137,7 @@ impl Context {

impl Default for Context {
fn default() -> Self {
Self::new(None)
Self::new()
}
}

Expand All @@ -148,7 +154,7 @@ impl Drop for Context {
#[cfg(not(feature = "ffmpeg_5_0"))]
impl Clone for Context {
fn clone(&self) -> Self {
let mut ctx = Context::new(None);
let mut ctx = Context::new();
ctx.clone_from(self);

ctx
Expand Down
2 changes: 1 addition & 1 deletion src/codec/decoder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::ffi::*;
use crate::Codec;

pub fn new() -> Decoder {
Context::new(None).decoder()
Context::new().decoder()
}

pub fn find(id: Id) -> Option<Codec> {
Expand Down
2 changes: 1 addition & 1 deletion src/codec/encoder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use crate::ffi::*;
use crate::Codec;

pub fn new() -> Encoder {
Context::new(None).encoder()
Context::new().encoder()
}

pub fn find(id: Id) -> Option<Codec> {
Expand Down

0 comments on commit 7d2f175

Please sign in to comment.