Skip to content

Commit d8895e1

Browse files
committed
- Change output json structure.
- Update CMakeLists.txt. - Upgrade dependencies.
1 parent 25375d5 commit d8895e1

File tree

8 files changed

+161
-60
lines changed

8 files changed

+161
-60
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Custom
2+
cmake-build-debug
3+
14
# Compiled Object files
25
*.slo
36
*.lo

CMakeLists.txt

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
1-
cmake_minimum_required(VERSION 3.6)
2-
project(animeloop_cli)
1+
cmake_minimum_required(VERSION 3.5)
2+
project(animeloop-cli)
3+
4+
find_package(PkgConfig REQUIRED)
35

46
add_subdirectory(${PROJECT_SOURCE_DIR}/cxxopts)
5-
add_subdirectory(${PROJECT_SOURCE_DIR}/jsoncpp)
67

78
include_directories(${PROJECT_SOURCE_DIR}/cxxopts/include)
8-
include_directories(${PROJECT_SOURCE_DIR}/jsoncpp/include/json)
9-
10-
find_package( OpenSSL 1.0.0 REQUIRED )
11-
12-
13-
find_package( OpenCV 3.2.0 REQUIRED )
14-
9+
include_directories(${PROJECT_SOURCE_DIR}/jsoncpp/dist/json)
1510

16-
find_package(Boost 1.63.0 REQUIRED)
1711

1812
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
1913

@@ -28,11 +22,27 @@ set(SOURCE_FILES
2822
animeloop-cli/models.cpp
2923
animeloop-cli/models.hpp
3024
animeloop-cli/utils.cpp
31-
animeloop-cli/utils.hpp)
25+
animeloop-cli/utils.hpp
26+
jsoncpp/dist/jsoncpp.cpp)
27+
28+
add_executable(animeloop-cli ${SOURCE_FILES})
29+
30+
# OpenCV
31+
find_package( OpenCV 3.2 REQUIRED )
32+
target_link_libraries( animeloop-cli ${OpenCV_LIBS} )
33+
34+
# Boost
35+
find_package(Boost COMPONENTS filesystem date_time system REQUIRED)
36+
target_link_libraries( animeloop-cli ${Boost_LIBRARIES} )
37+
38+
# Search OpenSSL
39+
pkg_search_module(OPENSSL REQUIRED openssl)
3240

33-
add_executable(animeloop_cli ${SOURCE_FILES})
41+
if( OPENSSL_FOUND )
42+
include_directories(${OPENSSL_INCLUDE_DIRS})
43+
message(STATUS "Using OpenSSL ${OPENSSL_VERSION}")
44+
else()
45+
# Error; with REQUIRED, pkg_search_module() will throw an error by it's own
46+
endif()
3447

35-
target_link_libraries(${EXECUTABLE_NAME} ${OpenSSL_LIBS})
36-
target_link_libraries(${EXECUTABLE_NAME} ${OpenCV_LIBS})
37-
set(Boost_USE_STATIC_LIBS ON)
38-
target_link_libraries(${EXECUTABLE_NAME} ${Boost_LIBS})
48+
target_link_libraries( animeloop-cli ${OPENSSL_LIBRARIES})

README.md

Lines changed: 84 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,103 @@
11
# animeloop-cli
22
Anime loop video command line tool.
33

4+
5+
46
### Installation
57

6-
#### Git Submodules Init
8+
#### Modules Init
79

