Skip to content

Commit

Permalink
added avtranscoder as ext dep, light usage
Browse files Browse the repository at this point in the history
removed docs
added dirty rgb pixel-read from frame
  • Loading branch information
cirquit committed Mar 28, 2017
1 parent 1ef1813 commit 78f96d7
Show file tree
Hide file tree
Showing 75 changed files with 279 additions and 4,788 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -54,3 +54,5 @@ trdrop_lib/build/*
trdrop_c/build/*
trdrop_v/build/*

#docs
trdrop_lib/apidocs/*
3 changes: 3 additions & 0 deletions .gitmodules
@@ -0,0 +1,3 @@
[submodule "ext/avTranscoder"]
path = ext/avTranscoder
url = https://github.com/avTranscoder/avTranscoder
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -25,6 +25,7 @@ install:


before_script:
- cd ext/avTranscoder && mkdir build && cd build && cmake .. -DAVTRANSCODER_DISABLE_APPS=True -DAVTRANSCODER_DISABLE_BINDINGS=True && sudo make install
- cd trdrop_lib/build && cmake .. && make && cd ../..
- cd trdrop_c/build && cmake .. && cd ../..
- cd trdrop_v/build && cmake .. && cd ../..
Expand Down
23 changes: 23 additions & 0 deletions CONTRIBUTING.md
Expand Up @@ -2,6 +2,29 @@

I use `clang-3.9`, `cmake-3.5.2` for local development. Travis runs tests with `cmake-2.8.7`, `clang-3.9` and `gcc-4.6.3` (even if I specifiy `gcc-5`). Documentation for `trdrop_lib` is generated with [`doxygen-1.8.14`](http://www.stack.nl/~dimitri/doxygen/download.html).

Using `ffmpeg-libs`. Install with `sudo apt-get install libavdevice-dev libavformat-dev libavfilter-dev libavcodec-dev libswscale-dev libavutil-dev`.
Using `https://github.com/avTranscoder/avTranscoder` as C++ wrapper for `ffmpeg`. Install with:

```bash
$ cd ext/avTranscoder
$ mkdir build && cd build
$ cmake ..
$ make
$ sudo make install
```

Create docs for `avtranscoder`:

```bash
$ cd ext/avTranscoder
$ cd build/src

Modify the Doxyfile so OUTPUT_DIRECTORY points to .

$ doxygen Doxyfile
$ firefox html/index.html
```

### Build process for Linux

Clone or fork the repo. (cloning in the example)
Expand Down
1 change: 1 addition & 0 deletions ext/avTranscoder
Submodule avTranscoder added at 858cc2
7 changes: 6 additions & 1 deletion trdrop_c/CMakeLists.txt
Expand Up @@ -6,13 +6,18 @@ project(trdrop_c)
##################################

# set flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -lavtranscoder")

# static library of trdrop
set (PROJECT_LINK_LIBS trdrop )
link_directories( ../trdrop_lib/build )
include_directories( ../trdrop_lib/include )


# include c++ wrapper for ffmpeg
# link_directories( ../ext/avTranscoder/build )
# include_directories( ../ext/avTranscoder/src/AvTranscoder )

# headers lie in the folder "include"
include_directories(include)

Expand Down
173 changes: 167 additions & 6 deletions trdrop_c/src/main.cpp
@@ -1,10 +1,171 @@
#include "trdrop.h"
#include <iostream>
#include <trdrop.hpp>

int main(int argc, char const* argv[])
#include <algorithm> // for_each
#include <locale>
#include <string>
#include <tuple>
#include <utility> // pair
#include <vector>

#include <AvTranscoder/file/InputFile.hpp>
#include <AvTranscoder/progress/ConsoleProgress.hpp>
#include <AvTranscoder/properties/PixelProperties.hpp>
#include <AvTranscoder/properties/VideoProperties.hpp>
#include <AvTranscoder/reader/VideoReader.hpp>
#include <AvTranscoder/util.hpp> // PropertyVector

// #define DEBUG_FILENAME "/home/rewrite/Videos/Sample 1 1080p FPS Drop Zelda Wii U.avi"
// #define DEBUG_FILENAME "/home/rewrite/Videos/Sample 2 1080p FPS Stable Skyrim XB1.avi"
// #define DEBUG_FILENAME "/home/rewrite/Videos/Sample 3 1080p Tearing Watch Dogs 2 PS4.avi"
// #define DEBUG_FILENAME "../../videos/Dirty Art Club - Rosslyn's Crypt.mp4"
#define DEBUG_FILENAME "../../videos/test-video-01.avi"

int same_until(std::vector<char> a, std::vector<char> b)
{
std::cout << "Hello World from the command line interface of trdrop."
<< '\n';
trdrop::print_hello_from_lib();
int diff = 0;
for (int i = 0; i < a.size(); ++i) {
diff += a[i] == b[i] ? 0 : 1;
}
return diff;
}

std::vector<std::tuple<int, int, int> > to_rgb_vector(const char* data, size_t width, int height)
{
std::vector<std::tuple<int, int, int> > rgb_vector;

for (int i = 0; i < height * width; i += 3) {
int r = static_cast<int>(data[i]);
int g = static_cast<int>(data[i + 1]);
int b = static_cast<int>(data[i + 2]);

if (r < 0)
r = 256 + r;

if (g < 0)
g = 256 + g;

if (b < 0)
b = 256 + b;

rgb_vector.push_back(std::make_tuple(r, g, b));
}

return rgb_vector;
}

int main(int argc, char** argv)
{
avtranscoder::preloadCodecsAndFormats(); // load ffmpeg context

avtranscoder::InputFile videoFile(DEBUG_FILENAME);

const std::vector<float> fpss(trdrop::get_fps_from_properties(videoFile));
for_each(fpss.begin(), fpss.end(),
[](const float& fps) {
std::cout << "Properties FPS: " << fps << '\n';
});

avtranscoder::VideoReader reader(avtranscoder::InputStreamDesc(DEBUG_FILENAME, 0));

int fst = 0;
int snd = 1;

const char* fst_frame = (const char*)reader.readFrameAt(fst)->getData()[0];
/*
std::vector<char> fst_frame_vector = std::vector<char>(reader.readFrameAt(fst)->getDataSize());
for (int i = 0; i < fst_frame_vector.size(); ++i) {
fst_frame_vector[i] = fst_frame[i];
}
const char* snd_frame = (const char*)reader.readFrameAt(snd)->getData()[0];
std::vector<char> snd_frame_vector = std::vector<char>(reader.readFrameAt(snd)->getDataSize());
for (int i = 0; i < snd_frame_vector.size(); ++i) {
snd_frame_vector[i] = snd_frame[i];
}
std::cout << fst_frame_vector[320] << '\n';
std::cout << snd_frame_vector[320] << '\n';
int diff = same_until(fst_frame_vector, snd_frame_vector);
std::cout << "diff : " << diff << '\n';
std::cout << reader.readFrameAt(snd)->getAVFrame().format << '\n';
*/

