Skip to content

Commit

Permalink
Supports FFmpeg 7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ldm0 committed Apr 5, 2024
1 parent 1c6a1f5 commit 23dda1d
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 24 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
libopus-dev
- run: |
git clone https://github.com/ffmpeg/ffmpeg --depth 1 --single-branch --branch release/6.1
git clone https://github.com/ffmpeg/ffmpeg --depth 1 --single-branch --branch release/7.0
cd ffmpeg
mkdir build
cd build
Expand Down Expand Up @@ -288,7 +288,7 @@ jobs:
# Disable exr,phm to workaround "multiple definition of 'ff_init_half2float_tables'"
# Ref: `https://github.com/larksuite/rsmpeg/pull/98#issuecomment-1467511193`
- run: |
git clone https://github.com/ffmpeg/ffmpeg --depth 1 --single-branch --branch release/6.1
git clone https://github.com/ffmpeg/ffmpeg --depth 1 --single-branch --branch release/7.0
cd ffmpeg
mkdir build
cd build
Expand Down Expand Up @@ -414,7 +414,7 @@ jobs:
- name: Build FFmpeg dylib
run: |
git clone https://github.com/ffmpeg/ffmpeg --depth 1 --single-branch --branch release/6.1
git clone https://github.com/ffmpeg/ffmpeg --depth 1 --single-branch --branch release/7.0
cd ffmpeg
mkdir build
cd build
Expand Down Expand Up @@ -496,7 +496,7 @@ jobs:
- name: Build FFmpeg dylib
run: |
git clone https://github.com/ffmpeg/ffmpeg --depth 1 --single-branch --branch release/6.1
git clone https://github.com/ffmpeg/ffmpeg --depth 1 --single-branch --branch release/7.0
cd ffmpeg
mkdir build
cd build
Expand Down Expand Up @@ -583,7 +583,7 @@ jobs:
cd ../..
- name: Build FFmpeg
run: |
git clone https://github.com/ffmpeg/ffmpeg --depth 1 --single-branch --branch release/6.1
git clone https://github.com/ffmpeg/ffmpeg --depth 1 --single-branch --branch release/7.0
cd ffmpeg
mkdir build
cd build
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
Cargo.lock
/.vscode
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ link_system_ffmpeg = []
ffmpeg5 = []
# FFmpeg 6.* support
ffmpeg6 = []
# FFmpeg 7.* support
ffmpeg7 = []
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ You need to set several environment variables for both linking and binding gener

You can enable system-wide FFmpeg linking by enabling feature `link_system_ffmpeg`.

### Use specific FFmpeg version

- Do nothing when you are using FFmpeg `4.*`
- Enable `ffmpeg5` feature when you are using FFmpeg `5.*`
- Enable `ffmpeg6` feature when you are using FFmpeg `6.*`
- Enable `ffmpeg7` feature when you are using FFmpeg `7.*`

## Attention

FFI is not that easy, especially when you are dealing with a big old C project. Don't feel depressed when there are some problems. The CI check already has some typical ffmpeg compilation and use cases for you to check. File an issue if you still have any problem.
11 changes: 6 additions & 5 deletions examples/slice/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Port from Original code: https://github.com/leandromoreira/ffmpeg-libav-tutorial/blob/master/0_hello_world.c

use rusty_ffmpeg::ffi;

