Skip to content

Commit e879188

Browse files
authored
FFmpeg 3 & 4 support, Travis CI support, OpenMP schedule change (#160)
* FFmpeg4 support. Compile warnings fixes. Credit goes to many people, including ferdnyc, peterM, and other awesome folks! * Adding environment checking to enable/disable omp taskwait after each video/audio frame is processed. This is experimental for some users with crashes. * Moving `omp taskwait` to after the ProcessVideoPacket() method, since that is the only place it is useful. * Fixing crashes on missing Clip source file, and changing FFmpeg scaling algorthm from SWS_BILINEAR to SWS_LANCZOS (for higher quality scaling) * Update FindFFmpeg.cmake module, and updating build script. Also enabling debug builds. * Updating experimental travis build script * Fixed unit test for newer version of FFmpeg (audio resampling) * Experimental travis multiple jobs * Adding OMP schedule hint (thanks PeterM), which prevents crashes in some circumstances.
1 parent 1989b09 commit e879188

19 files changed

+571
-307
lines changed

.travis.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
dist: trusty
2+
3+
matrix:
4+
include:
5+
- language: cpp
6+
name: "FFmpeg 2"
7+
before_script:
8+
- sudo add-apt-repository ppa:openshot.developers/libopenshot-daily -y
9+
- sudo add-apt-repository ppa:beineri/opt-qt58-trusty -y
10+
- sudo apt-get update -qq
11+
- sudo apt-get install gcc-4.8 cmake libavcodec-dev libavformat-dev libswscale-dev libavresample-dev libavutil-dev libopenshot-audio-dev libopenshot-dev libfdk-aac-dev libfdk-aac-dev libjsoncpp-dev libmagick++-dev libopenshot-audio-dev libunittest++-dev libzmq3-dev pkg-config python3-dev qtbase5-dev qtmultimedia5-dev swig -y
12+
- sudo apt autoremove -y
13+
script:
14+
- mkdir -p build; cd build;
15+
- cmake -D"CMAKE_BUILD_TYPE:STRING=Debug" ../
16+
- make VERBOSE=1
17+
- make test
18+
19+
- language: cpp
20+
name: "FFmpeg 3"
21+
before_script:
22+
- sudo add-apt-repository ppa:openshot.developers/libopenshot-daily -y
23+
- sudo add-apt-repository ppa:beineri/opt-qt58-trusty -y
24+
- sudo add-apt-repository ppa:jonathonf/ffmpeg-3 -y
25+
- sudo apt-get update -qq
26+
- sudo apt-get install gcc-4.8 cmake libavcodec-dev libavformat-dev libswscale-dev libavresample-dev libavutil-dev libopenshot-audio-dev libopenshot-dev libfdk-aac-dev libfdk-aac-dev libjsoncpp-dev libmagick++-dev libopenshot-audio-dev libunittest++-dev libzmq3-dev pkg-config python3-dev qtbase5-dev qtmultimedia5-dev swig -y
27+
- sudo apt autoremove -y
28+
script:
29+
- mkdir -p build; cd build;
30+
- cmake -D"CMAKE_BUILD_TYPE:STRING=Debug" ../
31+
- make VERBOSE=1
32+
- make test
33+
34+
- language: cpp
35+
name: "FFmpeg 4"
36+
before_script:
37+
- sudo add-apt-repository ppa:openshot.developers/libopenshot-daily -y
38+
- sudo add-apt-repository ppa:beineri/opt-qt58-trusty -y
39+
- sudo add-apt-repository ppa:jonathonf/ffmpeg -y
40+
- sudo add-apt-repository ppa:jonathonf/ffmpeg-4 -y
41+
- sudo add-apt-repository ppa:jonathonf/backports -y
42+
- sudo apt-get update -qq
43+
- sudo apt-get install gcc-4.8 cmake libavcodec58 libavformat58 libavcodec-dev libavformat-dev libswscale-dev libavresample-dev libavutil-dev libopenshot-audio-dev libopenshot-dev libfdk-aac-dev libfdk-aac-dev libjsoncpp-dev libmagick++-dev libopenshot-audio-dev libunittest++-dev libzmq3-dev pkg-config python3-dev qtbase5-dev qtmultimedia5-dev swig -y
44+
- sudo apt autoremove -y
45+
script:
46+
- mkdir -p build; cd build;
47+
- cmake -D"CMAKE_BUILD_TYPE:STRING=Debug" ../
48+
- make VERBOSE=1
49+
- make test

cmake/Modules/FindFFmpeg.cmake

Lines changed: 158 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -1,151 +1,161 @@
1-
# - Try to find FFMPEG
1+
# vim: ts=2 sw=2
2+
# - Try to find the required ffmpeg components(default: AVFORMAT, AVUTIL, AVCODEC)
3+
#
24
# Once done this will define
3-
#
4-
# FFMPEG_FOUND - system has FFMPEG
5-
# FFMPEG_INCLUDE_DIR - the include directory
6-
# FFMPEG_LIBRARY_DIR - the directory containing the libraries
7-
# FFMPEG_LIBRARIES - Link these to use FFMPEG
8-
#
9-
10-
# FindAvformat
11-
FIND_PATH( AVFORMAT_INCLUDE_DIR libavformat/avformat.h
12-
PATHS /usr/include/
13-
/usr/include/ffmpeg/
14-
$ENV{FFMPEGDIR}/include/
15-
$ENV{FFMPEGDIR}/include/ffmpeg/ )
16-
17-
FIND_LIBRARY( AVFORMAT_LIBRARY avformat avformat-55 avformat-57
18-
PATHS /usr/lib/
19-
/usr/lib/ffmpeg/
20-
$ENV{FFMPEGDIR}/lib/
21-
$ENV{FFMPEGDIR}/lib/ffmpeg/
22-
$ENV{FFMPEGDIR}/bin/ )
23-
24-
#FindAvcodec
25-
FIND_PATH( AVCODEC_INCLUDE_DIR libavcodec/avcodec.h
26-
PATHS /usr/include/
27-
/usr/include/ffmpeg/
28-
$ENV{FFMPEGDIR}/include/
29-
$ENV{FFMPEGDIR}/include/ffmpeg/ )
30-
31-
FIND_LIBRARY( AVCODEC_LIBRARY avcodec avcodec-55 avcodec-57
32-
PATHS /usr/lib/
33-
/usr/lib/ffmpeg/
34-
$ENV{FFMPEGDIR}/lib/
35-
$ENV{FFMPEGDIR}/lib/ffmpeg/
36-
$ENV{FFMPEGDIR}/bin/ )
37-
38-
#FindAvutil
39-
FIND_PATH( AVUTIL_INCLUDE_DIR libavutil/avutil.h
40-
PATHS /usr/include/
41-
/usr/include/ffmpeg/
42-
$ENV{FFMPEGDIR}/include/
43-
$ENV{FFMPEGDIR}/include/ffmpeg/ )
44-
45-
FIND_LIBRARY( AVUTIL_LIBRARY avutil avutil-52 avutil-55
46-
PATHS /usr/lib/
47-
/usr/lib/ffmpeg/
48-
$ENV{FFMPEGDIR}/lib/
49-
$ENV{FFMPEGDIR}/lib/ffmpeg/
50-
$ENV{FFMPEGDIR}/bin/ )
51-
52-
#FindAvdevice
53-
FIND_PATH( AVDEVICE_INCLUDE_DIR libavdevice/avdevice.h
54-
PATHS /usr/include/
55-
/usr/include/ffmpeg/
56-
$ENV{FFMPEGDIR}/include/
57-
$ENV{FFMPEGDIR}/include/ffmpeg/ )
58-
59-
FIND_LIBRARY( AVDEVICE_LIBRARY avdevice avdevice-55 avdevice-56
60-
PATHS /usr/lib/
61-
/usr/lib/ffmpeg/
62-
$ENV{FFMPEGDIR}/lib/
63-
$ENV{FFMPEGDIR}/lib/ffmpeg/
64-
$ENV{FFMPEGDIR}/bin/ )
65-
66-
#FindSwscale
67-
FIND_PATH( SWSCALE_INCLUDE_DIR libswscale/swscale.h
68-
PATHS /usr/include/
69-
/usr/include/ffmpeg/
70-
$ENV{FFMPEGDIR}/include/
71-
$ENV{FFMPEGDIR}/include/ffmpeg/ )
72-
73-
FIND_LIBRARY( SWSCALE_LIBRARY swscale swscale-2 swscale-4
74-
PATHS /usr/lib/
75-
/usr/lib/ffmpeg/
76-
$ENV{FFMPEGDIR}/lib/
77-
$ENV{FFMPEGDIR}/lib/ffmpeg/
78-
$ENV{FFMPEGDIR}/bin/ )
79-
80-
#FindAvresample
81-
FIND_PATH( AVRESAMPLE_INCLUDE_DIR libavresample/avresample.h
82-
PATHS /usr/include/
83-
/usr/include/ffmpeg/
84-
$ENV{FFMPEGDIR}/include/
85-
$ENV{FFMPEGDIR}/include/ffmpeg/ )
86-
87-
FIND_LIBRARY( AVRESAMPLE_LIBRARY avresample avresample-2 avresample-3
88-
PATHS /usr/lib/
89-
/usr/lib/ffmpeg/
90-
$ENV{FFMPEGDIR}/lib/
91-
$ENV{FFMPEGDIR}/lib/ffmpeg/
92-
$ENV{FFMPEGDIR}/bin/ )
93-
94-
SET( FFMPEG_FOUND FALSE )
95-
96-
IF ( AVFORMAT_INCLUDE_DIR AND AVFORMAT_LIBRARY )
97-
SET ( AVFORMAT_FOUND TRUE )
98-
ENDIF ( AVFORMAT_INCLUDE_DIR AND AVFORMAT_LIBRARY )
99-
100-
IF ( AVCODEC_INCLUDE_DIR AND AVCODEC_LIBRARY )
101-
SET ( AVCODEC_FOUND TRUE)
102-
ENDIF ( AVCODEC_INCLUDE_DIR AND AVCODEC_LIBRARY )
103-
104-
IF ( AVUTIL_INCLUDE_DIR AND AVUTIL_LIBRARY )
105-
SET ( AVUTIL_FOUND TRUE )
106-
ENDIF ( AVUTIL_INCLUDE_DIR AND AVUTIL_LIBRARY )
107-
108-
IF ( AVDEVICE_INCLUDE_DIR AND AVDEVICE_LIBRARY )
109-
SET ( AVDEVICE_FOUND TRUE )
110-
ENDIF ( AVDEVICE_INCLUDE_DIR AND AVDEVICE_LIBRARY )
111-
112-
IF ( SWSCALE_INCLUDE_DIR AND SWSCALE_LIBRARY )
113-
SET ( SWSCALE_FOUND TRUE )
114-
ENDIF ( SWSCALE_INCLUDE_DIR AND SWSCALE_LIBRARY )
115-
116-
IF ( AVRESAMPLE_INCLUDE_DIR AND AVRESAMPLE_LIBRARY )
117-
SET ( AVRESAMPLE_FOUND TRUE )
118-
ENDIF ( AVRESAMPLE_INCLUDE_DIR AND AVRESAMPLE_LIBRARY )
119-
120-
IF ( AVFORMAT_INCLUDE_DIR OR AVCODEC_INCLUDE_DIR OR AVUTIL_INCLUDE_DIR OR AVDEVICE_FOUND OR SWSCALE_FOUND OR AVRESAMPLE_FOUND )
121-
122-
SET ( FFMPEG_FOUND TRUE )
123-
124-
SET ( FFMPEG_INCLUDE_DIR
125-
${AVFORMAT_INCLUDE_DIR}
126-
${AVCODEC_INCLUDE_DIR}
127-
${AVUTIL_INCLUDE_DIR}
128-
${AVDEVICE_INCLUDE_DIR}
129-
${SWSCALE_INCLUDE_DIR}
130-
${AVRESAMPLE_INCLUDE_DIR} )
131-
132-
SET ( FFMPEG_LIBRARIES
133-
${AVFORMAT_LIBRARY}
134-
${AVCODEC_LIBRARY}
135-
${AVUTIL_LIBRARY}
136-
${AVDEVICE_LIBRARY}
137-
${SWSCALE_LIBRARY}
138-
${AVRESAMPLE_LIBRARY} )
139-
140-
ENDIF ( AVFORMAT_INCLUDE_DIR OR AVCODEC_INCLUDE_DIR OR AVUTIL_INCLUDE_DIR OR AVDEVICE_FOUND OR SWSCALE_FOUND OR AVRESAMPLE_FOUND )
141-
142-
MARK_AS_ADVANCED(
143-
FFMPEG_LIBRARY_DIR
144-
FFMPEG_INCLUDE_DIR
145-
)
5+
# FFMPEG_FOUND - System has the all required components.
6+
# FFMPEG_INCLUDE_DIRS - Include directory necessary for using the required components headers.
7+
# FFMPEG_LIBRARIES - Link these to use the required ffmpeg components.
8+
# FFMPEG_DEFINITIONS - Compiler switches required for using the required ffmpeg components.
9+
#
10+
# For each of the components it will additionally set.
11+
# - AVCODEC
12+
# - AVDEVICE
13+
# - AVFORMAT
14+
# - AVFILTER
15+
# - AVUTIL
16+
# - POSTPROC
17+
# - SWSCALE
18+
# - SWRESAMPLE
19+
# - AVRESAMPLE
20+
# the following variables will be defined
21+
# <component>_FOUND - System has <component>
22+
# <component>_INCLUDE_DIRS - Include directory necessary for using the <component> headers
23+
# <component>_LIBRARIES - Link these to use <component>
24+
# <component>_DEFINITIONS - Compiler switches required for using <component>
25+
# <component>_VERSION - The components version
26+
#
27+
# Copyright (c) 2006, Matthias Kretz, <[email protected]>
28+
# Copyright (c) 2008, Alexander Neundorf, <[email protected]>
29+
# Copyright (c) 2011, Michael Jansen, <[email protected]>
30+
#
31+
# Redistribution and use is allowed according to the terms of the BSD license.
32+
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
14633

14734
include(FindPackageHandleStandardArgs)
148-
# handle the QUIETLY and REQUIRED arguments and set FFMPEG_FOUND to TRUE
149-
# if all listed variables are TRUE
150-
find_package_handle_standard_args(FFMPEG DEFAULT_MSG
151-
FFMPEG_LIBRARIES FFMPEG_INCLUDE_DIR)
35+
36+
# The default components were taken from a survey over other FindFFMPEG.cmake files
37+
if (NOT FFmpeg_FIND_COMPONENTS)
38+
set(FFmpeg_FIND_COMPONENTS AVCODEC AVFORMAT AVUTIL)
39+
endif ()
40+
41+
#
42+
### Macro: set_component_found
43+
#
44+
# Marks the given component as found if both *_LIBRARIES AND *_INCLUDE_DIRS is present.
45+
#
46+
macro(set_component_found _component )
47+
if (${_component}_LIBRARIES AND ${_component}_INCLUDE_DIRS)
48+
# message(STATUS " - ${_component} found.")
49+
set(${_component}_FOUND TRUE)
50+
else ()
51+
# message(STATUS " - ${_component} not found.")
52+
endif ()
53+
endmacro()
54+
55+
#
56+
### Macro: find_component
57+
#
58+
# Checks for the given component by invoking pkgconfig and then looking up the libraries and
59+
# include directories.
60+
#
61+
macro(find_component _component _pkgconfig _library _header)
62+
63+
if (NOT WIN32)
64+
# use pkg-config to get the directories and then use these values
65+
# in the FIND_PATH() and FIND_LIBRARY() calls
66+
find_package(PkgConfig)
67+
if (PKG_CONFIG_FOUND)
68+
pkg_check_modules(PC_${_component} ${_pkgconfig})
69+
endif ()
70+
endif (NOT WIN32)
71+
72+
find_path(${_component}_INCLUDE_DIRS ${_header}
73+
HINTS
74+
/opt/
75+
/opt/include/
76+
${PC_LIB${_component}_INCLUDEDIR}
77+
${PC_LIB${_component}_INCLUDE_DIRS}
78+
$ENV{FFMPEGDIR}/include/
79+
$ENV{FFMPEGDIR}/include/ffmpeg/
80+
PATH_SUFFIXES
81+
ffmpeg
82+
)
83+
84+
find_library(${_component}_LIBRARIES NAMES ${_library}
85+
HINTS
86+
${PC_LIB${_component}_LIBDIR}
87+
${PC_LIB${_component}_LIBRARY_DIRS}
88+
$ENV{FFMPEGDIR}/lib/
89+
$ENV{FFMPEGDIR}/lib/ffmpeg/
90+
$ENV{FFMPEGDIR}/bin/
91+
)
92+
93+
set(${_component}_DEFINITIONS ${PC_${_component}_CFLAGS_OTHER} CACHE STRING "The ${_component} CFLAGS.")
94+
set(${_component}_VERSION ${PC_${_component}_VERSION} CACHE STRING "The ${_component} version number.")
95+
96+
set_component_found(${_component})
97+
98+
mark_as_advanced(
99+
${_component}_INCLUDE_DIRS
100+
${_component}_LIBRARIES
101+
${_component}_DEFINITIONS
102+
${_component}_VERSION)
103+
104+
endmacro()
105+
106+
107+
# Check for cached results. If there are skip the costly part.
108+
if (NOT FFMPEG_LIBRARIES)
109+
110+
# Check for all possible component.
111+
find_component(AVCODEC libavcodec avcodec libavcodec/avcodec.h)
112+
find_component(AVFORMAT libavformat avformat libavformat/avformat.h)
113+
find_component(AVDEVICE libavdevice avdevice libavdevice/avdevice.h)
114+
find_component(AVUTIL libavutil avutil libavutil/avutil.h)
115+
find_component(AVFILTER libavfilter avfilter libavfilter/avfilter.h)
116+
find_component(SWSCALE libswscale swscale libswscale/swscale.h)
117+
find_component(POSTPROC libpostproc postproc libpostproc/postprocess.h)
118+
find_component(SWRESAMPLE libswresample swresample libswresample/swresample.h)
119+
find_component(AVRESAMPLE libavresample avresample libavresample/avresample.h)
120+
121+
# Check if the required components were found and add their stuff to the FFMPEG_* vars.
122+
foreach (_component ${FFmpeg_FIND_COMPONENTS})
123+
if (${_component}_FOUND)
124+
# message(STATUS "Required component ${_component} present.")
125+
set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} ${${_component}_LIBRARIES})
126+
set(FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} ${${_component}_DEFINITIONS})
127+
list(APPEND FFMPEG_INCLUDE_DIRS ${${_component}_INCLUDE_DIRS})
128+
else ()
129+
# message(STATUS "Required component ${_component} missing.")
130+
endif ()
131+
endforeach ()
132+
133+
# Build the include path with duplicates removed.
134+
if (FFMPEG_INCLUDE_DIRS)
135+
list(REMOVE_DUPLICATES FFMPEG_INCLUDE_DIRS)
136+
endif ()
137+
138+
# cache the vars.
139+
set(FFMPEG_INCLUDE_DIRS ${FFMPEG_INCLUDE_DIRS} CACHE STRING "The FFmpeg include directories." FORCE)
140+
set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} CACHE STRING "The FFmpeg libraries." FORCE)
141+
set(FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} CACHE STRING "The FFmpeg cflags." FORCE)
142+
143+
mark_as_advanced(FFMPEG_INCLUDE_DIRS
144+
FFMPEG_LIBRARIES
145+
FFMPEG_DEFINITIONS)
146+
147+
endif ()
148+
149+
# Now set the noncached _FOUND vars for the components.
150+
foreach (_component AVCODEC AVDEVICE AVFORMAT AVUTIL POSTPROCESS SWSCALE SWRESAMPLE AVRESAMPLE)
151+
set_component_found(${_component})
152+
endforeach ()
153+
154+
# Compile the list of required vars
155+
set(_FFmpeg_REQUIRED_VARS FFMPEG_LIBRARIES FFMPEG_INCLUDE_DIRS)
156+
foreach (_component ${FFmpeg_FIND_COMPONENTS})
157+
list(APPEND _FFmpeg_REQUIRED_VARS ${_component}_LIBRARIES ${_component}_INCLUDE_DIRS)
158+
endforeach ()
159+
160+
# Give a nice error message if some of the required vars are missing.
161+
find_package_handle_standard_args(FFmpeg DEFAULT_MSG ${_FFmpeg_REQUIRED_VARS})

