Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 38 additions & 105 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ jobs:
build-linux:
name: build / ${{ matrix.platform }} / ffmpeg-${{ matrix.ffmpeg_version }}
runs-on: ubuntu-latest
container:
image: jrottenberg/ffmpeg:${{ matrix.ffmpeg_version }}-ubuntu

env:
DOCKER_DEFAULT_PLATFORM: ${{ matrix.platform }}
FFMPEG_INCLUDE_DIR: /usr/local/include
FFMPEG_PKG_CONFIG_PATH: /usr/local/lib/pkgconfig

strategy:
fail-fast: false
Expand All @@ -30,26 +37,20 @@ jobs:
ffmpeg_version: ["6.1", "7.1", "8.0"]
include:
- ffmpeg_version: "6.1"
lib_subdir: "amd64"
file: "ffmpeg-6.1-linux-clang-default.tar.xz"
feature: "ndarray,ffmpeg6,link_system_ffmpeg"
- ffmpeg_version: "7.1"
lib_subdir: "amd64"
file: "ffmpeg-7.1-linux-clang-default.tar.xz"
feature: "ndarray,ffmpeg7,link_system_ffmpeg"
- ffmpeg_version: "8.0"
lib_subdir: "amd64"
file: "ffmpeg-8.0-linux-clang-default.tar.xz"
feature: "ndarray,ffmpeg8,link_system_ffmpeg"

steps:
- name: Checkout
uses: actions/checkout@v5
uses: actions/checkout@v6

- name: Install dependencies
run: |
DEBIAN_FRONTEND=noninteractive sudo apt-get update
DEBIAN_FRONTEND=noninteractive sudo apt-get install -y --no-install-recommends \
DEBIAN_FRONTEND=noninteractive apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
nasm \
yasm \
curl \
Expand Down Expand Up @@ -147,25 +148,14 @@ jobs:
## libswscale-dev \
## libswresample-dev \

- name: Download FFmpeg-${{ matrix.ffmpeg_version }}
shell: bash
run: |
mkdir ffmpeg_home
curl -L "https://sourceforge.net/projects/avbuild/files/linux/${{ matrix.file }}/download" \
| tar xJf - --strip 1 -C ffmpeg_home

echo "FFMPEG_INCLUDE_DIR=$PWD/ffmpeg_home/include" >> "$GITHUB_ENV"
echo "PKG_CONFIG_PATH=$PWD/ffmpeg_home/lib/${{ matrix.lib_subdir }}/pkgconfig" >> "$GITHUB_ENV"
echo "LD_LIBRARY_PATH=$PWD/ffmpeg_home/lib/${{ matrix.lib_subdir }}" >> "$GITHUB_ENV"

- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: nightly
components: rustfmt, clippy, rust-src, llvm-tools-preview, rust-analysis

- name: Clippy check
run: cargo clippy --no-default-features --features ${{ matrix.feature }} -- -D warnings
run: cargo clippy --all --no-default-features --features ${{ matrix.feature }} -- -D warnings

- name: Build
run: cargo build --no-default-features --features ${{ matrix.feature }} --verbose
Expand All @@ -192,10 +182,12 @@ jobs:
env:
FFMPEG_PKG_CONFIG_PATH: /opt/homebrew/opt/ffmpeg@${{ matrix.ffmpeg_version }}/lib/pkgconfig
FFMPEG_INCLUDE_DIR: /opt/homebrew/opt/ffmpeg@${{ matrix.ffmpeg_version }}/include
CPPFLAGS: "-I/opt/homebrew/opt/ffmpeg@${{ matrix.ffmpeg_version }}/include"
LDFLAGS: "-L/opt/homebrew/opt/ffmpeg@${{ matrix.ffmpeg_version }}/lib"

steps:
- name: Checkout
uses: actions/checkout@v5
uses: actions/checkout@v6

- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
Expand All @@ -204,7 +196,7 @@ jobs:
components: rustfmt, clippy

- name: Cache Cargo
uses: actions/cache@v4
uses: actions/cache@v5
with:
path: |
~/.cargo/registry
Expand All @@ -224,105 +216,45 @@ jobs:
run: cargo test --all --no-default-features --features ${{ matrix.feature }} --verbose -- --nocapture

build-windows:
name: build / windows-${{ matrix.config.vcpkg_triplet }} / ffmpeg-7.1
name: build / windows / ffmpeg-8.1
runs-on: windows-latest

env:
FFMPEG_VERSION: "7.1"
BUILD_FEATURES: "ndarray,ffmpeg7,link_vcpkg_ffmpeg"

