Skip to content

Commit 1099801

Browse files
Add support for decoding input with ffmpeg libs in main (Linux)
- search for ffmpeg at cmake time - include ffmpegs/libav headers in main.cpp Todo: - if needed convert input file to wav 16khz in main.cpp
1 parent 58210d6 commit 1099801

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

CMakeLists.txt

+21
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ option(WHISPER_BUILD_EXAMPLES "whisper: build examples" ${WHISPER_STANDA
5959

6060
option(WHISPER_SDL2 "whisper: support for libSDL2" OFF)
6161

62+
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
63+
option(WHISPER_FFMPEG "whisper: support building and linking with ffmpeg libs" OFF)
64+
endif()
65+
6266
option(WHISPER_NO_AVX "whisper: disable AVX" OFF)
6367
option(WHISPER_NO_AVX2 "whisper: disable AVX2" OFF)
6468
option(WHISPER_NO_AVX512 "whisper: disable AVX512" ON)
@@ -125,6 +129,23 @@ else()
125129
set(CMAKE_CXX_STANDARD 11)
126130
endif()
127131

132+
if (WHISPER_FFMPEG)
133+
# As today (cmake 3.27), there is no official cmake support for FindFFmpeg. eg: not possible:
134+
# find_package(FFmpeg COMPONENTS AVCODEC AVFORMAT AVUTIL AVDEVICE REQUIRED)
135+
# Check with reviewers: worth to embed a FindFFmpeg.cmake script in whisper.cpp ?
136+
# eg https://github.com/snikulov/cmake-modules/blob/master/FindFFmpeg.cmake
137+
# Using PkgConfig atm:
138+
find_package(PkgConfig REQUIRED)
139+
pkg_check_modules(FFMPEG REQUIRED IMPORTED_TARGET libavdevice libavfilter libavformat libavcodec libswresample libswscale libavutil)
140+
if (NOT ${FFMPEG_FOUND})
141+
message(FATAL_ERROR "Cannot find ffmpeg libs/headers")
142+
endif()
143+
message(STATUS "Found ffmpeg headers in: ${FFMPEG_INCLUDE_DIRS}")
144+
include_directories(${FFMPEG_INCLUDE_DIRS})
145+
add_compile_definitions(WHISPER_FFMPEG)
146+
set(WHISPER_EXTRA_LIBS ${WHISPER_EXTRA_LIBS} PkgConfig::FFMPEG)
147+
endif()
148+
128149
# on APPLE
129150
if (APPLE)
130151
# include Accelerate framework

examples/main/CMakeLists.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@ add_executable(${TARGET} main.cpp)
33

44
include(DefaultTargetOptions)
55

6-
target_link_libraries(${TARGET} PRIVATE common whisper ${CMAKE_THREAD_LIBS_INIT})
6+
if (WHISPER_FFMPEG)
7+
target_link_libraries(${TARGET} PRIVATE common whisper ${CMAKE_THREAD_LIBS_INIT} PkgConfig::FFMPEG)
8+
else()
9+
target_link_libraries(${TARGET} PRIVATE common whisper ${CMAKE_THREAD_LIBS_INIT})
10+
endif()

examples/main/main.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
#include "whisper.h"
44
#include "grammar-parser.h"
55

6+
#ifdef WHISPER_FFMPEG
7+
#include <libavutil/frame.h>
8+
#include <libavutil/mem.h>
9+
#include <libavcodec/avcodec.h>
10+
#endif
11+
612
#include <cmath>
713
#include <fstream>
814
#include <cstdio>

0 commit comments

Comments
 (0)