Skip to content

Commit fe8ea21

Browse files
authored
Merge pull request #437 from ferdnyc/hw-accel-ffmpeg34
Limit HW accel support to FFmpeg 3.4+
2 parents 99fda01 + 4106b99 commit fe8ea21

File tree

6 files changed

+99
-60
lines changed

6 files changed

+99
-60
lines changed

.travis.yml

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ matrix:
3737

3838
- name: "Coverage (Ubuntu 18.04 Bionic)"
3939
env:
40-
- BUILD_VERSION=coverage_ffmpeg3
40+
- BUILD_VERSION=coverage_ffmpeg34
4141
- CMAKE_EXTRA_ARGS="-DENABLE_COVERAGE=1"
4242
- TEST_TARGET=coverage
4343
os: linux
@@ -80,9 +80,9 @@ matrix:
8080
- libavresample4
8181
- libswresample3
8282

83-
- name: "FFmpeg 3 GCC (Ubuntu 18.04 Bionic)"
83+
- name: "FFmpeg 3.4 GCC (Ubuntu 18.04 Bionic)"
8484
env:
85-
- BUILD_VERSION=ffmpeg3
85+
- BUILD_VERSION=ffmpeg34
8686
- CMAKE_EXTRA_ARGS=""
8787
- TEST_TARGET=test
8888
os: linux
@@ -97,9 +97,9 @@ matrix:
9797
- qt5-default
9898
- libjsoncpp-dev
9999

100-
- name: "FFmpeg 3 Clang (Ubuntu 18.04 Bionic)"
100+
- name: "FFmpeg 3.4 Clang (Ubuntu 18.04 Bionic)"
101101
env:
102-
- BUILD_VERSION=clang_ffmpeg3
102+
- BUILD_VERSION=clang_ffmpeg34
103103
- CMAKE_EXTRA_ARGS=""
104104
- TEST_TARGET=test
105105
os: linux
@@ -115,6 +115,31 @@ matrix:
115115
- qt5-default
116116
- libomp-dev
117117

118+
- name: "FFmpeg 3.2 GCC (Ubuntu 16.04 Xenial)"
119+
env:
120+
- BUILD_VERSION=ffmpeg32
121+
- CMAKE_EXTRA_ARGS=""
122+
- TEST_TARGET="os_test"
123+
os: linux
124+
dist: xenial
125+
addons:
126+
apt:
127+
sources:
128+
- sourceline: 'ppa:openshot.developers/libopenshot-daily'
129+
- sourceline: 'ppa:beineri/opt-qt-5.10.0-xenial'
130+
- sourceline: 'ppa:jon-hedgerows/ffmpeg-backports'
131+
packages:
132+
- *ff_common
133+
- libavcodec57
134+
- libavdevice57
135+
- libavfilter6
136+
- libavformat57
137+
- libavresample3
138+
- libavutil55
139+
- libpostproc54
140+
- libswresample2
141+
- libswscale4
142+
118143
- name: "FFmpeg 2 GCC (Ubuntu 16.04 Xenial)"
119144
env:
120145
- BUILD_VERSION=ffmpeg2

doc/HW-ACCEL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The following table summarizes our current level of support:
2626

2727
## Supported FFmpeg Versions
2828

29-
* HW accel is supported from FFmpeg version 3.2 (3.3 for nVidia drivers)
29+
* HW accel is supported from FFmpeg version 3.4
3030
* HW accel was removed for nVidia drivers in Ubuntu for FFmpeg 4+
3131

3232
**Notice:** The FFmpeg versions of Ubuntu and PPAs for Ubuntu show the