8-
```Shell
9-
$ git submodule init
10-
$ git submodule update
10+
``` Shell
11+
git submodule init
12+
git submodule update
13+
```
14+
15+
16+
#### Dependencies
17+
18+
##### macOS
19+
20+
``` Shell
21+
# OpenCV
22+
brew tap homebrew/science
23+
brew install opencv3 --with-contrib --with-ffmpeg --c++11
24+
25+
# Boost
26+
brew install boost
27+
```
28+
29+
##### Linux
30+
31+
``` Shell
32+
# OpenCV
33+
sudo apt-get -y install libopencv-dev build-essential cmake git libgtk2.0-dev pkg-config python-dev python-numpy libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev libtbb-dev libqt4-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils unzip
34+
35+
mkdir opencv
36+
cd opencv
37+
38+
wget https://github.com/Itseez/opencv/archive/3.2.0.zip -O opencv-3.2.0.zip
39+
unzip opencv-3.2.0.zip
40+
cd opencv-3.2.0
41+
42+
mkdir build
43+
cd build
44+
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..
45+
46+
make -j $(nproc)
47+
sudo make install
48+
49+
sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
50+
sudo ldconfig
51+
52+
## uninstall opencv
53+
sudo apt-get remove opencv
54+
55+
# Boost
56+
sudo apt-get install libboost-all-dev
1157
```
1258

13-
#### macOS
59+
#### Compile & Build
60+
61+
##### Xcode
62+
63+
Open `animeloop-cli.xcodeproj` and run it.
1464

15-
Just run in Xcode.
65+
(if you compile opencv source code by yourself, you maybe need edit `Linked Frameworks and Libraries` settings in Xcode project.)
1666

17-
#### Cross-Platform
67+
##### cmake
1868

19-
CMake is not available currently.
69+
``` Shell
70+
cd animeloop-cli
71+
mkdir build
72+
cd build
73+
cmake ..
74+
make
75+
(make install)
76+
```
2077

2178
## Usage
2279

2380
```Shell
24-
$ animeloop -i ~/your-video-file -o ~/Downloads/ --max-duration 4 --min-duration 1.0
25-
```
2681

27-
## Dependencies
2882

29-
* Boost
30-
* OpenCV 3
83+
animeloop [OPTION...]
84+
85+
-h, --help Show animeloop help
86+
-v, --version Show animeloop version
87+
-i, --input arg Input video file path
88+
-o, --output arg Output video directory path (default:
89+
<current dir>)
90+
--episode arg Episode name of the source video (default:
91+
<filename>)
92+
--series arg Series name of the source video (default:
93+
<filename>)
94+
--min-duration arg Minimum duration (second) of loop video (default:
95+
0.8)
96+
--max-duration arg Maximum duration (second) of loop video (default:
97+
4.0)
98+
--cover Output loop video cover image.
3199

32-
## Thanks
33100

34-
* cxxopts
101+
# Example
102+
animeloop -i ~/your-video-file -o ~/Downloads/ --max-duration 4 --min-duration 1.0
103+
```

animeloop-cli/loop_video.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ using namespace cv;
2323
using namespace al;
2424

2525

