Skip to content

Commit

Permalink
Merge pull request #10 from petermcneil/bug/dynamic-libraries
Browse files Browse the repository at this point in the history
Bug/dynamic libraries
  • Loading branch information
petermcneil authored May 6, 2019
2 parents bcb94ab + 15f3a6f commit d1b7e9f
Show file tree
Hide file tree
Showing 14 changed files with 115 additions and 77 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
cmake_minimum_required(VERSION 3.13)
project(lodge)

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

FIND_PACKAGE(Boost 1.68 COMPONENTS filesystem program_options regex REQUIRED)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
FIND_PACKAGE(Boost 1.69 COMPONENTS filesystem program_options regex REQUIRED)

enable_testing()

add_subdirectory(include)
add_subdirectory(lib)
add_subdirectory(app)
add_subdirectory(gui)
add_subdirectory(app)
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: clean build run test
.PHONY: clean build run test gui release

clean:
rm -rf build/
Expand All @@ -15,7 +15,7 @@ run: build
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"

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

test:
@mkdir -p ./build
Expand All @@ -31,4 +31,7 @@ release:
@make -C ./release

gui: build
@mkdir -p build/gui
@qmake -o build/gui
make -C build/gui -j8
open build/gui/Lodge.app
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,37 @@ used by video editors or stenographers and will merge the subtitles into the vid
(Lodge Viewer) will be used by the layperson while watching videos and will extract the subtitles from the video file
and display them to the user. The two products together will provide a complete end-to-end workflow for subtitling.


Compiled for MacOS 10.12.+

Dependencies
--
For using the Lodge binaries on a system FFmpeg must be installed. Use Homebrew for easiest installation.

To build Lodge for development purposes the following dependencies need to be installed

- Qt5
- FFmpeg
- Boost
- Spdlog

The script `./configure` is provided for convenience of setting these up. It will use Homebrew to install these packages.

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
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
by editing the script.


Building
---
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.

- make build: builds all non-gui parts
- make gui: builds everything and runs GUI
- make tests: runs the tests
- make read: runs a full write and read of a subtitle file
- make run: runs a write of a subtitle file

Detecting Lodge in video frames
---
A header will be written to each frame that Lodge writes to, of the format:
Expand Down
3 changes: 0 additions & 3 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wshadow -Wnon-virtual-dtor -pedantic -g")

