Skip to content

Commit 7b6eb9c

Browse files
authored
Integration of resvg SVG library (optional during build) (#185)
* Integration of libresvg SVG library (optional during build) * Major refactor of max_width and max_height for preview optimization * Fixed many bugs related to preview resizing, with regards to cached frames * Updating gitlab CI to find RESVGDIR correctly for windows, and adding svgz support * Updating cmake findresvg module to search for windows locations first, to prevent an issue on our windows builders and updating some CMake output. * Removing folder path from resvg header, since it could be installed in different named folders. This is an attempt to fix Windows include issues. * Making call to AV_FREE_FRAME conditional for non windows systems (because it crashes on Windows for seemingly no reason). Needs more investigation.
1 parent 64a5328 commit 7b6eb9c

21 files changed

+329
-171
lines changed

.gitlab-ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ windows-builder-x86:
6666
- Expand-Archive -Path artifacts.zip -DestinationPath .
6767
- $env:LIBOPENSHOT_AUDIO_DIR = "$CI_PROJECT_DIR\build\install-x86"
6868
- $env:UNITTEST_DIR = "C:\msys32\usr"
69+
- $env:RESVGDIR = "C:\msys32\usr\local"
6970
- $env:ZMQDIR = "C:\msys32\usr"
7071
- $env:Path = "C:\msys32\mingw32\bin;C:\msys32\mingw32\lib;C:\msys32\usr\lib\cmake\UnitTest++;C:\msys32\home\jonathan\depot_tools;C:\msys32\usr;C:\msys32\usr\lib;" + $env:Path;
7172
- New-Item -ItemType Directory -Force -Path build

cmake/Modules/FindRESVG.cmake

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# - Try to find RESVG
2+
# Once done this will define
3+
# RESVG_FOUND - System has RESVG
4+
# RESVG_INCLUDE_DIRS - The RESVG include directories
5+
# RESVG_LIBRARIES - The libraries needed to use RESVG
6+
# RESVG_DEFINITIONS - Compiler switches required for using RESVG
7+
find_path ( RESVG_INCLUDE_DIR ResvgQt.h
8+
PATHS ${RESVGDIR}/include/resvg
9+
$ENV{RESVGDIR}/include/resvg
10+
$ENV{RESVGDIR}/include
11+
/usr/include/resvg
12+
/usr/include
13+
/usr/local/include/resvg
14+
/usr/local/include )
15+
16+
find_library ( RESVG_LIBRARY NAMES resvg
17+
PATHS /usr/lib
18+
/usr/local/lib
19+
$ENV{RESVGDIR}/lib )
20+
21+
set ( RESVG_LIBRARIES ${RESVG_LIBRARY} )
22+
set ( RESVG_INCLUDE_DIRS ${RESVG_INCLUDE_DIR} )
23+
24+
SET( RESVG_FOUND FALSE )
25+
26+
IF ( RESVG_INCLUDE_DIR AND RESVG_LIBRARY )
27+
SET ( RESVG_FOUND TRUE )
28+
29+
include ( FindPackageHandleStandardArgs )
30+
# handle the QUIETLY and REQUIRED arguments and set RESVG_FOUND to TRUE
31+
# if all listed variables are TRUE
32+
find_package_handle_standard_args ( RESVG DEFAULT_MSG RESVG_LIBRARY RESVG_INCLUDE_DIR )
33+
ENDIF ( RESVG_INCLUDE_DIR AND RESVG_LIBRARY )
34+

include/ChunkReader.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
#define OPENSHOT_CHUNK_READER_H
3030

3131
#include "ReaderBase.h"
32-
#include "FFmpegReader.h"
33-
3432
#include <cmath>
3533
#include <ctime>
3634
#include <iostream>
@@ -107,7 +105,7 @@ namespace openshot
107105
string path;
108106
bool is_open;
109107
int64_t chunk_size;
110-
FFmpegReader *local_reader;
108+
ReaderBase *local_reader;
111109
ChunkLocation previous_location;
112110
ChunkVersion version;
113111
std::shared_ptr<Frame> last_frame;

include/Clip.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,9 @@
4444
#include "EffectBase.h"
4545
#include "Effects.h"
4646
#include "EffectInfo.h"
47-
#include "FFmpegReader.h"
4847
#include "Fraction.h"
49-
#include "FrameMapper.h"
50-
#ifdef USE_IMAGEMAGICK
51-
#include "ImageReader.h"
52-
#include "TextReader.h"
53-
#endif
54-
#include "QtImageReader.h"
55-
#include "ChunkReader.h"
5648
#include "KeyFrame.h"
5749
#include "ReaderBase.h"
58-
#include "DummyReader.h"
5950

6051
using namespace std;
6152
using namespace openshot;

include/ClipBase.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ namespace openshot {
5858
float start; ///< The position in seconds to start playing (used to trim the beginning of a clip)
5959
float end; ///< The position in seconds to end playing (used to trim the ending of a clip)
6060
string previous_properties; ///< This string contains the previous JSON properties
61-
int max_width; ///< The maximum image width needed by this clip (used for optimizations)
62-
int max_height; ///< The maximium image height needed by this clip (used for optimizations)
6361

6462
/// Generate JSON for a property
6563
Json::Value add_property_json(string name, float value, string type, string memo, Keyframe* keyframe, float min_value, float max_value, bool readonly, int64_t requested_frame);
@@ -70,7 +68,7 @@ namespace openshot {
7068
public:
7169

7270
/// Constructor for the base clip
73-
ClipBase() { max_width = 0; max_height = 0; };
71+
ClipBase() { };
7472

7573
// Compare a clip using the Position() property
7674
bool operator< ( ClipBase& a) { return (Position() < a.Position()); }
@@ -93,9 +91,6 @@ namespace openshot {
9391
void Start(float value) { start = value; } ///< Set start position (in seconds) of clip (trim start of video)
9492
void End(float value) { end = value; } ///< Set end position (in seconds) of clip (trim end of video)
9593

96-
/// Set Max Image Size (used for performance optimization)
97-
void SetMaxSize(int width, int height) { max_width = width; max_height = height; };
98-
9994
/// Get and Set JSON methods
10095
virtual string Json() = 0; ///< Generate JSON string of this object
10196
virtual void SetJson(string value) = 0; ///< Load JSON string into this object

include/FFmpegReader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include <stdio.h>
4343
#include <memory>
4444
#include "CacheMemory.h"
45+
#include "Clip.h"
4546
#include "Exceptions.h"
4647
#include "OpenMPUtilities.h"
4748
#include "Settings.h"

include/FFmpegUtilities.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@
141141
#define AV_ALLOCATE_FRAME() av_frame_alloc()
142142
#define AV_ALLOCATE_IMAGE(av_frame, pix_fmt, width, height) av_image_alloc(av_frame->data, av_frame->linesize, width, height, pix_fmt, 1)
143143
#define AV_RESET_FRAME(av_frame) av_frame_unref(av_frame)
144-
#define AV_FREE_FRAME(av_frame) if (av_frame) av_frame_free(av_frame)
144+
#define AV_FREE_FRAME(av_frame) av_frame_free(av_frame)
145145
#define AV_FREE_PACKET(av_packet) av_packet_unref(av_packet)
146146
#define AV_FREE_CONTEXT(av_context) avcodec_free_context(&av_context)
147147
#define AV_GET_CODEC_TYPE(av_stream) av_stream->codecpar->codec_type
@@ -176,7 +176,7 @@
176176
#define AV_ALLOCATE_FRAME() av_frame_alloc()
177177
#define AV_ALLOCATE_IMAGE(av_frame, pix_fmt, width, height) av_image_alloc(av_frame->data, av_frame->linesize, width, height, pix_fmt, 1)
178178
#define AV_RESET_FRAME(av_frame) av_frame_unref(av_frame)
179-
#define AV_FREE_FRAME(av_frame) if(av_frame) av_frame_free(av_frame)
179+
#define AV_FREE_FRAME(av_frame) av_frame_free(av_frame)
180180
#define AV_FREE_PACKET(av_packet) av_packet_unref(av_packet)
181181
#define AV_FREE_CONTEXT(av_context) avcodec_free_context(&av_context)
182182
#define AV_GET_CODEC_TYPE(av_stream) av_stream->codecpar->codec_type
@@ -211,7 +211,7 @@
211211
#define AV_ALLOCATE_FRAME() av_frame_alloc()
212212
#define AV_ALLOCATE_IMAGE(av_frame, pix_fmt, width, height) avpicture_alloc((AVPicture *) av_frame, pix_fmt, width, height)
213213
#define AV_RESET_FRAME(av_frame) av_frame_unref(av_frame)
214-
#define AV_FREE_FRAME(av_frame) if (av_frame) av_frame_free(av_frame)
214+
#define AV_FREE_FRAME(av_frame) av_frame_free(av_frame)
215215
#define AV_FREE_PACKET(av_packet) av_packet_unref(av_packet)
216216
#define AV_FREE_CONTEXT(av_context) avcodec_close(av_context)
217217
#define AV_GET_CODEC_TYPE(av_stream) av_stream->codec->codec_type
@@ -241,7 +241,7 @@
241241
#define AV_ALLOCATE_FRAME() avcodec_alloc_frame()
242242
#define AV_ALLOCATE_IMAGE(av_frame, pix_fmt, width, height) avpicture_alloc((AVPicture *) av_frame, pix_fmt, width, height)
243243
#define AV_RESET_FRAME(av_frame) avcodec_get_frame_defaults(av_frame)
244-
#define AV_FREE_FRAME(av_frame) if(av_frame) avcodec_free_frame(av_frame)
244+
#define AV_FREE_FRAME(av_frame) avcodec_free_frame(av_frame)
245245
#define AV_FREE_PACKET(av_packet) av_free_packet(av_packet)
246246
#define AV_FREE_CONTEXT(av_context) avcodec_close(av_context)
247247
#define AV_GET_CODEC_TYPE(av_stream) av_stream->codec->codec_type

include/QtImageReader.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,14 @@
2828
#ifndef OPENSHOT_QIMAGE_READER_H
2929
#define OPENSHOT_QIMAGE_READER_H
3030

31-
#include "ReaderBase.h"
32-
3331
#include <cmath>
3432
#include <ctime>
3533
#include <iostream>
3634
#include <omp.h>
3735
#include <stdio.h>
3836
#include <memory>
39-
#include <QtCore/QString>
40-
#include <QtGui/QImage>
41-
#include <QtGui/QPainter>
42-
#include "CacheMemory.h"
4337
#include "Exceptions.h"
38+
#include "ReaderBase.h"
4439

4540
using namespace std;
4641

@@ -110,9 +105,6 @@ namespace openshot
110105
Json::Value JsonValue(); ///< Generate Json::JsonValue for this object
111106
void SetJsonValue(Json::Value root); ///< Load Json::JsonValue into this object
112107

113-
/// Set Max Image Size (used for performance optimization)
114-
void SetMaxSize(int width, int height);
115-
116108
/// Open File - which is called by the constructor automatically
117109
void Open();
118110
};

include/ReaderBase.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <sstream>
3636
#include "CacheMemory.h"
3737
#include "ChannelLayouts.h"
38+
#include "ClipBase.h"
3839
#include "Fraction.h"
3940
#include "Frame.h"
4041
#include "Json.h"
@@ -99,9 +100,7 @@ namespace openshot
99100
/// Section lock for multiple threads
100101
CriticalSection getFrameCriticalSection;
101102
CriticalSection processingCriticalSection;
102-
103-
int max_width; ///< The maximum image width needed by this clip (used for optimizations)
104-
int max_height; ///< The maximium image height needed by this clip (used for optimizations)
103+
ClipBase* parent;
105104

106105
public:
107106

@@ -111,6 +110,12 @@ namespace openshot
111110
/// Information about the current media file
112111
ReaderInfo info;
113112

113+
/// Parent clip object of this reader (which can be unparented and NULL)
114+
ClipBase* GetClip();
115+
116+
/// Set parent clip object of this reader
117+
void SetClip(ClipBase* clip);
118+
114119
/// Close the reader (and any resources it was consuming)
115120
virtual void Close() = 0;
116121

@@ -140,9 +145,6 @@ namespace openshot
140145
virtual Json::Value JsonValue() = 0; ///< Generate Json::JsonValue for this object
141146
virtual void SetJsonValue(Json::Value root) = 0; ///< Load Json::JsonValue into this object
142147

143-
/// Set Max Image Size (used for performance optimization)
144-
void SetMaxSize(int width, int height) { max_width = width; max_height = height; };
145-
146148
/// Open the reader (and start consuming resources, such as images or video files)
147149
virtual void Open() = 0;
148150
};

include/Settings.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ namespace openshot {
8585
/// Scale mode used in FFmpeg decoding and encoding (used as an optimization for faster previews)
8686
bool HIGH_QUALITY_SCALING = false;
8787

88+
/// Maximum width for image data (useful for optimzing for a smaller preview or render)
89+
int MAX_WIDTH = 0;
90+
91+
/// Maximum height for image data (useful for optimzing for a smaller preview or render)
92+
int MAX_HEIGHT = 0;
93+
8894
/// Wait for OpenMP task to finish before continuing (used to limit threads on slower systems)
8995
bool WAIT_FOR_VIDEO_PROCESSING_TASK = false;
9096

0 commit comments

Comments
 (0)