Skip to content

Commit a4a7338

Browse files
authored
Merge pull request #154 from acoustid/ffmpeg-8.0
Upgrade FFmpeg to 8.0
2 parents 122328a + b801357 commit a4a7338

File tree

8 files changed

+132
-2
lines changed

8 files changed

+132
-2
lines changed

CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ set(AUDIO_PROCESSOR_LIB CACHE STRING "Library to use for audio processing")
1313
set_property(CACHE AUDIO_PROCESSOR_LIB PROPERTY STRINGS avresample swresample)
1414

1515
set(FFT_LIB CACHE STRING "Library to use for FFT calculations")
16-
set_property(CACHE FFT_LIB PROPERTY STRINGS avfft fftw3 fftw3f kissfft vdsp)
16+
set_property(CACHE FFT_LIB PROPERTY STRINGS avtx avfft fftw3 fftw3f kissfft vdsp)
1717

1818
option(USE_INTERNAL_AVRESAMPLE "Use internal copy of avresample from ffmpeg for input conversion" ON)
1919

@@ -98,13 +98,16 @@ endif()
9898

9999
set(USE_VDSP OFF)
100100
set(USE_AVFFT OFF)
101+
set(USE_AVTX OFF)
101102
set(USE_FFTW3 OFF)
102103
set(USE_FFTW3F OFF)
103104
set(USE_KISSFFT OFF)
104105

105106
if(NOT FFT_LIB)
106107
if(APPLE AND ACCELERATE_LIBRARIES)
107108
set(FFT_LIB "vdsp")
109+
elseif(FFMPEG_LIBAVUTIL_TX_FOUND)
110+
set(FFT_LIB "avtx")
108111
elseif(FFMPEG_LIBAVCODEC_FFT_FOUND)
109112
set(FFT_LIB "avfft")
110113
elseif(FFTW3_LIBRARIES)
@@ -122,6 +125,12 @@ if(FFT_LIB STREQUAL "vdsp")
122125
else()
123126
message(FATAL_ERROR "Selected ${FFT_LIB} for FFT calculations, but the library is not found")
124127
endif()
128+
elseif(FFT_LIB STREQUAL "avtx")
129+
if(FFMPEG_LIBAVUTIL_TX_FOUND)
130+
set(USE_AVTX ON)
131+
else()
132+
message(FATAL_ERROR "Selected ${FFT_LIB} for FFT calculations, but the library is not found")
133+
endif()
125134
elseif(FFT_LIB STREQUAL "avfft")
126135
if(FFMPEG_LIBAVCODEC_FFT_FOUND)
127136
set(USE_AVFFT ON)

cmake/modules/FindFFmpeg.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ FFMPEG_FIND(LIBAVDEVICE avdevice avdevice.h)
102102
FFMPEG_FIND(LIBAVCODEC avcodec avcodec.h)
103103
FFMPEG_FIND(LIBAVCODEC_FFT avcodec avfft.h)
104104
FFMPEG_FIND(LIBAVUTIL avutil avutil.h)
105+
FFMPEG_FIND(LIBAVUTIL_TX avutil tx.h)
105106
FFMPEG_FIND(LIBSWSCALE swscale swscale.h) # not sure about the header to look for here.
106107
FFMPEG_FIND(LIBSWRESAMPLE swresample swresample.h) # not sure about the header to look for here.
107108
FFMPEG_FIND(LIBAVRESAMPLE avresample avresample.h)

config.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#cmakedefine USE_AVRESAMPLE 1
1111
#cmakedefine USE_INTERNAL_AVRESAMPLE 1
1212

13+
#cmakedefine USE_AVTX 1
1314
#cmakedefine USE_AVFFT 1
1415
#cmakedefine USE_FFTW3 1
1516
#cmakedefine USE_FFTW3F 1

package/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ set -eux
77

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

10-
FFMPEG_VERSION=5.1.2
10+
FFMPEG_VERSION=8.0
1111
FFMPEG_BUILD_TAG=v${FFMPEG_VERSION}-1
1212

1313
TMP_BUILD_DIR=$BASE_DIR/$(mktemp -d build.XXXXXXXX)

