Skip to content

Commit

Permalink
Windows: use ffmpeg from Rtools when available (#57)
Browse files Browse the repository at this point in the history
Also relax a few tests for RHEL/Fedora builds.
  • Loading branch information
jeroen authored Jan 28, 2025
1 parent f924ee4 commit 86f8aa7
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
- {os: macos-14, r: 'release'}
- {os: windows-latest, r: '4.1'}
- {os: windows-latest, r: '4.2'}
- {os: windows-latest, r: '4.3'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-24.04, r: 'release'}
Expand Down
54 changes: 54 additions & 0 deletions .github/workflows/RHEL-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
on:
push:
workflow_dispatch:

name: rhel.yaml

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
# cancel-in-progress: true

permissions: read-all

jobs:
rhel:
runs-on: ubuntu-latest
name: ${{ matrix.config.os }} (${{ matrix.config.r }})
strategy:
fail-fast: false
matrix:
config:
# cannot run the nodejs actions because RHEL7 cannot run node20
# - { os: rhel7, r: release, key: REDHAT_ACTIVATION_KEY_RHEL7 }
- { os: rhel8, r: release }
- { os: rhel9, r: release }
container:
image: ghcr.io/r-hub/containers/${{ matrix.config.os }}:latest

steps:
- uses: actions/checkout@v4

- name: Register
run: |
subscription-manager register \
--org ${{ secrets.REDHAT_ORG }} \
--activationkey ${{ secrets.REDHAT_KEY }}
shell: bash

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check

- name: Unregister
if: always()
run: |
subscription-manager unregister || true
- uses: r-lib/actions/check-r-package@v2
with:
args: '"--no-manual"'
env:
NOT_CRAN: true
_R_CHECK_DOC_SIZES_: FALSE
LANG: en_US.UTF-8
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
0.9.4
- Windows: use ffmpeg from Rtools when available
- Relax unit tests for libavfilter-free-devel on RedHat/Fedora

0.9.3
- Fixes for ffmpeg 7.1
- Cleanup configure script
Expand Down
20 changes: 16 additions & 4 deletions src/Makevars.win
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
PKG_CONFIG_NAME = libavfilter
PKG_CONFIG ?= $(BINPREF)pkg-config
PKG_LIBS := $(shell $(PKG_CONFIG) --libs $(PKG_CONFIG_NAME))

# See https://bugs.r-project.org/show_bug.cgi?id=18835
ifneq ($(findstring mp3lame,$(PKG_LIBS)),)
$(info using ffmpeg from Rtools)
PKG_CPPFLAGS := $(shell $(PKG_CONFIG) --cflags $(PKG_CONFIG_NAME))
else
RWINLIB = ../windows/ffmpeg
PKG_CPPFLAGS = -I$(RWINLIB)/include -D__USE_MINGW_ANSI_STDIO=1 -DR_NO_REMAP -DSTRICT_R_HEADERS
PKG_LIBS = -L$(RWINLIB)/lib${subst gcc,,$(COMPILED_BY)}$(R_ARCH) \
Expand All @@ -6,11 +15,14 @@ PKG_LIBS = -L$(RWINLIB)/lib${subst gcc,,$(COMPILED_BY)}$(R_ARCH) \
-lvorbis -lvorbisenc -logg -lvpx \
-lbz2 -lsecur32 -lws2_32 -liconv -lz -lmp3lame -lx264 \
-lxvidcore -pthread -lole32 -lm -luser32 -lbcrypt -lmfplat -lmfuuid -lstrmiids
endif

all: winlibs clean
all: $(SHLIB)

clean:
rm -f $(SHLIB) $(OBJECTS)
$(OBJECTS): $(RWINLIB)

winlibs:
$(RWINLIB):
"${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" "../tools/winlibs.R"

clean:
rm -f $(SHLIB) $(OBJECTS)
2 changes: 1 addition & 1 deletion tests/testthat/test-audio.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test_that("Audio can be converted to various formats", {
input_info <- av_media_info(wonderland)

# Convert mp3 to mkv (defaults to libvorbis audio)
expect_equal(av_audio_convert(wonderland, tmp_mkv, verbose = FALSE), tmp_mkv)
expect_equal(av_audio_convert(wonderland, tmp_mkv, verbose = FALSE, sample_rate = 16000), tmp_mkv)
expect_true(file.exists(tmp_mkv))
mkv_info <- av_media_info(tmp_mkv)
expect_equal(input_info$duration, mkv_info$duration, tolerance = 0.1)
Expand Down
5 changes: 3 additions & 2 deletions tests/testthat/test-fft.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ test_that("Audio FFT", {
av_log_level(16) # muffle some warnings about ac3 vbr
for(ext in extensions){
filename <- paste0('wonderland.', ext)
av_audio_convert(wonderland, filename, verbose = FALSE)
# libopus on fedora does not do support input sample_rate 44100
av_audio_convert(wonderland, filename, verbose = FALSE, sample_rate = 48000)
data <- read_audio_fft(filename, window = hanning(2048))
expect_equal(dim(data)[1], 1024)
expect_equal(dim(data)[2], 2584, tol = 0.001)
expect_equal(dim(data)[2], 2813, tol = 0.001)
unlink(filename)
}
})
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-formats.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,15 @@ test_that("Listing formats", {
expect_equal(names(decoders), c("type", "name", "description", "format"))
expect_equal(names(filters), c("name", "description"))
})

test_that("Critical encoders", {
encoders <- av_encoders()
expect_contains(encoders$name, 'libmp3lame')
expect_contains(encoders$name, 'libvorbis')
expect_contains(encoders$name, 'libxvid')
if(!grepl("(Fedora|Red Hat)", osVersion)){
# libx264 is not supported on RHEL/Fedora libavfilter-free-devel but it is
# in ffmpeg-devel from rpmfusion.
expect_contains(encoders$name, 'libx264')
}
})
9 changes: 7 additions & 2 deletions tests/testthat/test-video.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ test_that("convert images into video formats", {
test_that("audio sampling works", {
for(ext in c("mkv", "mp4", "mov", "flv")){
filename <- paste0("test.", ext)
if(ext == 'mkv' && grepl("(Fedora|Red Hat)", osVersion)){
# libavfilter-free-devel only supports certain audio bitrates
wonderland <- av_audio_convert(wonderland, tempfile(fileext = '.mka'), sample_rate = 48000, verbose = FALSE)
}
input_rate <- av_media_info(wonderland)$audio$sample_rate
av::av_encode_video(png_files, filename, framerate = framerate, verbose = FALSE, audio = wonderland)
expect_true(file.exists(filename))
info <- av_media_info(filename)
Expand All @@ -70,7 +75,7 @@ test_that("audio sampling works", {
expect_equal(info$video$framerate, framerate)

expect_equal(info$audio$channels, 2)
expect_equal(info$audio$sample_rate, 44100)
expect_equal(info$audio$sample_rate, input_rate)

# Audio stream may slightly alter the duration, 5% margin
expect_equal(info$duration, n / framerate, tolerance = 0.05)
Expand All @@ -84,7 +89,7 @@ test_that("audio sampling works", {
expect_equal(info$video$framerate, framerate)

expect_equal(info$audio$channels, 2)
expect_equal(info$audio$sample_rate, 44100)
expect_equal(info$audio$sample_rate, input_rate)

# Audio stream may slightly alter the duration, 5% margin
expect_equal(info$duration, n / framerate, tolerance = 0.05)
Expand Down

0 comments on commit 86f8aa7

Please sign in to comment.