Skip to content

Commit d1b7e9f

Browse files
authored
Merge pull request #10 from petermcneil/bug/dynamic-libraries
Bug/dynamic libraries
2 parents bcb94ab + 15f3a6f commit d1b7e9f

File tree

14 files changed

+115
-77
lines changed

14 files changed

+115
-77
lines changed

CMakeLists.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
cmake_minimum_required(VERSION 3.13)
22
project(lodge)
33

4+
set(Boost_USE_STATIC_LIBS ON)
45
set(CMAKE_CXX_STANDARD 17)
6+
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wshadow -Wnon-virtual-dtor -pedantic -g -fvisibility=hidden -fvisibility-inlines-hidden -mmacosx-version-min=10.12")
57

6-
FIND_PACKAGE(Boost 1.68 COMPONENTS filesystem program_options regex REQUIRED)
7-
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
8+
FIND_PACKAGE(Boost 1.69 COMPONENTS filesystem program_options regex REQUIRED)
89

910
enable_testing()
1011

1112
add_subdirectory(include)
1213
add_subdirectory(lib)
13-
add_subdirectory(app)
14-
add_subdirectory(gui)
14+
add_subdirectory(app)

Makefile

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: clean build run test
1+
.PHONY: clean build run test gui release
22

33
clean:
44
rm -rf build/
@@ -15,7 +15,7 @@ run: build
1515
build/app/lodge write -i -d "extras/samples/videos/Time Lapse Video Of Night Sky.mp4" -s "extras/samples/subtitles/proper_test.srt" -o "output/test.mp4"
1616

1717
read: run
18-
build/app/lodge read -i -d "output/test.mp4" -o "output/test.srt"
18+
build/app/lodge read -i -d "output/test.mp4"
1919

2020
test:
2121
@mkdir -p ./build
@@ -31,4 +31,7 @@ release:
3131
@make -C ./release
3232

3333
gui: build
34+
@mkdir -p build/gui
35+
@qmake -o build/gui
36+
make -C build/gui -j8
3437
open build/gui/Lodge.app

README.md

+31
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,37 @@ used by video editors or stenographers and will merge the subtitles into the vid
2020
(Lodge Viewer) will be used by the layperson while watching videos and will extract the subtitles from the video file
2121
and display them to the user. The two products together will provide a complete end-to-end workflow for subtitling.
2222

23+
24+
Compiled for MacOS 10.12.+
25+
26+
Dependencies
27+
--
28+
For using the Lodge binaries on a system FFmpeg must be installed. Use Homebrew for easiest installation.
29+
30+
To build Lodge for development purposes the following dependencies need to be installed
31+
32+
- Qt5
33+
- FFmpeg
34+
- Boost
35+
- Spdlog
36+
37+
The script `./configure` is provided for convenience of setting these up. It will use Homebrew to install these packages.
38+
39+
To build Lodge for releasing, Qt must be compiled statically. The script `qt.sh` in `scripts/` will download and compile it for you. Be warned
40+
this process takes a substantial amount of time. Currently it is set up to use 8 cores - 4 physical, 4 logical - this can be changed if needed
41+
by editing the script.
42+
43+
44+
Building
45+
---
46+
There are two build systems in use in this project. CMake for the library portions and Qmake for the GUI portion. A top-level make file has been provided for convenience.
47+
48+
- make build: builds all non-gui parts
49+
- make gui: builds everything and runs GUI
50+
- make tests: runs the tests
51+
- make read: runs a full write and read of a subtitle file
52+
- make run: runs a write of a subtitle file
53+
2354
Detecting Lodge in video frames
2455
---
2556
A header will be written to each frame that Lodge writes to, of the format:

app/CMakeLists.txt