use std::{
Expand All @@ -8,6 +9,7 @@ use std::{
ptr, slice,
};

// This should only be used with FFmpeg 7
fn main() {
let filepath: CString = CString::new("./examples/slice/bear.mp4").unwrap();

Expand Down Expand Up @@ -98,7 +100,7 @@ fn main() {
ffi::AVMEDIA_TYPE_AUDIO => {
println!(
"Audio Codec: {} channels, sample rate {}",
local_codec_params.channels, local_codec_params.sample_rate
local_codec_params.ch_layout.nb_channels, local_codec_params.sample_rate
);
}
_ => {}
Expand Down Expand Up @@ -174,18 +176,17 @@ fn decode_packet(
));
} else {
println!(
"Frame {} (type={}, size={} bytes) pts {} key_frame {} [DTS {}]",
codec_context.frame_number,
"Frame {} (type={}, size={} bytes) pts {} key_frame {}",
codec_context.frame_num,
unsafe { ffi::av_get_picture_type_char(frame.pict_type) },
frame.pkt_size,
frame.pts,
frame.key_frame,
frame.coded_picture_number
);

let frame_filename = format!(
"./examples/slice/output/frame-{}.pgm",
codec_context.frame_number
codec_context.frame_num
);
let width = frame.width as usize;
let height = frame.height as usize;
Expand Down
34 changes: 20 additions & 14 deletions src/avutil/pixfmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ AV_PIX_FMT_NE!(AV_PIX_FMT_GBRP14, AV_PIX_FMT_GBRP14BE, AV_PIX_FMT_GBRP14LE);
AV_PIX_FMT_NE!(AV_PIX_FMT_GBRP16, AV_PIX_FMT_GBRP16BE, AV_PIX_FMT_GBRP16LE);
AV_PIX_FMT_NE!(AV_PIX_FMT_GBRAP10, AV_PIX_FMT_GBRAP10BE, AV_PIX_FMT_GBRAP10LE);
AV_PIX_FMT_NE!(AV_PIX_FMT_GBRAP12, AV_PIX_FMT_GBRAP12BE, AV_PIX_FMT_GBRAP12LE);
#[cfg(any(feature = "ffmpeg7"))]
AV_PIX_FMT_NE!(AV_PIX_FMT_GBRAP14, AV_PIX_FMT_GBRAP14BE, AV_PIX_FMT_GBRAP14LE);
AV_PIX_FMT_NE!(AV_PIX_FMT_GBRAP16, AV_PIX_FMT_GBRAP16BE, AV_PIX_FMT_GBRAP16LE);

AV_PIX_FMT_NE!(AV_PIX_FMT_BAYER_BGGR16, AV_PIX_FMT_BAYER_BGGR16BE, AV_PIX_FMT_BAYER_BGGR16LE);
Expand All @@ -86,36 +88,40 @@ AV_PIX_FMT_NE!(AV_PIX_FMT_XYZ12, AV_PIX_FMT_XYZ12BE, AV_PIX_FMT_XYZ12LE);
AV_PIX_FMT_NE!(AV_PIX_FMT_NV20, AV_PIX_FMT_NV20BE, AV_PIX_FMT_NV20LE);
AV_PIX_FMT_NE!(AV_PIX_FMT_AYUV64, AV_PIX_FMT_AYUV64BE, AV_PIX_FMT_AYUV64LE);
AV_PIX_FMT_NE!(AV_PIX_FMT_P010, AV_PIX_FMT_P010BE, AV_PIX_FMT_P010LE);
#[cfg(feature = "ffmpeg6")]
#[cfg(any(feature = "ffmpeg6", feature = "ffmpeg7"))]
AV_PIX_FMT_NE!(AV_PIX_FMT_P012, AV_PIX_FMT_P012BE, AV_PIX_FMT_P012LE);
AV_PIX_FMT_NE!(AV_PIX_FMT_P016, AV_PIX_FMT_P016BE, AV_PIX_FMT_P016LE);

#[cfg(any(feature = "ffmpeg5", feature = "ffmpeg6"))]
#[cfg(any(feature = "ffmpeg5", feature = "ffmpeg6", feature = "ffmpeg7"))]
AV_PIX_FMT_NE!(AV_PIX_FMT_Y210, AV_PIX_FMT_Y210BE, AV_PIX_FMT_Y210LE);
#[cfg(feature = "ffmpeg6")]
#[cfg(any(feature = "ffmpeg6", feature = "ffmpeg7"))]
AV_PIX_FMT_NE!(AV_PIX_FMT_Y212, AV_PIX_FMT_Y212BE, AV_PIX_FMT_Y212LE);
#[cfg(feature = "ffmpeg6")]
#[cfg(any(feature = "ffmpeg6", feature = "ffmpeg7"))]
AV_PIX_FMT_NE!(AV_PIX_FMT_XV30, AV_PIX_FMT_XV30BE, AV_PIX_FMT_XV30LE);
#[cfg(feature = "ffmpeg6")]
#[cfg(any(feature = "ffmpeg6", feature = "ffmpeg7"))]
AV_PIX_FMT_NE!(AV_PIX_FMT_XV36, AV_PIX_FMT_XV36BE, AV_PIX_FMT_XV36LE);
#[cfg(any(feature = "ffmpeg5", feature = "ffmpeg6"))]
#[cfg(any(feature = "ffmpeg5", feature = "ffmpeg6", feature = "ffmpeg7"))]
AV_PIX_FMT_NE!(AV_PIX_FMT_X2RGB10, AV_PIX_FMT_X2RGB10BE, AV_PIX_FMT_X2RGB10LE);
#[cfg(any(feature = "ffmpeg5", feature = "ffmpeg6"))]
#[cfg(any(feature = "ffmpeg5", feature = "ffmpeg6", feature = "ffmpeg7"))]
AV_PIX_FMT_NE!(AV_PIX_FMT_X2BGR10, AV_PIX_FMT_X2BGR10BE, AV_PIX_FMT_X2BGR10LE);

#[cfg(any(feature = "ffmpeg5", feature = "ffmpeg6"))]
#[cfg(any(feature = "ffmpeg5", feature = "ffmpeg6", feature = "ffmpeg7"))]
AV_PIX_FMT_NE!(AV_PIX_FMT_P210, AV_PIX_FMT_P210BE, AV_PIX_FMT_P210LE);
#[cfg(any(feature = "ffmpeg5", feature = "ffmpeg6"))]
#[cfg(any(feature = "ffmpeg5", feature = "ffmpeg6", feature = "ffmpeg7"))]
AV_PIX_FMT_NE!(AV_PIX_FMT_P410, AV_PIX_FMT_P410BE, AV_PIX_FMT_P410LE);
#[cfg(any(feature = "ffmpeg5", feature = "ffmpeg6"))]
#[cfg(any(feature = "ffmpeg7"))]
AV_PIX_FMT_NE!(AV_PIX_FMT_P212, AV_PIX_FMT_P212BE, AV_PIX_FMT_P212LE);
#[cfg(any(feature = "ffmpeg7"))]
AV_PIX_FMT_NE!(AV_PIX_FMT_P412, AV_PIX_FMT_P412BE, AV_PIX_FMT_P412LE);
#[cfg(any(feature = "ffmpeg5", feature = "ffmpeg6", feature = "ffmpeg7"))]
AV_PIX_FMT_NE!(AV_PIX_FMT_P216, AV_PIX_FMT_P216BE, AV_PIX_FMT_P216LE);
#[cfg(any(feature = "ffmpeg5", feature = "ffmpeg6"))]
#[cfg(any(feature = "ffmpeg5", feature = "ffmpeg6", feature = "ffmpeg7"))]
AV_PIX_FMT_NE!(AV_PIX_FMT_P416, AV_PIX_FMT_P416BE, AV_PIX_FMT_P416LE);

#[cfg(feature = "ffmpeg6")]
#[cfg(any(feature = "ffmpeg6", feature = "ffmpeg7"))]
AV_PIX_FMT_NE!(AV_PIX_FMT_RGBAF16, AV_PIX_FMT_RGBAF16BE, AV_PIX_FMT_RGBAF16LE);

#[cfg(feature = "ffmpeg6")]
#[cfg(any(feature = "ffmpeg6", feature = "ffmpeg7"))]
AV_PIX_FMT_NE!(AV_PIX_FMT_RGBF32, AV_PIX_FMT_RGBF32BE, AV_PIX_FMT_RGBF32LE);
#[cfg(feature = "ffmpeg6")]
#[cfg(any(feature = "ffmpeg6", feature = "ffmpeg7"))]
AV_PIX_FMT_NE!(AV_PIX_FMT_RGBAF32, AV_PIX_FMT_RGBAF32BE, AV_PIX_FMT_RGBAF32LE);

0 comments on commit 23dda1d

Please sign in to comment.