Skip to content

Commit 68d6d63

Browse files
authored
Merge branch 'develop' into debian-pybuild
2 parents 7930b28 + 4837655 commit 68d6d63

22 files changed

+1615
-805
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ are also available in the /docs/ source folder.
3434
* [Mac](https://github.com/OpenShot/libopenshot/wiki/Mac-Build-Instructions)
3535
* [Windows](https://github.com/OpenShot/libopenshot/wiki/Windows-Build-Instructions)
3636

37+
## Hardware Acceleration
38+
39+
OpenShot now supports experimental hardware acceleration, both for encoding and
40+
decoding videos. When enabled, this can either speed up those operations or slow
41+
them down, depending on the power and features supported by your graphics card.
42+
Please see [doc/HW-ACCELL.md](doc/HW-ACCEL.md) for more information.
43+
3744
## Documentation
3845

3946
Beautiful HTML documentation can be generated using Doxygen.

cmake/Modules/FindFFmpeg.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,4 @@ foreach (_component ${FFmpeg_FIND_COMPONENTS})
158158
endforeach ()
159159

160160
# 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})
161+
find_package_handle_standard_args(FFmpeg DEFAULT_MSG ${_FFmpeg_REQUIRED_VARS})

doc/HW-ACCEL.md

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
## Hardware Acceleration
2+
3+
OpenShot now has experimental support for hardware acceleration, which uses 1 (or more)
4+
graphics cards to offload some of the work for both decoding and encoding. This is
5+
very new and experimental (as of May 2019), but we look forward to "accelerating"
6+
our support for this in the future!
7+
8+
The following table summarizes our current level of support:
9+
10+
| | Linux Decode | Linux Encode | Mac Decode | Mac Encode |Windows Decode| Windows Encode | Notes |
11+
|--------------------|------------------------|----------------------|------------------|----------------|--------------|------------------|------------------|
12+
| VA-API | :heavy_check_mark: | :heavy_check_mark: | - | - | - | - | *Linux Only* |
13+
| VDPAU | :heavy_check_mark:(+) |:white_check_mark:(++)| - | - | - | - | *Linux Only* |
14+
| CUDA (NVDEC/NVENC) | :x:(+++) | :heavy_check_mark: | - | - | - |:heavy_check_mark:| *Cross Platform* |
15+
| VideoToolBox | - | - |:heavy_check_mark:| :x:(++++) | - | - | *Mac Only* |
16+
| DXVA2 | - | - | - | - | :x:(+++) | - | *Windows Only* |
17+
| D3D11VA | - | - | - | - | :x:(+++) | - | *Windows Only* |
18+
| QSV | :x:(+++) | :x: | :x: | :x: | :x: | :x: | *Cross Platform* |
19+
20+
* *(+) VDPAU for some reason needs a card number one higher than it really is*
21+
* *(++) VDPAU is a decoder only.*
22+
* *(+++) Green frames (pixel data not correctly tranferred back to system memory)*
23+
* *(++++) Crashes and burns*
24+
25+
## Supported FFmpeg Versions
26+
27+
* HW accel is supported from FFmpeg version 3.2 (3.3 for nVidia drivers)
28+
* HW accel was removed for nVidia drivers in Ubuntu for FFmpeg 4+
29+
30+
**Notice:** The FFmpeg versions of Ubuntu and PPAs for Ubuntu show the
31+
same behaviour. FFmpeg 3 has working nVidia hardware acceleration while
32+
FFmpeg 4+ has no support for nVidia hardware acceleration
33+
included.
34+
35+
## OpenShot Settings
36+
37+
The following settings are use by libopenshot to enable, disable, and control
38+
the various hardware acceleration features.
39+
40+
```
41+
/// Use video codec for faster video decoding (if supported)
42+
int HARDWARE_DECODER = 0;
43+
44+
/* 0 - No acceleration
45+
1 - Linux VA-API
46+
2 - nVidia NVDEC
47+
3 - Windows D3D9
48+
4 - Windows D3D11
49+
5 - MacOS / VideoToolBox
50+
6 - Linux VDPAU
51+
7 - Intel QSV */
52+
53+
/// Number of threads of OpenMP
54+
int OMP_THREADS = 12;
55+
56+
/// Number of threads that FFmpeg uses
57+
int FF_THREADS = 8;
58+
59+
/// Maximum rows that hardware decode can handle
60+
int DE_LIMIT_HEIGHT_MAX = 1100;
61+
62+
/// Maximum columns that hardware decode can handle
63+
int DE_LIMIT_WIDTH_MAX = 1950;
64+
65+
/// Which GPU to use to decode (0 is the first, LINUX ONLY)
66+
int HW_DE_DEVICE_SET = 0;
67+
68+
/// Which GPU to use to encode (0 is the first, LINUX ONLY)
69+
int HW_EN_DEVICE_SET = 0;
70+
```
71+
72+
## Libva / VA-API (Video Acceleration API)
73+
74+
The correct version of libva is needed (libva in Ubuntu 16.04 or libva2
75+
in Ubuntu 18.04) for the AppImage to work with hardware acceleration.
76+
An AppImage that works on both systems (supporting libva and libva2),
77+
might be possible when no libva is included in the AppImage.
78+
79+
* vaapi is working for intel and AMD
80+
* vaapi is working for decode only for nouveau
81+
* nVidia driver is working for export only
82+
83+
## AMD Graphics Cards (RadeonOpenCompute/ROCm)
84+
85+
Decoding and encoding on the (AMD) GPU is possible with the default drivers.
86+
On systems where ROCm is installed and run a future use for GPU acceleration
87+
of effects could be implemented (contributions welcome).
88+
89+
## Multiple Graphics Cards
90+
91+
If the computer has multiple graphics cards installed, you can choose which
92+
should be used by libopenshot. Also, you can optionally use one card for
93+
decoding and the other for encoding (if both cards support acceleration).
94+
This is currently only supported on Linux, due to the device name FFmpeg
95+
expects (i.e. **/dev/dri/render128**). Contributions welcome if anyone can
96+
determine what string format to pass for Windows and Mac.
97+
98+
## Help Us Improve Hardware Support
99+
100+
This information might be wrong, and we would love to continue improving
101+
our support for hardware acceleration in OpenShot. Please help us update
102+
this document if you find an error or discover new and/or useful information.
103+
104+
**FFmpeg 4 + nVidia** The manual at:
105+
https://www.tal.org/tutorials/ffmpeg_nvidia_encode
106+
works pretty well. We could compile and install a version of FFmpeg 4.1.3
107+
on Mint 19.1 that supports the GPU on nVidia cards. A version of openshot
108+
with hardware support using these libraries could use the nVidia GPU.
109+
110+
**BUG:** Hardware supported decoding still has some bugs (as you can see from
111+
the chart above). Also, the speed gains with decoding are not as great
112+
as with encoding. Currently, if hardware decoding fails, there is no
113+
fallback (you either get green frames or an "invalid file" error in OpenShot).
114+
This needs to be improved to successfully fall-back to software decoding.
115+
116+
**Needed:**
117+
* A way to get options and limits of the GPU, such as
118+
supported dimensions (width and height).
119+
* A way to list the actual Graphic Cards available to FFmpeg (for the
120+
user to choose which card for decoding and encoding, as opposed
121+
to "Graphics Card X")
122+
123+
**Further improvement:** Right now the frame can be decoded on the GPU, but the
124+
frame is then copied to CPU memory for modifications. It is then copied back to
125+
GPU memory for encoding. Using the GPU for both decoding and modifications
126+
will make it possible to do away with these two copies. A possible solution would
127+
be to use Vulkan compute which would be available on Linux and Windows natively
128+
and on MacOS via MoltenVK.
129+
130+
## Credit
131+
132+
A big thanks to Peter M (https://github.com/eisneinechse) for all his work
133+
on integrating hardware acceleration into libopenshot! The community thanks
134+
you for this major contribution!

include/AudioDeviceInfo.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* @file
3+
* @brief Header file for Audio Device Info struct
4+
* @author Jonathan Thomas <[email protected]>
5+
*
6+
* @section LICENSE
7+
*
8+
* Copyright (c) 2008-2014 OpenShot Studios, LLC
9+
* <http://www.openshotstudios.com/>. This file is part of
10+
* OpenShot Library (libopenshot), an open-source project dedicated to
11+
* delivering high quality video editing and animation solutions to the
12+
* world. For more information visit <http://www.openshot.org/>.
13+
*
14+
* OpenShot Library (libopenshot) is free software: you can redistribute it
15+
* and/or modify it under the terms of the GNU Lesser General Public License
16+
* as published by the Free Software Foundation, either version 3 of the
17+
* License, or (at your option) any later version.
18+
*
19+
* OpenShot Library (libopenshot) is distributed in the hope that it will be
20+
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
* GNU Lesser General Public License for more details.
23+
*
24+
* You should have received a copy of the GNU Lesser General Public License
25+
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
26+
*/
27+
28+
#ifndef OPENSHOT_AUDIODEVICEINFO_H
29+
#define OPENSHOT_AUDIODEVICEINFO_H
30+
31+
32+
/**
33+
* @brief This struct hold information about Audio Devices
34+
*
35+
* The type and name of the audio device.
36+
*/
37+
struct AudioDeviceInfo
38+
{
39+
string name;
40+
string type;
41+
};
42+
43+
#endif

include/FFmpegReader.h

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,17 @@
5050

5151
using namespace std;
5252

53-
namespace openshot
54-
{
53+
namespace openshot {
5554
/**
5655
* @brief This struct holds the associated video frame and starting sample # for an audio packet.
5756
*
5857
* Because audio packets do not match up with video frames, this helps determine exactly
5958
* where the audio packet's samples belong.
6059
*/
61-
struct AudioLocation
62-
{
60+
struct AudioLocation {
6361
int64_t frame;
6462
int sample_start;
63+
6564
bool is_near(AudioLocation location, int samples_per_frame, int64_t amount);
6665
};
6766

@@ -91,14 +90,16 @@ namespace openshot
9190
* r.Close();
9291
* @endcode
9392
*/
94-
class FFmpegReader : public ReaderBase
95-
{
93+
class FFmpegReader : public ReaderBase {
9694
private:
9795
string path;
9896

9997
AVFormatContext *pFormatCtx;
10098
int i, videoStream, audioStream;
10199
AVCodecContext *pCodecCtx, *aCodecCtx;
100+
#if (LIBAVFORMAT_VERSION_MAJOR >= 57)
101+
AVBufferRef *hw_device_ctx = NULL; //PM
102+
#endif
102103
AVStream *pStream, *aStream;
103104
AVPacket *packet;
104105
AVFrame *pFrame;
@@ -142,7 +143,15 @@ namespace openshot
142143
int64_t video_pts_offset;
143144
int64_t last_frame;
144145
int64_t largest_frame_processed;
145-
int64_t current_video_frame; // can't reliably use PTS of video to determine this
146+
int64_t current_video_frame; // can't reliably use PTS of video to determine this
147+
148+
int hw_de_supported = 0; // Is set by FFmpegReader
149+
#if IS_FFMPEG_3_2
150+
AVPixelFormat hw_de_av_pix_fmt = AV_PIX_FMT_NONE;
151+
AVHWDeviceType hw_de_av_device_type = AV_HWDEVICE_TYPE_NONE;
152+
#endif
153+
154+
int IsHardwareDecodeSupported(int codecid);
146155

147156
/// Check for the correct frames per second value by scanning the 1st few seconds of video packets.
148157
void CheckFPS();
@@ -199,10 +208,10 @@ namespace openshot
199208
std::shared_ptr<Frame> ReadStream(int64_t requested_frame);
200209

201210
/// Remove AVFrame from cache (and deallocate it's memory)
202-
void RemoveAVFrame(AVFrame*);
211+
void RemoveAVFrame(AVFrame *);
203212

204213
/// Remove AVPacket from cache (and deallocate it's memory)
205-
void RemoveAVPacket(AVPacket*);
214+
void RemoveAVPacket(AVPacket *);
206215

207216
/// Seek to a specific Frame. This is not always frame accurate, it's more of an estimation on many codecs.
208217
void Seek(int64_t requested_frame);
@@ -240,7 +249,7 @@ namespace openshot
240249
void Close();
241250

242251
/// Get the cache object used by this reader
243-
CacheMemory* GetCache() { return &final_cache; };
252+
CacheMemory *GetCache() { return &final_cache; };
244253

245254
/// Get a shared pointer to a openshot::Frame object for a specific frame number of this reader.
246255
///

include/FFmpegUtilities.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
extern "C" {
4343
#include <libavcodec/avcodec.h>
4444
#include <libavformat/avformat.h>
45+
#if (LIBAVFORMAT_VERSION_MAJOR >= 57)
46+
#include <libavutil/hwcontext.h> //PM
47+
#endif
4548
#include <libswscale/swscale.h>
4649
// Change this to the first version swrescale works
4750
#if (LIBAVFORMAT_VERSION_MAJOR >= 57)

0 commit comments

Comments
 (0)