include/CrashHandler.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,15 @@ namespace openshot {
5353
class CrashHandler {
5454
private:
5555
/// Default constructor
56-
CrashHandler(){}; // Don't allow user to create an instance of this singleton
56+
CrashHandler(){return;}; // Don't allow user to create an instance of this singleton
5757

5858
/// Default copy method
59-
CrashHandler(CrashHandler const&){}; // Don't allow the user to copy this instance
59+
//CrashHandler(CrashHandler const&){}; // Don't allow the user to copy this instance
60+
CrashHandler(CrashHandler const&) = delete; // Don't allow the user to copy this instance
6061

6162
/// Default assignment operator
62-
CrashHandler & operator=(CrashHandler const&){}; // Don't allow the user to assign this instance
63+
//CrashHandler & operator=(CrashHandler const&){}; // Don't allow the user to assign this instance
64+
CrashHandler & operator=(CrashHandler const&) = delete; // Don't allow the user to assign this instance
6365

6466
/// Private variable to keep track of singleton instance
6567
static CrashHandler *m_pInstance;

include/FFmpegReader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ namespace openshot
105105
bool check_interlace;
106106
bool check_fps;
107107
bool has_missing_frames;
108+
bool use_omp_threads;
108109

109110
CacheMemory working_cache;
110111
CacheMemory missing_frames;

0 commit comments

Comments
 (0)