int size = reader.readFrameAt(fst)->getDataSize();
int width = *reader.readFrameAt(fst)->getLineSize();
int height = size / width;

std::vector<std::tuple<int, int, int> > rgb_vector(to_rgb_vector(fst_frame, height, width));

std::cout << "size: " << size << '\n';
std::cout << "width: " << width << '\n';
std::cout << "height: " << height << '\n';

std::cout << rgb_vector.size() << '\n';
//char c = '{';
//std::cout << "convert: " << static_cast<int>(c) << '\n';

for (int px = 0; px < size / 3; ++px) {
std::cout << "r: " << std::get<0>(rgb_vector[px])
<< ", g: " << std::get<1>(rgb_vector[px])
<< ", b: " << std::get<2>(rgb_vector[px]) << '\n';
}
// for (int i = 0; i < fst_frame)

/*
const char* b2 = (const char*)reader.readFrameAt(snd)->getData()[0];
char b2_val = b2[202];
std::cout << b1_val << '\n';
std::cout << b2_val << '\n';
*/
// char* result = malloc(reader.getOutputHeight() * reader.getOutputWidth() * sizeof(char));
/*
bool b = true;
for (int i = 0; i < reader.getOutputHeight() * reader.getOutputWidth(); ++i) {
//if (b1[i] != b2[i]) {
//b &= false;
// std::wcout << b1[i]; // << " - " << b2[i];
//}
}
*/

/*
avtranscoder::FileProperties file_prop(videoFile.getProperties());
const std::vector<avtranscoder::VideoProperties> video_props(file_prop.getVideoProperties());
const avtranscoder::VideoProperties video_prop(video_props[0]);
const avtranscoder::PixelProperties pixel_prop(video_prop.getPixelProperties());
avtranscoder::PropertyVector prop_vector(pixel_prop.asVector());
*/
// trdrop::print_properties(prop_vector);

// avtranscoder::VideoProperties video_prop(videoFile.getProperties().getVideoProperties());

/*
// call to analyse to access getProperties()
videoFile.analyse(p, avtranscoder::eAnalyseLevelFull);
avtranscoder::PropertyVector properties(videoFile.getProperties().asVector());
for_each(properties.begin(), properties.end(),
[](std::pair<std::string, std::string> pair) {
std::cout << std::get<0>(pair) << ": " << std::get<1>(pair) << '\n';
});
const std::vector<avtranscoder::VideoProperties>& videoPropVector = videoFile.getProperties().getVideoProperties();
for_each(videoPropVector.begin(), videoPropVector.end(),
[](const avtranscoder::VideoProperties& vprop) {
std::cout << vprop.getFps() << '\n';
});
// std::cout << videoFile.getProperties().getVideoProperties() << '\n';
*/
return 0;
}
Binary file removed trdrop_lib/apidocs/html/bc_s.png
Binary file not shown.
Binary file removed trdrop_lib/apidocs/html/bdwn.png
Binary file not shown.
Binary file removed trdrop_lib/apidocs/html/closed.png
Binary file not shown.
85 changes: 0 additions & 85 deletions trdrop_lib/apidocs/html/dir_68267d1309a1af8e8297ef4c3efbcdba.html

This file was deleted.

0 comments on commit 78f96d7

Please sign in to comment.