-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wshadow -Wnon-virtual-dtor -pedantic -g")
2-
31
set(BINARY_NAME lodge)
42
file (GLOB APP_SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")
53

@@ -13,4 +11,3 @@ target_link_libraries(${BINARY_NAME} PUBLIC "libavutil.a")
1311
target_link_libraries(${BINARY_NAME} PUBLIC "libavcodec.a")
1412
target_link_libraries(${BINARY_NAME} PUBLIC "libavfilter.a")
1513
target_link_libraries(${BINARY_NAME} PUBLIC "swscale.a")
16-
target_link_libraries(${BINARY_NAME} PUBLIC "swscale.a")

app/src/lodge.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -87,26 +87,28 @@ int main(int ac, char *av[]) {
8787
string input = vm["input"].as<string>();;
8888
cout << "Reading from video file: " << input << endl;
8989
string output;
90+
subtitle *sub;
9091

9192
log::debug("Checking for output subtitle path");
9293
if (vm.count("output")) {
9394
log::debug("Found output subtitle path and setting it");
9495
output = vm["output"].as<string>();
96+
sub = new subtitle(output, RW::WRITE);
9597
} else {
9698
cout << "Output file is going to be generated from video file";
99+
sub = nullptr;
97100
}
98101

99102
log::debug("Building subtitle object");
100-
subtitle *sub = new subtitle(output, RW::WRITE);
101103
log::debug("Building video object");
102104
video *vid = new video(input, sub);
103105

104106
if (vid->has_steg_file()) {
105-
cout << "Writing to subtitle file: " << sub->get_path() << endl;
107+
cout << "Writing to subtitle file: " << vid->subtitle_file->get_path() << endl;
106108
log::debug("Starting to read from the video file");
107109
ret = vid->read_subtitle_file();
108110
if (ret == 0) {
109-
cout << "\x1B[32mSuccessfully saved the subtitle file: " << sub->get_path() << "\x1B[0m" << endl;
111+
cout << "\x1B[32mSuccessfully saved the subtitle file: " << vid->subtitle_file->get_path() << "\x1B[0m" << endl;
110112
return EXIT_SUCCESS;
111113
} else {
112114
cout << "\x1B[91mFailed to extract a subtitle file from: " << input << "\x1B[0m" << endl;

extras/samples/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ the project the right to download, edit, and re-distribute at will without attri
77

88
Despite the license, I still believe it is right and proper to give proper attribution.
99
The table below details the "owner" and gives a link to where you may download it yourselves.
10-
``
10+
1111
|Video |Attribution |Link |
1212
|-----------------------------|-------------|---------------------------------------------------------------------|
1313
|Time Lapse Video Of Night Sky|Vimeo |https://videos.pexels.com/videos/time-lapse-video-of-night-sky-857195|

gui/CMakeLists.txt

-39
This file was deleted.

gui/src/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <QGuiApplication>
22
#include <QQmlApplicationEngine>
33
#include <video.h>
4-
#include <src/backend.h>
4+
#include "backend.h"
55

66
int main(int argc, char *argv[]) {
77
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

lib/CMakeLists.txt

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
project(lodge_lib)
22

3-
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wshadow -Wnon-virtual-dtor -pedantic -g")
4-
53
set (LIBRARY_MODULE_PATH "${CMAKE_SOURCE_DIR}/lib")
64
set (LIBRARY_SRC_PATH "${CMAKE_CURRENT_SOURCE_DIR}/src" )
75
set (LIBRARY_INCLUDE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/include")
@@ -12,7 +10,7 @@ include_directories (${LIBRARY_INCLUDE_PATH})
1210
file (GLOB LIB_HEADER_FILES "${LIBRARY_INCLUDE_PATH}/*.h")
1311
file (GLOB LIB_SOURCE_FILES "${LIBRARY_SRC_PATH}/*.cpp")
1412

15-
add_library (${PROJECT_NAME} STATIC ${LIB_SOURCE_FILES} ${LIB_HEADER_FILES})
13+
add_library (${PROJECT_NAME} STATIC ${LIB_SOURCE_FILES} ${LIB_HEADER_FILES} ${Boost_INCLUDE_DIRS} ${Boost_LIBRARY_DIRS})
1614

1715
enable_testing()
1816
add_subdirectory (test)

lib/include/video.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace lodge {
3030

3131
class video {
3232
private:
33-
filesystem::path inputFilePath;
33+
filesystem::path input_file_path;
3434
filesystem::path outputFilePath;
3535
vector<frame_header> *headers = new vector<frame_header>;
3636

@@ -39,7 +39,7 @@ namespace lodge {
3939

4040
int write_x = 0;
4141
int write_y = 0;
42-
int block_size = 1;
42+
int block_size = 16;
4343
int no_of_frames = 0;
4444
int no_of_bits_in_char = 8;
4545

lib/src/subtitle.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ int subtitle::write_line(const vector<char> &lineCharacters) {
118118
line += character;
119119
}
120120
}
121-
log::trace("Adding this to file: {}", line);
121+
log::debug("Adding this to file: {}", line);
122122
*subtitle_file << line << std::endl;
123123
return 0;
124124
}

lib/src/video.cpp

+23-18
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ using namespace lodge;
99
namespace log = spdlog;
1010

1111
video::video(string inputVideo, string outputVideo, subtitle *subFile) {
12-
this->inputFilePath = canonical(filesystem::path(inputVideo));
12+
this->input_file_path = canonical(filesystem::path(inputVideo));
1313
this->outputFilePath = weakly_canonical(filesystem::path(outputVideo));
1414
this->subtitle_file = subFile;
1515
}
1616

1717
video::video(string inputVideo, subtitle *subFile) {
18-
this->inputFilePath = weakly_canonical(filesystem::path(inputVideo));
18+
this->input_file_path = weakly_canonical(filesystem::path(inputVideo));
1919
this->subtitle_file = subFile;
2020
}
2121

@@ -278,7 +278,7 @@ int video::open_input_file() {
278278
input_format_context = nullptr;
279279

280280
//Open input file
281-
retu = avformat_open_input(&input_format_context, this->inputFilePath.c_str(), nullptr, nullptr);
281+
retu = avformat_open_input(&input_format_context, this->input_file_path.c_str(), nullptr, nullptr);
282282
if (retu < 0) {
283283
log::error("Cannot open input file");
284284
return retu;
@@ -341,7 +341,7 @@ int video::open_input_file() {
341341
}
342342

343343
//Print out the important information regarding the input file
344-
av_dump_format(input_format_context, 0, this->inputFilePath.c_str(), 0);
344+
av_dump_format(input_format_context, 0, this->input_file_path.c_str(), 0);
345345
return 0;
346346
}
347347

@@ -881,6 +881,7 @@ int video::read_subtitle_file() {
881881
return -234;
882882
}
883883

884+
log::debug("Reading from the file properly and outputing here: {}", this->subtitle_file->get_path().c_str());
884885
this->init_read();
885886

886887
while (this->no_of_frames > 0 && av_read_frame(format, pkt) >= 0) {
@@ -972,17 +973,21 @@ bool video::has_steg_file() {
972973
frame_header *h = this->read_steg_header(picture);
973974
if (h != nullptr) {
974975
log::debug("Setting frame_header: {}", h->to_string());
975-
log::debug("Creating new subtitle");
976+
log::debug("Checking if subtitle file exists");
977+
if(this->subtitle_file == nullptr) {
978+
filesystem::path output_sub = this->input_file_path.parent_path();
979+
output_sub /= filesystem::path(h->filename);
980+
log::debug("New path for subtitle file: {}", output_sub.c_str());
981+
this->subtitle_file = new subtitle(output_sub, RW::WRITE);
982+
}
976983

977-
filesystem::path output_sub = this->subtitle_file->get_path().parent_path();
978-
output_sub /= filesystem::path(h->filename);
979-
this->subtitle_file = new subtitle(output_sub, RW::WRITE);
980984
this->no_of_frames = (int) h->total_frames;
985+
log::debug("Has header = true");
986+
has_header = true;
981987
} else {
982988
this->no_of_frames = 0;
989+
has_header = false;
983990
}
984-
log::debug("Has header = true");
985-
has_header = true;
986991
av_frame_unref(frame);
987992
goto end;
988993
}
@@ -1013,19 +1018,19 @@ int video::init_read() {
10131018

10141019
context = nullptr;
10151020
format = avformat_alloc_context();
1016-
log::debug("Opening input '{}' in libav", this->inputFilePath.generic_string());
1017-
ret = avformat_open_input(&format, this->inputFilePath.c_str(), nullptr, nullptr);
1021+
log::debug("Opening input '{}' in libav", this->input_file_path.generic_string());
1022+
ret = avformat_open_input(&format, this->input_file_path.c_str(), nullptr, nullptr);
10181023

10191024
if (ret != 0) {
1020-
log::error("Couldn't open video file: {}", inputFilePath.generic_string());
1025+
log::error("Couldn't open video file: {}", input_file_path.generic_string());
10211026
return -1;
10221027
}
10231028

10241029
log::debug("Finding stream information about the file");
10251030
ret = avformat_find_stream_info(format, nullptr);
10261031

10271032
if (ret < 0) {
1028-
log::error("Wasn't able to generate stream information for file: {} ", inputFilePath.generic_string());
1033+
log::error("Wasn't able to generate stream information for file: {} ", input_file_path.generic_string());
10291034
return -1;
10301035
}
10311036

@@ -1041,7 +1046,7 @@ int video::init_read() {
10411046
}
10421047

10431048
if (video_stream == -1337) {
1044-
log::error("This file doesn't contain a video stream: ", inputFilePath.generic_string());
1049+
log::error("This file doesn't contain a video stream: ", input_file_path.generic_string());
10451050
return -1;
10461051
}
10471052

@@ -1077,11 +1082,11 @@ int video::init_read() {
10771082
return -1;
10781083
}
10791084

1080-
log::debug("Open the input file: '{}'", inputFilePath.generic_string());
1081-
f = fopen(inputFilePath.c_str(), "rb");
1085+
log::debug("Open the input file: '{}'", input_file_path.generic_string());
1086+
f = fopen(input_file_path.c_str(), "rb");
10821087

10831088
if (!f) {
1084-
log::error("Could not open file: ", inputFilePath.generic_string());
1089+
log::error("Could not open file: ", input_file_path.generic_string());
10851090
return -1;
10861091
}
10871092

main.pro

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
QMAKE_CXXFLAGS = -fvisibility=hidden -fvisibility-inlines-hidden
2+
CONFIG += app_bundle
3+
ICON = gui/resources/icon.icns
4+
5+
TARGET = Lodge
6+
CONFIG += c++17
7+
CONFIG += qt debug
8+
9+
QT += core widgets quick
10+
11+
HEADERS = gui/src/backend.h
12+
SOURCES = gui/src/backend.cpp gui/src/main.cpp
13+
RESOURCES += gui/qml.qrc
14+
15+
INCLUDEPATH += lib/include
16+
INCLUDEPATH += /usr/local/Cellar/ffmpeg/4.1.3/include
17+
INCLUDEPATH += /usr/local/include/
18+
LIBS += "$$PWD/build/lib/liblodge_lib.a"
19+
LIBS += "/usr/local/Cellar/boost/1.69.0_2/lib/libboost_filesystem.a" "/usr/local/Cellar/boost/1.69.0_2/lib/libboost_regex.a"
20+
LIBS += "-L/usr/local/Cellar/ffmpeg/4.1.3/lib" -lavcodec -lavutil -lavformat -lswscale -lavfilter
21+
LIBS += -dead_strip
22+
23+
# LIBS += "/usr/local/Cellar/ffmpeg/4.1.3/lib/libavcodec.a" \
24+
# "/usr/local/Cellar/ffmpeg/4.1.3/lib/libavutil.a" \
25+
# "/usr/local/Cellar/ffmpeg/4.1.3/lib/libavformat.a" \
26+
# "/usr/local/Cellar/ffmpeg/4.1.3/lib/libswscale.a" \
27+
# "/usr/local/Cellar/ffmpeg/4.1.3/lib/libavfilter.a"

scripts/qt.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
git clone git://code.qt.io/qt/qt5.git
4+
cd qt5
5+
git checkout 5.12
6+
7+
perl init-repository -f
8+
9+
./configure -static -opensource -nomake examples -nomake tests -confirm-license
10+
11+
make -j8
12+
sudo make install -j8
13+
14+
mv qt5 /tmp/qt5

0 commit comments

Comments
 (0)