strategy:
matrix:
config:
- target: "x86_64-pc-windows-msvc"
vcpkg_triplet: "x64-windows-static"
rustflags: "-Ctarget-feature=+crt-static"
- target: "x86_64-pc-windows-msvc"
vcpkg_triplet: "x64-windows-static-md"
- target: "x86_64-pc-windows-msvc"
vcpkg_triplet: "x64-windows"
dynamic: true
fail-fast: false
FFMPEG_VERSION: "8.1"
BUILD_FEATURES: "ndarray,ffmpeg8,link_vcpkg_ffmpeg"
FFMPEG_DOWNLOAD_URL: https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-full-shared.7z

steps:
- name: Checkout
uses: actions/checkout@v5
uses: actions/checkout@v6

- name: Cache Cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Install dependencies
run: |
$VCINSTALLDIR = $(& "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property installationPath)
Add-Content $env:GITHUB_ENV "LIBCLANG_PATH=${VCINSTALLDIR}\VC\Tools\LLVM\x64\bin"
Invoke-WebRequest "${env:FFMPEG_DOWNLOAD_URL}" -OutFile ffmpeg-release-full-shared.7z
7z x ffmpeg-release-full-shared.7z
mkdir ffmpeg
mv ffmpeg-*/* ffmpeg/
Add-Content $env:GITHUB_PATH "${pwd}\ffmpeg\bin"
Add-Content $env:GITHUB_ENV "FFMPEG_DIR=${pwd}\ffmpeg"
Add-Content $env:GITHUB_ENV "FFMPEG_LIBS_DIR=${pwd}\ffmpeg\lib"
Add-Content $env:GITHUB_ENV "FFMPEG_INCLUDE_DIR=${pwd}\ffmpeg\include"

- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: nightly
components: rustfmt, clippy
targets: ${{ matrix.config.target }}

# Using this since it's used by clang-sys's CI
- name: Install LLVM and Clang
uses: KyleMayes/install-llvm-action@v2
with:
version: "10.0"
directory: ${{ github.workspace }}/clang

- name: Cache vcpkg
id: cache
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/vcpkg
key: vcpkg-${{ runner.os }}-${{ matrix.config.vcpkg_triplet }}

- name: Build vcpkg
if: steps.cache.outputs.cache-hit != 'true'
run: |
git clone https://github.com/microsoft/vcpkg --depth 1
./vcpkg/bootstrap-vcpkg.bat

- name: Install Dependencies
run: |
./vcpkg/vcpkg.exe install ffmpeg:${{ matrix.config.vcpkg_triplet }}

- name: Set env
shell: bash
run: |
if [ '${{ matrix.config.dynamic }}' != '' ]; then
echo "VCPKGRS_DYNAMIC=1" >> $GITHUB_ENV
fi

- name: Clippy check
shell: bash
env:
RUSTFLAGS: ${{ matrix.config.rustflags }}
VCPKG_ROOT: ${{ github.workspace }}/vcpkg
VCPKG_DEFAULT_TRIPLET: ${{ matrix.config.vcpkg_triplet }}
LIBCLANG_PATH: ${{ github.workspace }}/clang/lib
LLVM_CONFIG_PATH: ${{ github.workspace }}/clang/bin/llvm-config
run: cargo clippy --no-default-features --features ${{ env.BUILD_FEATURES }} --target ${{ matrix.config.target }} -- -D warnings
run: cargo clippy --no-default-features --features ${{ env.BUILD_FEATURES }} -- -D warnings

- name: Build
shell: bash
env:
RUSTFLAGS: ${{ matrix.config.rustflags }}
VCPKG_ROOT: ${{ github.workspace }}/vcpkg
VCPKG_DEFAULT_TRIPLET: ${{ matrix.config.vcpkg_triplet }}
LIBCLANG_PATH: ${{ github.workspace }}/clang/lib
LLVM_CONFIG_PATH: ${{ github.workspace }}/clang/bin/llvm-config
run: cargo build --no-default-features --features ${{ env.BUILD_FEATURES }} --target ${{ matrix.config.target }} --verbose
run: cargo build --no-default-features --features ${{ env.BUILD_FEATURES }} --verbose

- name: Run Test
shell: bash
env:
RUSTFLAGS: ${{ matrix.config.rustflags }}
VCPKG_ROOT: ${{ github.workspace }}/vcpkg
VCPKG_DEFAULT_TRIPLET: ${{ matrix.config.vcpkg_triplet }}
LIBCLANG_PATH: ${{ github.workspace }}/clang/lib
LLVM_CONFIG_PATH: ${{ github.workspace }}/clang/bin/llvm-config
run: cargo test --no-default-features --features ${{ env.BUILD_FEATURES }} --target ${{ matrix.config.target }} --verbose -- --nocapture
run: cargo test --no-default-features --features ${{ env.BUILD_FEATURES }} --verbose -- --nocapture

test_and_clippy:
name: Clippy & Test / ${{ matrix.platform }} / ffmpeg-${{ matrix.ffmpeg_version }}
Expand Down Expand Up @@ -350,12 +282,13 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v5
uses: actions/checkout@v6

- name: Install dependencies
run: |
DEBIAN_FRONTEND=noninteractive apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
jq \
nasm \
yasm \
curl \
Expand Down Expand Up @@ -467,7 +400,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v5
uses: actions/checkout@v6

- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
Expand Down
24 changes: 12 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,41 +31,41 @@ colorous = "1.0"
colorutils-rs = "0.7"
palette = "0.7"
image = "0.25"
imageproc = "0.25"
imageproc = "0.26"
num-traits = "0.2"
anyhow = "1.0"
log = "0.4"
tracing = "0.1"
url = "2.5"
rand = "0.9"
rayon = "1.10"
rand = "0.10"
rayon = "1.11"
dashmap = "6.1"
once_cell = "1.21"
num_cpus = "1.17"
ndarray = { version = "0.16", optional = true }
ndarray = { version = "0.17", optional = true }
rsmpeg = { git = "https://github.com/larksuite/rsmpeg", default-features = false }

[dev-dependencies]
libc = "0.2"
camino = "1.1"
camino = "1.2"
chrono = "0.4"
ringbuf = "0.4"
ctor = "0.5"
ctor = "0.6"
tracing-subscriber = { version = "0.3", features = ["fmt", "env-filter", "chrono"] }
ab_glyph = "0.2"
libblur = "0.20"
pic-scale = "0.6"
fast_image_resize = "5.1"
libblur = "0.23"
pic-scale = "0.7"
fast_image_resize = "6.0"
histogram_equalization = "0.2"
## security & async
futures = "0.3"
tokio = { version = "1", features = ["full"] }
## sound & audio
cpal = "0.16"
cpal = "0.17"
wavers = "1.5"
rubato = "0.16"
rubato = "1.0"
dasp = { version = "0.11", features = ["all"] }
rodio = { version = "0.21", features = ["symphonia-all", "tracing"] }
rodio = { version = "0.22", features = ["symphonia-all", "tracing"] }

[build-dependencies]
vcpkg = { version = "0.2", optional = true }
Expand Down
8 changes: 7 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,13 @@ fn configure_linux(target_arch: &str) {

fn configure_windows(target_arch: &str) {
// 获取 VCPKG_ROOT 并检查 triplet
let vcpkg_root = PathBuf::from(env::var("VCPKG_ROOT").expect("VCPKG_ROOT not found"));
let vcpkg_root = match env::var("VCPKG_ROOT") {
Ok(path) => PathBuf::from(path),
Err(_) => {
eprintln!("VCPKG_ROOT environment variable is not set");
return;
}
};
let triplets = if target_arch == "x86_64" {
vec![
"x64-windows",
Expand Down
16 changes: 8 additions & 8 deletions examples/audio_recorder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anyhow::Result;
use chrono::Local;
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
use cpal::{Device, SampleFormat, Stream, StreamConfig};
use rodio::{Decoder, Sink};
use rodio::{Decoder, DeviceSinkBuilder};
use std::fs::File;
use std::io::{BufReader, Write};
use std::path::Path;
Expand Down Expand Up @@ -30,11 +30,11 @@ impl AudioRecorder {
.default_input_device()
.ok_or_else(|| anyhow::anyhow!("未找到输入设备"))?;

println!("使用输入设备: {}", device.name()?);
println!("使用输入设备: {}", device.description()?);

let config: StreamConfig = device.default_input_config()?.into();

println!("采样率: {} Hz", config.sample_rate.0);
println!("采样率: {} Hz", config.sample_rate);
println!("通道数: {}", config.channels);

Ok(Self {
Expand Down Expand Up @@ -124,7 +124,7 @@ impl AudioRecorder {
/// 保存录音到WAV文件
pub fn save_to_wav(&self, filename: &str) -> Result<()> {
let samples = self.recording_buffer.lock().unwrap();
let sample_rate = self.config.sample_rate.0 as i32;
let sample_rate = self.config.sample_rate as i32;
let n_channels = self.config.channels;

// 使用 wavers 的 write 函数保存 WAV 文件
Expand Down Expand Up @@ -259,15 +259,15 @@ impl RecordingController {
println!("时长: {:.2} 秒", wav.duration());

// 使用 rodio 播放音频
let stream_handle = rodio::OutputStreamBuilder::open_default_stream().unwrap();
let sink = Sink::connect_new(&stream_handle.mixer());
let stream_handle = DeviceSinkBuilder::open_default_sink().unwrap();
let player = rodio::Player::connect_new(stream_handle.mixer());

let file = File::open(filename)?;
let source = Decoder::new(BufReader::new(file))?;
sink.append(source);
player.append(source);

println!("播放中... (按 Ctrl+C 停止)");
sink.sleep_until_end();
player.sleep_until_end();
Ok(())
}
}
Expand Down
Loading
Loading