set(BINARY_NAME lodge)
file (GLOB APP_SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")

Expand All @@ -13,4 +11,3 @@ target_link_libraries(${BINARY_NAME} PUBLIC "libavutil.a")
target_link_libraries(${BINARY_NAME} PUBLIC "libavcodec.a")
target_link_libraries(${BINARY_NAME} PUBLIC "libavfilter.a")
target_link_libraries(${BINARY_NAME} PUBLIC "swscale.a")
target_link_libraries(${BINARY_NAME} PUBLIC "swscale.a")
8 changes: 5 additions & 3 deletions app/src/lodge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,26 +87,28 @@ int main(int ac, char *av[]) {
string input = vm["input"].as<string>();;
cout << "Reading from video file: " << input << endl;
string output;
subtitle *sub;

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

log::debug("Building subtitle object");
subtitle *sub = new subtitle(output, RW::WRITE);
log::debug("Building video object");
video *vid = new video(input, sub);

if (vid->has_steg_file()) {
cout << "Writing to subtitle file: " << sub->get_path() << endl;
cout << "Writing to subtitle file: " << vid->subtitle_file->get_path() << endl;
log::debug("Starting to read from the video file");
ret = vid->read_subtitle_file();
if (ret == 0) {
cout << "\x1B[32mSuccessfully saved the subtitle file: " << sub->get_path() << "\x1B[0m" << endl;
cout << "\x1B[32mSuccessfully saved the subtitle file: " << vid->subtitle_file->get_path() << "\x1B[0m" << endl;
return EXIT_SUCCESS;
} else {
cout << "\x1B[91mFailed to extract a subtitle file from: " << input << "\x1B[0m" << endl;
Expand Down
2 changes: 1 addition & 1 deletion extras/samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ the project the right to download, edit, and re-distribute at will without attri

Despite the license, I still believe it is right and proper to give proper attribution.
The table below details the "owner" and gives a link to where you may download it yourselves.
``

|Video |Attribution |Link |
|-----------------------------|-------------|---------------------------------------------------------------------|
|Time Lapse Video Of Night Sky|Vimeo |https://videos.pexels.com/videos/time-lapse-video-of-night-sky-857195|
Expand Down
39 changes: 0 additions & 39 deletions gui/CMakeLists.txt

This file was deleted.

2 changes: 1 addition & 1 deletion gui/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <video.h>
#include <src/backend.h>
#include "backend.h"

int main(int argc, char *argv[]) {
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
Expand Down
4 changes: 1 addition & 3 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
project(lodge_lib)

set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wshadow -Wnon-virtual-dtor -pedantic -g")

set (LIBRARY_MODULE_PATH "${CMAKE_SOURCE_DIR}/lib")
set (LIBRARY_SRC_PATH "${CMAKE_CURRENT_SOURCE_DIR}/src" )
set (LIBRARY_INCLUDE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/include")
Expand All @@ -12,7 +10,7 @@ include_directories (${LIBRARY_INCLUDE_PATH})
file (GLOB LIB_HEADER_FILES "${LIBRARY_INCLUDE_PATH}/*.h")
file (GLOB LIB_SOURCE_FILES "${LIBRARY_SRC_PATH}/*.cpp")

add_library (${PROJECT_NAME} STATIC ${LIB_SOURCE_FILES} ${LIB_HEADER_FILES})
add_library (${PROJECT_NAME} STATIC ${LIB_SOURCE_FILES} ${LIB_HEADER_FILES} ${Boost_INCLUDE_DIRS} ${Boost_LIBRARY_DIRS})

enable_testing()
add_subdirectory (test)
4 changes: 2 additions & 2 deletions lib/include/video.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace lodge {

class video {
private:
filesystem::path inputFilePath;
filesystem::path input_file_path;
filesystem::path outputFilePath;
vector<frame_header> *headers = new vector<frame_header>;

Expand All @@ -39,7 +39,7 @@ namespace lodge {

int write_x = 0;
int write_y = 0;
int block_size = 1;
int block_size = 16;
int no_of_frames = 0;
int no_of_bits_in_char = 8;

Expand Down
2 changes: 1 addition & 1 deletion lib/src/subtitle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ int subtitle::write_line(const vector<char> &lineCharacters) {
line += character;
}
}
log::trace("Adding this to file: {}", line);
log::debug("Adding this to file: {}", line);
*subtitle_file << line << std::endl;
return 0;
}
Expand Down
41 changes: 23 additions & 18 deletions lib/src/video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ using namespace lodge;
namespace log = spdlog;

video::video(string inputVideo, string outputVideo, subtitle *subFile) {
this->inputFilePath = canonical(filesystem::path(inputVideo));
this->input_file_path = canonical(filesystem::path(inputVideo));
this->outputFilePath = weakly_canonical(filesystem::path(outputVideo));
this->subtitle_file = subFile;
}

video::video(string inputVideo, subtitle *subFile) {
this->inputFilePath = weakly_canonical(filesystem::path(inputVideo));
this->input_file_path = weakly_canonical(filesystem::path(inputVideo));
this->subtitle_file = subFile;
}

Expand Down Expand Up @@ -278,7 +278,7 @@ int video::open_input_file() {
input_format_context = nullptr;

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

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

Expand Down Expand Up @@ -881,6 +881,7 @@ int video::read_subtitle_file() {
return -234;
}

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

while (this->no_of_frames > 0 && av_read_frame(format, pkt) >= 0) {
Expand Down Expand Up @@ -972,17 +973,21 @@ bool video::has_steg_file() {
frame_header *h = this->read_steg_header(picture);
if (h != nullptr) {
log::debug("Setting frame_header: {}", h->to_string());
log::debug("Creating new subtitle");
log::debug("Checking if subtitle file exists");
if(this->subtitle_file == nullptr) {
filesystem::path output_sub = this->input_file_path.parent_path();
output_sub /= filesystem::path(h->filename);
log::debug("New path for subtitle file: {}", output_sub.c_str());
this->subtitle_file = new subtitle(output_sub, RW::WRITE);
}

filesystem::path output_sub = this->subtitle_file->get_path().parent_path();
output_sub /= filesystem::path(h->filename);
this->subtitle_file = new subtitle(output_sub, RW::WRITE);
this->no_of_frames = (int) h->total_frames;
log::debug("Has header = true");
has_header = true;
} else {
this->no_of_frames = 0;
has_header = false;
}
log::debug("Has header = true");
has_header = true;
av_frame_unref(frame);
goto end;
}
Expand Down Expand Up @@ -1013,19 +1018,19 @@ int video::init_read() {

context = nullptr;
format = avformat_alloc_context();
log::debug("Opening input '{}' in libav", this->inputFilePath.generic_string());
ret = avformat_open_input(&format, this->inputFilePath.c_str(), nullptr, nullptr);
log::debug("Opening input '{}' in libav", this->input_file_path.generic_string());
ret = avformat_open_input(&format, this->input_file_path.c_str(), nullptr, nullptr);

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

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

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

Expand All @@ -1041,7 +1046,7 @@ int video::init_read() {
}

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

Expand Down Expand Up @@ -1077,11 +1082,11 @@ int video::init_read() {
return -1;
}

log::debug("Open the input file: '{}'", inputFilePath.generic_string());
f = fopen(inputFilePath.c_str(), "rb");
log::debug("Open the input file: '{}'", input_file_path.generic_string());
f = fopen(input_file_path.c_str(), "rb");

if (!f) {
log::error("Could not open file: ", inputFilePath.generic_string());
log::error("Could not open file: ", input_file_path.generic_string());
return -1;
}

Expand Down
27 changes: 27 additions & 0 deletions main.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
QMAKE_CXXFLAGS = -fvisibility=hidden -fvisibility-inlines-hidden
CONFIG += app_bundle
ICON = gui/resources/icon.icns

TARGET = Lodge
CONFIG += c++17
CONFIG += qt debug

QT += core widgets quick

HEADERS = gui/src/backend.h
SOURCES = gui/src/backend.cpp gui/src/main.cpp
RESOURCES += gui/qml.qrc

INCLUDEPATH += lib/include
INCLUDEPATH += /usr/local/Cellar/ffmpeg/4.1.3/include
INCLUDEPATH += /usr/local/include/
LIBS += "$$PWD/build/lib/liblodge_lib.a"
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"
LIBS += "-L/usr/local/Cellar/ffmpeg/4.1.3/lib" -lavcodec -lavutil -lavformat -lswscale -lavfilter
LIBS += -dead_strip

# LIBS += "/usr/local/Cellar/ffmpeg/4.1.3/lib/libavcodec.a" \
# "/usr/local/Cellar/ffmpeg/4.1.3/lib/libavutil.a" \
# "/usr/local/Cellar/ffmpeg/4.1.3/lib/libavformat.a" \
# "/usr/local/Cellar/ffmpeg/4.1.3/lib/libswscale.a" \
# "/usr/local/Cellar/ffmpeg/4.1.3/lib/libavfilter.a"
14 changes: 14 additions & 0 deletions scripts/qt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

git clone git://code.qt.io/qt/qt5.git
cd qt5
git checkout 5.12

perl init-repository -f

./configure -static -opensource -nomake examples -nomake tests -confirm-license

make -j8
sudo make install -j8

mv qt5 /tmp/qt5

0 comments on commit d1b7e9f

Please sign in to comment.