src/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ set(chromaprint_SOURCES
3030
set(chromaprint_PUBLIC_SOURCES chromaprint.cpp)
3131
set(chromaprint_PUBLIC_HEADERS chromaprint.h)
3232

33+
if(USE_AVTX)
34+
set(chromaprint_SOURCES fft_lib_avtx.cpp ${chromaprint_SOURCES})
35+
set(chromaprint_LINK_LIBS
36+
${FFMPEG_LIBAVUTIL_LIBRARIES}
37+
)
38+
include_directories(
39+
${FFMPEG_LIBAVUTIL_INCLUDE_DIRS}
40+
)
41+
endif(USE_AVTX)
42+
3343
if(USE_AVFFT)
3444
set(chromaprint_SOURCES fft_lib_avfft.cpp ${chromaprint_SOURCES})
3545
set(chromaprint_LINK_LIBS

src/fft_lib.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
#include <config.h>
99
#endif
1010

11+
#ifdef USE_AVTX
12+
#include "fft_lib_avtx.h"
13+
#endif
14+
1115
#ifdef USE_AVFFT
1216
#include "fft_lib_avfft.h"
1317
#endif

src/fft_lib_avtx.cpp

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Copyright (C) 2010-2016 Lukas Lalinsky
2+
// Distributed under the MIT license, see the LICENSE file for details.
3+
4+
#include "fft_lib_avtx.h"
5+
6+
namespace chromaprint {
7+
8+
FFTLib::FFTLib(size_t frame_size) : m_frame_size(frame_size) {
9+
m_window = (float *) av_malloc(sizeof(float) * frame_size);
10+
m_input = (float *) av_malloc(sizeof(float) * frame_size);
11+
m_output = (AVComplexFloat *) av_malloc(sizeof(AVComplexFloat) * (frame_size / 2 + 1));
12+
PrepareHammingWindow(m_window, m_window + frame_size, 1.0 / INT16_MAX);
13+
14+
// Initialize the RDFT transform context
15+
// For real-to-complex transform: inv=0, no scaling, no special flags
16+
int ret = av_tx_init(&m_tx_ctx, &m_tx_fn, AV_TX_FLOAT_RDFT, 0, frame_size, NULL, 0);
17+
if (ret < 0) {
18+
// Handle initialization error - this should not happen with valid parameters
19+
m_tx_ctx = NULL;
20+
m_tx_fn = NULL;
21+
}
22+
}
23+
24+
FFTLib::~FFTLib() {
25+
av_tx_uninit(&m_tx_ctx);
26+
av_free(m_output);
27+
av_free(m_input);
28+
av_free(m_window);
29+
}
30+
31+
void FFTLib::Load(const int16_t *b1, const int16_t *e1, const int16_t *b2, const int16_t *e2) {
32+
auto window = m_window;
33+
auto output = m_input;
34+
ApplyWindow(b1, e1, window, output);
35+
ApplyWindow(b2, e2, window, output);
36+
}
37+
38+
void FFTLib::Compute(FFTFrame &frame) {
39+
if (!m_tx_ctx || !m_tx_fn) {
40+
// Transform context initialization failed
41+
return;
42+
}
43+
44+
// Perform the real-to-complex FFT
45+
// stride parameter: spacing between input samples in bytes
46+
m_tx_fn(m_tx_ctx, m_output, m_input, sizeof(float));
47+
48+
// Convert complex output to power spectrum
49+
auto input = m_output;
50+
auto output = frame.begin();
51+
52+
// Handle DC component (index 0)
53+
output[0] = input[0].re * input[0].re;
54+
55+
// Handle Nyquist frequency (index frame_size/2)
56+
output[m_frame_size / 2] = input[m_frame_size / 2].re * input[m_frame_size / 2].re;
57+
58+
// Handle intermediate frequencies (indices 1 to frame_size/2-1)
59+
output += 1;
60+
input += 1;
61+
for (size_t i = 1; i < m_frame_size / 2; i++) {
62+
*output++ = input->re * input->re + input->im * input->im;
63+
input++;
64+
}
65+
}
66+
67+
}; // namespace chromaprint

src/fft_lib_avtx.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (C) 2010-2016 Lukas Lalinsky
2+
// Distributed under the MIT license, see the LICENSE file for details.
3+
4+
#ifndef CHROMAPRINT_FFT_LIB_AVTX_H_
5+
#define CHROMAPRINT_FFT_LIB_AVTX_H_
6+
7+
extern "C" {
8+
#include <libavutil/tx.h>
9+
#include <libavutil/mem.h>
10+
}
11+
12+
#include "fft_frame.h"
13+
#include "utils.h"
14+
15+
namespace chromaprint {
16+
17+
class FFTLib {
18+
public:
19+
FFTLib(size_t frame_size);
20+
~FFTLib();
21+
22+
void Load(const int16_t *begin1, const int16_t *end1, const int16_t *begin2, const int16_t *end2);
23+
void Compute(FFTFrame &frame);
24+
25+
private:
26+
CHROMAPRINT_DISABLE_COPY(FFTLib);
27+
28+
size_t m_frame_size;
29+
float *m_window;
30+
float *m_input;
31+
AVComplexFloat *m_output;
32+
AVTXContext *m_tx_ctx;
33+
av_tx_fn m_tx_fn;
34+
};
35+
36+
}; // namespace chromaprint
37+
38+
#endif // CHROMAPRINT_FFT_LIB_AVTX_H_

0 commit comments

Comments
 (0)