26-
al::LoopVideo::LoopVideo(std::string title, std::string input, std::string output) {
26+
al::LoopVideo::LoopVideo(std::string series, std::string episode, std::string input, std::string output) {
2727

2828
this->md5 = al::md5_of_file(input);
2929

30-
this->title = title;
30+
this->series = series;
31+
this->episode = episode;
3132

3233
this->filename = path(input).stem().string();
3334

@@ -90,7 +91,9 @@ void al::LoopVideo::generate(const LoopDurations durations) {
9091
VideoInfo info = get_info(this->input_path.string());
9192

9293
Json::Value videos_json;
93-
videos_json["title"] = this->title;
94+
videos_json["series"] = this->series;
95+
videos_json["episode"] = this->episode;
96+
9497
videos_json["animeloop_ver"] = kVersion;
9598

9699
Json::Value source_json;
@@ -146,20 +149,22 @@ void al::LoopVideo::generate(const LoopDurations durations) {
146149
// Save video info json file.
147150
Json::Value video_json;
148151

149-
video_json["video_filename"] = video_filename;
150-
video_json["cover_filename"] = cover_filename;
152+
Json::Value files_json;
153+
files_json["mp4_1080p"] = video_filename;
154+
files_json["jpg_1080p"] = cover_filename;
155+
video_json["files"] = files_json;
151156

152157
video_json["duration"] = video_duration;
153158

154159
Json::Value frame_json;
155-
frame_json["start"] = to_string(start_frame);
160+
frame_json["begin"] = to_string(start_frame);
156161
frame_json["end"] = to_string(end_frame);
157162
video_json["frame"] = frame_json;
158163

159-
Json::Value time_json;
160-
time_json["start"] = al::time_string(start_frame / info.fps);
161-
time_json["end"] = al::time_string(end_frame / info.fps);
162-
video_json["time"] = time_json;
164+
Json::Value period_json;
165+
period_json["begin"] = al::time_string(start_frame / info.fps);
166+
period_json["end"] = al::time_string(end_frame / info.fps);
167+
video_json["period"] = period_json;
163168

164169
auto md5 = al::md5_of_file(video_filepath);
165170
video_json["md5"] = md5;

animeloop-cli/loop_video.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616
#include <boost/filesystem.hpp>
1717

1818
namespace al {
19-
const std::string kVersion = "1.3.0";
19+
const std::string kVersion = "1.3.1";
2020

2121
class LoopVideo {
2222
public:
2323
// infomation
2424
std::string filename;
25-
std::string title;
25+
std::string series;
26+
std::string episode;
2627

2728
// I/O path
2829
boost::filesystem::path input_path;
@@ -49,7 +50,7 @@ namespace al {
4950
LoopDurations filtered_durations;
5051
FrameVector frames;
5152

52-
LoopVideo(std::string title, std::string input, std::string output);
53+
LoopVideo(std::string series, std::string episode, std::string input, std::string output);
5354
cv::CascadeClassifier face_cascade;
5455

5556
void init();

animeloop-cli/main.cpp

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,52 @@
1212
#include "cxxopts.hpp"
1313
#include "loop_video.hpp"
1414

15+
using namespace std;
16+
using namespace boost::filesystem;
17+
using namespace cxxopts;
18+
1519
int main(int argc, char * argv[]) {
1620

17-
auto rpath = boost::filesystem::path(argv[0]).parent_path();
21+
auto rpath = path(argv[0]).parent_path();
1822
double min_duration, max_duration;
1923

2024
try {
2125
cxxopts::Options options("animeloop", "anime loop video generator.");
2226

23-
std::string input, output, title;
27+
string input, output, episode, series;
2428

2529
options.add_options()
2630
("h,help", "Show animeloop help")
2731
("v,version", "Show animeloop version")
28-
("title", "Title of the source video", cxxopts::value<std::string>(title))
29-
("i,input", "Input video file path", cxxopts::value<std::string>(input))
30-
("o,output", "Output video directory path", cxxopts::value<std::string>(output)->default_value(rpath.string()))
31-
("min-duration", "Minimum duration (second) of loop video", cxxopts::value<double>(min_duration)->default_value("0.8"))
32-
("max-duration", "Maximum duration (second) of loop video", cxxopts::value<double>(max_duration)->default_value("4.0"))
32+
("i,input", "Input video file path", value<string>(input))
33+
("o,output", "Output video directory path", value<string>(output)->default_value(rpath.string()))
34+
("episode", "Episode name of the source video (default: <filename>)", value<string>(episode))
35+
("series", "Series name of the source video (default: <filename>)", value<string>(series))
36+
("min-duration", "Minimum duration (second) of loop video", value<double>(min_duration)->default_value("0.8"))
37+
("max-duration", "Maximum duration (second) of loop video", value<double>(max_duration)->default_value("4.0"))
3338
("cover", "Output loop video cover image.")
3439
;
3540

3641
options.parse(argc, argv);
3742

3843
if (options.count("version")) {
39-
std::cout << "version: " << al::kVersion << std::endl;
44+
cout << "version: " << al::kVersion << endl;
4045
}
4146

4247
if (options.count("help")) {
43-
std::cout << options.help() << std::endl;
48+
cout << options.help() << endl;
4449
}
4550

46-
if (options.count("input") && options.count("title")) {
47-
al::LoopVideo loop_video(title, input, output);
51+
if (options.count("input")) {
52+
if (episode == "") {
53+
episode = path(input).stem().string();
54+
}
55+
56+
if (series == "") {
57+
series = path(input).stem().string();
58+
}
59+
60+
al::LoopVideo loop_video(series, episode, input, output);
4861
loop_video.kMinduration = min_duration;
4962
loop_video.kMaxduration = max_duration;
5063

@@ -60,8 +73,8 @@ int main(int argc, char * argv[]) {
6073
}
6174

6275

63-
} catch (const cxxopts::OptionException& e) {
64-
std::cout << "error parsing options: " << e.what() << std::endl;
76+
} catch (const OptionException& e) {
77+
cout << "error parsing options: " << e.what() << endl;
6578
exit(1);
6679
}
6780

cxxopts

0 commit comments

Comments
 (0)