include/FFmpegReader.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ namespace openshot {
9898
AVFormatContext *pFormatCtx;
9999
int i, videoStream, audioStream;
100100
AVCodecContext *pCodecCtx, *aCodecCtx;
101-
#if (LIBAVFORMAT_VERSION_MAJOR >= 57)
101+
#if HAVE_HW_ACCEL
102102
AVBufferRef *hw_device_ctx = NULL; //PM
103103
#endif
104104
AVStream *pStream, *aStream;
@@ -147,12 +147,11 @@ namespace openshot {
147147
int64_t current_video_frame; // can't reliably use PTS of video to determine this
148148

149149
int hw_de_supported = 0; // Is set by FFmpegReader
150-
#if IS_FFMPEG_3_2
150+
#if HAVE_HW_ACCEL
151151
AVPixelFormat hw_de_av_pix_fmt = AV_PIX_FMT_NONE;
152152
AVHWDeviceType hw_de_av_device_type = AV_HWDEVICE_TYPE_NONE;
153-
#endif
154-
155153
int IsHardwareDecodeSupported(int codecid);
154+
#endif
156155

157156
/// Check for the correct frames per second value by scanning the 1st few seconds of video packets.
158157
void CheckFPS();

include/FFmpegUtilities.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
#ifndef IS_FFMPEG_3_2
4141
#define IS_FFMPEG_3_2 (LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 64, 101))
4242
#endif
43+
44+
#ifndef HAVE_HW_ACCEL
45+
#define HAVE_HW_ACCEL (LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 107, 100))
46+
#endif
4347

4448
// Include the FFmpeg headers
4549
extern "C" {

src/FFmpegReader.cpp

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@
3535

3636
#define ENABLE_VAAPI 0
3737

38-
#if IS_FFMPEG_3_2
38+
#if HAVE_HW_ACCEL
3939
#pragma message "You are compiling with experimental hardware decode"
4040
#else
4141
#pragma message "You are compiling only with software decode"
4242
#endif
4343

44-
#if IS_FFMPEG_3_2
44+
#if HAVE_HW_ACCEL
4545
#define MAX_SUPPORTED_WIDTH 1950
4646
#define MAX_SUPPORTED_HEIGHT 1100
4747

@@ -71,14 +71,14 @@ typedef struct VAAPIDecodeContext {
7171
enum AVPixelFormat surface_format;
7272
int surface_count;
7373
} VAAPIDecodeContext;
74-
#endif
75-
#endif
74+
#endif // ENABLE_VAAPI
75+
#endif // HAVE_HW_ACCEL
7676

7777

7878
using namespace openshot;
7979

8080
int hw_de_on = 0;
81-
#if IS_FFMPEG_3_2
81+
#if HAVE_HW_ACCEL
8282
AVPixelFormat hw_de_av_pix_fmt_global = AV_PIX_FMT_NONE;
8383
AVHWDeviceType hw_de_av_device_type_global = AV_HWDEVICE_TYPE_NONE;
8484
#endif
@@ -153,7 +153,7 @@ bool AudioLocation::is_near(AudioLocation location, int samples_per_frame, int64
153153
return false;
154154
}
155155

156-
#if IS_FFMPEG_3_2
156+
#if HAVE_HW_ACCEL
157157

158158
// Get hardware pix format
159159
static enum AVPixelFormat get_hw_dec_format(AVCodecContext *ctx, const enum AVPixelFormat *pix_fmts)
@@ -234,7 +234,7 @@ int FFmpegReader::IsHardwareDecodeSupported(int codecid)
234234
}
235235
return ret;
236236
}
237-
#endif
237+
#endif // HAVE_HW_ACCEL
238238

239239
void FFmpegReader::Open() {
240240
// Open reader if not already open
@@ -287,7 +287,7 @@ void FFmpegReader::Open() {
287287
// If hw accel is selected but hardware cannot handle repeat with software decoding
288288
do {
289289
pCodecCtx = AV_GET_CODEC_CONTEXT(pStream, pCodec);
290-
#if IS_FFMPEG_3_2
290+
#if HAVE_HW_ACCEL
291291
if (hw_de_on && (retry_decode_open==2)) {
292292
// Up to here no decision is made if hardware or software decode
293293
hw_de_supported = IsHardwareDecodeSupported(pCodecCtx->codec_id);
@@ -304,7 +304,7 @@ void FFmpegReader::Open() {
304304

305305
// Init options
306306
av_dict_set(&opts, "strict", "experimental", 0);
307-
#if IS_FFMPEG_3_2
307+
#if HAVE_HW_ACCEL
308308
if (hw_de_on && hw_de_supported) {
309309
// Open Hardware Acceleration
310310
int i_decoder_hw = 0;
@@ -433,13 +433,13 @@ void FFmpegReader::Open() {
433433
throw InvalidCodec("Hardware device create failed.", path);
434434
}
435435
}
436-
#endif
436+
#endif // HAVE_HW_ACCEL
437437

438438
// Open video codec
439439
if (avcodec_open2(pCodecCtx, pCodec, &opts) < 0)
440440
throw InvalidCodec("A video codec was found, but could not be opened.", path);
441441

442-
#if IS_FFMPEG_3_2
442+
#if HAVE_HW_ACCEL
443443
if (hw_de_on && hw_de_supported) {
444444
AVHWFramesConstraints *constraints = NULL;
445445
void *hwconfig = NULL;
@@ -449,7 +449,7 @@ void FFmpegReader::Open() {
449449
#if ENABLE_VAAPI
450450
((AVVAAPIHWConfig *)hwconfig)->config_id = ((VAAPIDecodeContext *)(pCodecCtx->priv_data))->va_config;
451451
constraints = av_hwdevice_get_hwframe_constraints(hw_device_ctx,hwconfig);
452-
#endif
452+
#endif // ENABLE_VAAPI
453453
if (constraints) {
454454
if (pCodecCtx->coded_width < constraints->min_width ||
455455
pCodecCtx->coded_height < constraints->min_height ||
@@ -506,7 +506,7 @@ void FFmpegReader::Open() {
506506
}
507507
#else
508508
retry_decode_open = 0;
509-
#endif
509+
#endif // HAVE_HW_ACCEL
510510
} while (retry_decode_open); // retry_decode_open
511511
// Free options
512512
av_dict_free(&opts);
@@ -592,14 +592,14 @@ void FFmpegReader::Close() {
592592
if (info.has_video) {
593593
avcodec_flush_buffers(pCodecCtx);
594594
AV_FREE_CONTEXT(pCodecCtx);
595-
#if IS_FFMPEG_3_2
595+
#if HAVE_HW_ACCEL
596596
if (hw_de_on) {
597597
if (hw_device_ctx) {
598598
av_buffer_unref(&hw_device_ctx);
599599
hw_device_ctx = NULL;
600600
}
601601
}
602-
#endif
602+
#endif // HAVE_HW_ACCEL
603603
}
604604
if (info.has_audio) {
605605
avcodec_flush_buffers(aCodecCtx);
@@ -1100,19 +1100,22 @@ bool FFmpegReader::GetAVFrame() {
11001100

11011101
ret = avcodec_send_packet(pCodecCtx, packet);
11021102

1103+
#if HAVE_HW_ACCEL
11031104
// Get the format from the variables set in get_hw_dec_format
11041105
hw_de_av_pix_fmt = hw_de_av_pix_fmt_global;
11051106
hw_de_av_device_type = hw_de_av_device_type_global;
1106-
1107+
#endif // HAVE_HW_ACCEL
11071108
if (ret < 0 || ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
11081109
ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::GetAVFrame (Packet not sent)");
11091110
}
11101111
else {
11111112
AVFrame *next_frame2;
1113+
#if HAVE_HW_ACCEL
11121114
if (hw_de_on && hw_de_supported) {
11131115
next_frame2 = AV_ALLOCATE_FRAME();
11141116
}
11151117
else
1118+
#endif // HAVE_HW_ACCEL
11161119
{
11171120
next_frame2 = next_frame;
11181121
}
@@ -1125,6 +1128,7 @@ bool FFmpegReader::GetAVFrame() {
11251128
if (ret != 0) {
11261129
ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::GetAVFrame (invalid return frame received)");
11271130
}
1131+
#if HAVE_HW_ACCEL
11281132
if (hw_de_on && hw_de_supported) {
11291133
int err;
11301134
if (next_frame2->format == hw_de_av_pix_fmt) {
@@ -1138,6 +1142,7 @@ bool FFmpegReader::GetAVFrame() {
11381142
}
11391143
}
11401144
else
1145+
#endif // HAVE_HW_ACCEL
11411146
{ // No hardware acceleration used -> no copy from GPU memory needed
11421147
next_frame = next_frame2;
11431148
}
@@ -1151,9 +1156,11 @@ bool FFmpegReader::GetAVFrame() {
11511156
(AVPixelFormat)(pStream->codecpar->format), info.width, info.height);
11521157
}
11531158
}
1159+
#if HAVE_HW_ACCEL
11541160
if (hw_de_on && hw_de_supported) {
11551161
AV_FREE_FRAME(&next_frame2);
11561162
}
1163+
#endif // HAVE_HW_ACCEL
11571164
}
11581165
#else
11591166
avcodec_decode_video2(pCodecCtx, next_frame, &frameFinished, packet);
@@ -1169,7 +1176,7 @@ bool FFmpegReader::GetAVFrame() {
11691176
av_picture_copy((AVPicture *) pFrame, (AVPicture *) next_frame, pCodecCtx->pix_fmt, info.width,
11701177
info.height);
11711178
}
1172-
#endif
1179+
#endif // IS_FFMPEG_3_2
11731180
}
11741181

11751182
// deallocate the frame

0 commit comments

Comments
 (0)