Support FFmpeg 7.0 (#48)

* sys: Run cargo fmt

* sys: Add new channel layout consts

* sys: Update build script for 7.0

- Add new FF_API flags
- Update version_check_info range
- Add ffmpeg_7_0 feature entry

* sys: Update non-exhaustive match statement

* Update enums

* Mark old APIs as removed with 7.0

* Make Audio frame work with 7.0

The .unwrap() in clone() is a bit wonky

* Add API for swr_alloc_set_opts2

* Use AVFrame::duration field in 7.0+

* Include 7.0 in CI runs

* Add fn ChanneLayoutIter::best

* Update examples for new API

* Add/update Context setter for ch layout
This commit is contained in:
FreezyLemon
2024-04-30 03:38:37 +02:00
committed by GitHub
parent 0107b62f56
commit fd2d71c92b
26 changed files with 419 additions and 43 deletions

View File

@ -13,12 +13,16 @@ fn filter(
) -> Result<filter::Graph, ffmpeg::Error> {
let mut filter = filter::Graph::new();
#[cfg(feature = "ffmpeg_5_1")]
let channel_layout = decoder.ch_layout().description();
#[cfg(not(feature = "ffmpeg_5_1"))]
let channel_layout = format!("0x{:x}", decoder.channel_layout().bits());
let args = format!(
"time_base={}:sample_rate={}:sample_fmt={}:channel_layout=0x{:x}",
"time_base={}:sample_rate={}:sample_fmt={}:channel_layout={channel_layout}",
decoder.time_base(),
decoder.rate(),
decoder.format().name(),
decoder.channel_layout().bits()
decoder.format().name()
);
filter.add(&filter::find("abuffer").unwrap(), "in", &args)?;
@ -28,7 +32,10 @@ fn filter(
let mut out = filter.get("out").unwrap();
out.set_sample_format(encoder.format());
#[cfg(not(feature = "ffmpeg_5_1"))]
out.set_channel_layout(encoder.channel_layout());
#[cfg(feature = "ffmpeg_5_1")]
out.set_ch_layout(encoder.ch_layout());
out.set_sample_rate(encoder.rate());
}
@ -88,18 +95,31 @@ fn transcoder<P: AsRef<Path>>(
let context = ffmpeg::codec::context::Context::from_parameters(output.parameters())?;
let mut encoder = context.encoder().audio()?;
let channel_layout = codec
.channel_layouts()
.map(|cls| cls.best(decoder.channel_layout().channels()))
.unwrap_or(ffmpeg::channel_layout::ChannelLayoutMask::STEREO);
if global {
encoder.set_flags(ffmpeg::codec::flag::Flags::GLOBAL_HEADER);
}
#[cfg(feature = "ffmpeg_5_1")]
{
let ch_layout = codec
.ch_layouts()
.map(|cls| cls.best(decoder.ch_layout().channels()))
.unwrap_or(ffmpeg::channel_layout::ChannelLayout::STEREO);
encoder.set_ch_layout(ch_layout);
}
#[cfg(not(feature = "ffmpeg_5_1"))]
{
let channel_layout = codec
.channel_layouts()
.map(|cls| cls.best(decoder.channel_layout().channels()))
.unwrap_or(ffmpeg::channel_layout::ChannelLayoutMask::STEREO);
encoder.set_channel_layout(channel_layout);
encoder.set_channels(channel_layout.channels());
}
encoder.set_rate(decoder.rate() as i32);
encoder.set_channel_layout(channel_layout);
encoder.set_channels(channel_layout.channels());
encoder.set_format(
codec
.formats()