Skip to content

Commit

Permalink
Use FFmpeg 5.x (#120)
Browse files Browse the repository at this point in the history
* Use FFmpeg 5.1.2 for CI builds

* Build on Ubuntu 20.04

* Upgrade code to FFmpeg 5.x APIs

* Only set FFmpeg include dirs if building tools

* No longer needed

* Use ubuntu 20.04
  • Loading branch information
lalinsky committed Nov 4, 2022
1 parent 41e23c2 commit 8ccad69
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 199 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Expand Up @@ -6,7 +6,7 @@ on:

jobs:
test-linux:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
strategy:
matrix:
fft:
Expand Down Expand Up @@ -50,7 +50,7 @@ jobs:
make check VERBOSE=1
package-linux:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
strategy:
matrix:
arch:
Expand All @@ -71,7 +71,7 @@ jobs:
path: artifacts/

package-windows:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
strategy:
matrix:
arch:
Expand Down
16 changes: 0 additions & 16 deletions CMakeLists.txt
Expand Up @@ -84,9 +84,6 @@ find_package(FFmpeg)
if(FFMPEG_LIBRARIES)
cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_LIBRARIES ${FFMPEG_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} -lm)
check_function_exists(av_packet_unref HAVE_AV_PACKET_UNREF)
check_function_exists(av_frame_alloc HAVE_AV_FRAME_ALLOC)
check_function_exists(av_frame_free HAVE_AV_FRAME_FREE)
cmake_pop_check_state()
endif()

Expand Down Expand Up @@ -163,31 +160,18 @@ message(STATUS "Using ${FFT_LIB} for FFT calculations")
if(NOT AUDIO_PROCESSOR_LIB)
if(FFMPEG_LIBSWRESAMPLE_FOUND)
set(AUDIO_PROCESSOR_LIB "swresample")
elseif(FFMPEG_LIBAVRESAMPLE_FOUND)
set(AUDIO_PROCESSOR_LIB "avresample")
endif()
endif()

if(AUDIO_PROCESSOR_LIB STREQUAL "swresample")
if(FFMPEG_LIBSWRESAMPLE_FOUND)
set(USE_AVRESAMPLE OFF)
set(USE_SWRESAMPLE ON)
set(AUDIO_PROCESSOR_LIBRARIES ${FFMPEG_LIBSWRESAMPLE_LIBRARIES})
set(AUDIO_PROCESSOR_INCLUDE_DIRS ${FFMPEG_LIBSWRESAMPLE_INCLUDE_DIRS})
else()
message(FATAL_ERROR "Selected ${AUDIO_PROCESSOR_LIB} for audio processing, but the library is not found")
endif()
message(STATUS "Using ${AUDIO_PROCESSOR_LIB} for audio conversion")
elseif(AUDIO_PROCESSOR_LIB STREQUAL "avresample")
if(FFMPEG_LIBAVRESAMPLE_FOUND)
set(USE_AVRESAMPLE ON)
set(USE_SWRESAMPLE OFF)
set(AUDIO_PROCESSOR_LIBRARIES ${FFMPEG_LIBAVRESAMPLE_LIBRARIES})
set(AUDIO_PROCESSOR_INCLUDE_DIRS ${FFMPEG_LIBAVRESAMPLE_INCLUDE_DIRS})
else()
message(FATAL_ERROR "Selected ${AUDIO_PROCESSOR_LIB} for audio processing, but the library is not found")
endif()
message(STATUS "Using ${AUDIO_PROCESSOR_LIB} for audio conversion")
else()
message(STATUS "Building without audio conversion support, please install FFmpeg with libswresample")
endif()
Expand Down
4 changes: 2 additions & 2 deletions package/build.sh
Expand Up @@ -7,8 +7,8 @@ set -eux

BASE_DIR=$(cd $(dirname $0)/.. && pwd)

FFMPEG_VERSION=4.4.1
FFMPEG_BUILD_TAG=v4.4.1-2
FFMPEG_VERSION=5.1.2
FFMPEG_BUILD_TAG=v${FFMPEG_VERSION}-1

TMP_BUILD_DIR=$BASE_DIR/$(mktemp -d build.XXXXXXXX)
trap 'rm -rf $TMP_BUILD_DIR' EXIT
Expand Down
2 changes: 0 additions & 2 deletions src/audio/ffmpeg_audio_processor.h
Expand Up @@ -10,8 +10,6 @@

#if defined(USE_SWRESAMPLE)
#include "audio/ffmpeg_audio_processor_swresample.h"
#elif defined(USE_AVRESAMPLE)
#include "audio/ffmpeg_audio_processor_avresample.h"
#else
#error "no audio processing library"
#endif
Expand Down
72 changes: 0 additions & 72 deletions src/audio/ffmpeg_audio_processor_avresample.h

This file was deleted.

18 changes: 8 additions & 10 deletions src/audio/ffmpeg_audio_processor_swresample.h
Expand Up @@ -28,30 +28,28 @@ class FFmpegAudioProcessor {
av_opt_set_double(m_swr_ctx, "cutoff", 0.8, 0);
}

void SetInputChannelLayout(int64_t channel_layout) {
av_opt_set_int(m_swr_ctx, "icl", channel_layout, 0);
av_opt_set_int(m_swr_ctx, "ich", av_get_channel_layout_nb_channels(channel_layout), 0);
void SetInputChannelLayout(AVChannelLayout *channel_layout) {
av_opt_set_int(m_swr_ctx, "in_channel_layout", channel_layout->u.mask, 0);
}

void SetInputSampleFormat(AVSampleFormat sample_format) {
av_opt_set_int(m_swr_ctx, "isf", sample_format, 0);
av_opt_set_sample_fmt(m_swr_ctx, "in_sample_fmt", sample_format, 0);
}

void SetInputSampleRate(int sample_rate) {
av_opt_set_int(m_swr_ctx, "isr", sample_rate, 0);
av_opt_set_int(m_swr_ctx, "in_sample_rate", sample_rate, 0);
}

void SetOutputChannelLayout(int64_t channel_layout) {
av_opt_set_int(m_swr_ctx, "ocl", channel_layout, 0);
av_opt_set_int(m_swr_ctx, "och", av_get_channel_layout_nb_channels(channel_layout), 0);
void SetOutputChannelLayout(AVChannelLayout *channel_layout) {
av_opt_set_int(m_swr_ctx, "out_channel_layout", channel_layout->u.mask, 0);
}

void SetOutputSampleFormat(AVSampleFormat sample_format) {
av_opt_set_int(m_swr_ctx, "osf", sample_format, 0);
av_opt_set_sample_fmt(m_swr_ctx, "out_sample_fmt", sample_format, 0);
}

void SetOutputSampleRate(int sample_rate) {
av_opt_set_int(m_swr_ctx, "osr", sample_rate, 0);
av_opt_set_int(m_swr_ctx, "out_sample_rate", sample_rate, 0);
}

int Init() {
Expand Down

0 comments on commit 8ccad69

Please sign in to comment.