Skip to content

Commit 1415a54

Browse files
committed
Merge pull request #127 from cchampet/build_fixLibAV
Fix build compatibility with libav
2 parents a55b2db + ee18afc commit 1415a54

File tree

8 files changed

+68
-40
lines changed

8 files changed

+68
-40
lines changed

INSTALL.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
AvTranscoder uses CMake as build system.
44

5+
#### Dependencies
6+
AvTranscoder can depend on ffmpeg, libav, or any fork of these projects that follow the same API.
7+
* Recommended ffmpeg versions: 2.2.2 or upper
8+
* Recommended libav versions: not tested
9+
510
#### To build
611
```
712
mkdir build && cd build
@@ -12,7 +17,7 @@ make install
1217

1318
#### To indicate a specific ffmpeg/libav folder
1419
```
15-
cmake .. -DFFMPEG_INCLUDE_DIR=/path/to/include/ -DFFMPEG_LIBRARY_DIR=/path/to/lib/
20+
cmake .. -DCMAKE_PREFIX_PATH=/path/to/your/install
1621
```
1722

1823
#### To not build apps
@@ -40,3 +45,20 @@ cmake .. -DCMAKE_INSTALL_PREFIX=/path/to/install
4045
```
4146
cmake .. -DCMAKE_BUILD_TYPE=Release/Debug
4247
```
48+
49+
#### Mac OSX using homebrew
50+
51+
###### Install homebrew
52+
http://brew.sh/
53+
54+
###### Install avTranscoder
55+
```
56+
brew tap cbenhagen/video
57+
brew install avtranscoder
58+
```
59+
60+
###### Use homebrew to install only dependencies
61+
```
62+
brew deps avtranscoder
63+
brew install avtranscoder --only-dependencies
64+
```

cmake/FindFFmpeg.cmake

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -68,32 +68,20 @@ macro(find_component COMPONENT PKGCONFIG LIBRARY HEADER)
6868
endif()
6969

7070
mark_as_advanced(
71+
${COMPONENT}_FOUND
7172
${COMPONENT}_INCLUDE_DIR
7273
${COMPONENT}_LIBRARIES
7374
${COMPONENT}_DEFINITIONS
7475
${COMPONENT}_VERSION
7576
)
7677
endmacro()
7778

78-
# Get FFmpeg from custom install
79-
if(FFMPEG_LIBRARY_DIR AND FFMPEG_INCLUDE_DIR)
80-
set(FFMPEG_FOUND TRUE)
81-
if(WIN32)
82-
file(GLOB FFMPEG_LIBRARIES "${FFMPEG_LIBRARY_DIR}/*.lib")
83-
else()
84-
file(GLOB FFMPEG_LIBRARIES "${FFMPEG_LIBRARY_DIR}/*.so")
85-
endif()
86-
# Get FFmpeg from system install
87-
else()
88-
# Check FFmpeg version
89-
if(DEFINED FFmpeg_FIND_VERSION)
90-
check_ffmpeg_version()
91-
endif()
92-
93-
if(NOT FFmpeg_FIND_COMPONENTS)
94-
set(FFmpeg_FIND_COMPONENTS avcodec avformat avutil)
95-
endif()
96-
79+
### Macro: manage_components
80+
# Define CMake variables for each component defined in FFmpeg_FIND_COMPONENTS
81+
# Send error if a required component is missing (warning if not required)
82+
# Set if FFMPEG is found
83+
#
84+
macro(manage_components)
9785
# Check components and add their stuff to the FFMPEG_* vars.
9886
foreach(COMPONENT ${FFmpeg_FIND_COMPONENTS})
9987
# Get component name is lower cases.
@@ -119,4 +107,17 @@ else()
119107
list(REMOVE_DUPLICATES FFMPEG_INCLUDE_DIR)
120108
set(FFMPEG_FOUND TRUE)
121109
endif()
110+
endmacro()
111+
112+
# Check FFmpeg version
113+
if(DEFINED FFmpeg_FIND_VERSION)
114+
check_ffmpeg_version()
122115
endif()
116+
117+
# Get basic components if no one is indicated
118+
if(NOT FFmpeg_FIND_COMPONENTS)
119+
set(FFmpeg_FIND_COMPONENTS avcodec avformat avutil)
120+
endif()
121+
122+
# Check each component
123+
manage_components()

src/AvTranscoder/Library.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ extern "C" {
55
#include <libavcodec/version.h>
66
#include <libswscale/version.h>
77
#include <libswscale/swscale.h>
8-
#ifdef AV_RESAMPLE_LIBRARY
8+
#ifdef AVTRANSCODER_LIBAV_DEPENDENCY
99
#include <libavresample/version.h>
1010
#else
1111
#include <libswresample/version.h>
@@ -80,7 +80,7 @@ Libraries getLibraries()
8080
libs.push_back( Library( "avutil", avutil_license(), LIBAVUTIL_VERSION_MAJOR, LIBAVUTIL_VERSION_MINOR, LIBAVUTIL_VERSION_MICRO ) );
8181
libs.push_back( Library( "avformat", avformat_license(), LIBAVFORMAT_VERSION_MAJOR, LIBAVFORMAT_VERSION_MINOR, LIBAVFORMAT_VERSION_MICRO ) );
8282
libs.push_back( Library( "avcodec", avcodec_license(), LIBAVCODEC_VERSION_MAJOR, LIBAVCODEC_VERSION_MINOR, LIBAVCODEC_VERSION_MICRO ) );
83-
#ifdef AV_RESAMPLE_LIBRARY
83+
#ifdef AVTRANSCODER_LIBAV_DEPENDENCY
8484
libs.push_back( Library( "avresample", avutil_license(), LIBAVRESAMPLE_VERSION_MAJOR, LIBAVRESAMPLE_VERSION_MINOR, LIBAVRESAMPLE_VERSION_MICRO ) );
8585
#else
8686
libs.push_back( Library( "swresample", avutil_license(), LIBSWRESAMPLE_VERSION_MAJOR, LIBSWRESAMPLE_VERSION_MINOR, LIBSWRESAMPLE_VERSION_MICRO ) );

src/AvTranscoder/frame/Frame.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ void Frame::initAVPacket()
8383

8484
void Frame::copyAVPacket( const AVPacket& avPacket )
8585
{
86-
#if LIBAVCODEC_VERSION_INT > AV_VERSION_INT(55, 56, 108)
86+
#if AVTRANSCODER_FFMPEG_DEPENDENCY && LIBAVCODEC_VERSION_INT > AV_VERSION_INT(55, 56, 108)
8787
av_copy_packet( &_packet, &avPacket );
88-
#elif LIBAVCODEC_VERSION_INT > AV_VERSION_INT(54, 56, 0)
88+
#elif AVTRANSCODER_FFMPEG_DEPENDENCY && LIBAVCODEC_VERSION_INT > AV_VERSION_INT(54, 56, 0)
8989
av_copy_packet( &_packet, const_cast<AVPacket*>( &avPacket ) );
9090
#else
9191
// we just care about data, not side properties of AVPacket

src/AvTranscoder/log.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@ namespace avtranscoder
55

66
void callbackToWriteInFile( void *ptr, int level, const char *fmt, va_list vl )
77
{
8+
std::ofstream outputFile;
9+
outputFile.open( LOG_FILE, std::ios::out | std::ios::app );
10+
11+
#ifdef AVTRANSCODER_FFMPEG_DEPENDENCY
812
// Format a line of log the same way as the default callback
913
char line[1024];
1014
static int print_prefix = 1;
11-
av_log_format_line(ptr, level, fmt, vl, line, sizeof(line), &print_prefix);
12-
13-
// Print line in log file
14-
std::ofstream outputFile;
15-
outputFile.open( LOG_FILE, std::ios::out | std::ios::app );
15+
av_log_format_line(ptr, level, fmt, vl, line, sizeof(line), &print_prefix); //only available with ffmpeg
1616
outputFile << line;
17+
#else
18+
outputFile << "Warning: currently can't log in file with avtranscoder when depending on libav" << std::endl;
19+
#endif
20+
1721
outputFile.close();
1822
}
1923

src/AvTranscoder/transform/AudioTransform.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ extern "C" {
66
#include <libavcodec/avcodec.h>
77
#include <libavutil/opt.h>
88

9-
#ifdef AV_RESAMPLE_LIBRARY
9+
#ifdef AVTRANSCODER_LIBAV_DEPENDENCY
1010
#include <libavresample/avresample.h>
1111
#define AllocResampleContext avresample_alloc_context
1212
#define FreeResampleContext avresample_free
@@ -99,7 +99,7 @@ void AudioTransform::convert( const Frame& srcFrame, Frame& dstFrame )
9999
unsigned char* dstData = dstFrame.getData();
100100

101101
int nbOutputSamplesPerChannel;
102-
#ifdef AV_RESAMPLE_LIBRARY
102+
#ifdef AVTRANSCODER_LIBAV_DEPENDENCY
103103
nbOutputSamplesPerChannel = avresample_convert( _audioConvertContext, (uint8_t**)&dstData, 0, nbSamplesOfCurrentFrame, (uint8_t**)&srcData, 0, nbSamplesOfCurrentFrame );
104104
#else
105105
nbOutputSamplesPerChannel = swr_convert( _audioConvertContext, &dstData, nbSamplesOfCurrentFrame, &srcData, nbSamplesOfCurrentFrame );

src/AvTranscoder/transform/AudioTransform.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <AvTranscoder/common.hpp>
77
#include <AvTranscoder/frame/Frame.hpp>
88

9-
#ifdef AV_RESAMPLE_LIBRARY
9+
#ifdef AVTRANSCODER_LIBAV_DEPENDENCY
1010
#define ResampleContext AVAudioResampleContext
1111
#else
1212
#define ResampleContext SwrContext

src/CMakeLists.txt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
33
include(AvTranscoderMacros)
44

5-
##find_package(FFmpeg)
6-
find_package(FFmpeg
7-
COMPONENTS avcodec avformat avutil swscale swresample avresample)
5+
# find package ffmpeg/libav
6+
find_package(FFmpeg COMPONENTS avcodec avformat avutil swscale swresample avresample)
87

98
# Check if FFmpeg or libav dependency
10-
if(avresample_VERSION)
11-
add_definitions(-DAV_RESAMPLE_LIBRARY)
12-
elseif(swresample_VERSION)
13-
add_definitions(-DFF_RESAMPLE_LIBRARY)
9+
if(avresample_FOUND)
10+
add_definitions(-DAVTRANSCODER_LIBAV_DEPENDENCY)
11+
message("Build avTranscoder with dependency to libav.")
12+
elseif(swresample_FOUND)
13+
add_definitions(-DAVTRANSCODER_FFMPEG_DEPENDENCY)
14+
message("Build avTranscoder with dependency to ffmpeg.")
1415
else()
15-
message(SEND_ERROR, "Need 'swresample' or 'avresample'.")
16+
message(SEND_ERROR "Can't define if you depend on ffmpeg or libav.")
1617
endif()
1718

1819
# Include AvTranscoder and FFmpeg

0 commit comments

Comments
 (0)