diff --git a/README b/README index e69de29..3d09d94 100644 --- a/README +++ b/README @@ -0,0 +1,66 @@ +PRPA +==== + +Apply a video-filtering chain with full exploitation of multi-threading. + +Usage +----- + +./prpa [options] [file...] + +Options are one or more of the following: + -h [ --help ] produce help message + -f [ --filter ] arg apply a filter (see below) + -i [ --input-file ] arg file to treat + -o [ --output ] arg output file + -c [ --codec ] arg output codec + -d [ --disable ] disable parallelism + +Codecs +------ +Codec name are 4-character codes that can be found on this page +http://www.fourcc.org/codecs.php + +Codec name *must* match the output file extension. +Exemples are: +-c MP42 -o .avi # MPEG4 +-c MP42 -o .mp4 # MPEG4 +-c XVID -o .avi # Xvid +-c theo -o .ogg # OGG Theora + +Note that MP42 and XVID are two of the quickest output codecs and thus will not +be a bottleneck for the parallelism. + +Filter +------ + +Available filters are: +* grey Produce black and white ouput. +* reverse Reverse colors. +* cartoon Try to apply a "cartoon" effect (VERY SLOW). +* drunk Simulate alcool abuse. +* count Count frame per thread (debug?). +* color=B,G,R Apply the B,G,R color filter. +* sepia Apply a sepia effect. +* blur[=X] Blurs the video, X is the strength of the blur effect. +* merge Merge 2 videos pixel per pixel with a transparent effect. +* interlace Merge 2 videos, alterning between one pixel of each. +* inlay=B,G,R Inlay a video into another one at the place of the + B, G or R color, trying to replace the whole color, not + just the particular value. +* strictinlay=B,G,R Inlay a video into another one at the place of the + precise BGR color asked. + +For the merge, interlace, inlay and strict inlay filters, at least two videos +must be passed in the input files list. + +Examples +-------- + +./prpa -f drunk -f sepia -o bar.avi -c MP42 foo.avi +./prpa -f blur=50 -f reverse -o bar.avi -c XVID foo.avi +./prpa -f inlay=1,0,0 -o bar.avi -c XVID foo.avi +./prpa -f strictinlay=255,137,42 -o bar.avi -c XVID orig.avi inlayed.avi + +time ./prpa -f drunk -f sepia -o bar.avi -c MP42 foo.avi +time ./prpa -d -f drunk -f sepia -o bar.avi -c MP42 foo.avi diff --git a/src/filterSample/Makefile.am b/src/filterSample/Makefile.am index 0032175..f1ace7f 100644 --- a/src/filterSample/Makefile.am +++ b/src/filterSample/Makefile.am @@ -8,4 +8,4 @@ AM_CXXFLAGS = \ ______lib_libfilterSample_a_SOURCES = grey.cc reverse.cc merge.cc \ interlace.cc inlay.cc blur.cc cartoon.cc count.cc color.cc \ - rotate.cc + rotate.cc drunk.cc diff --git a/src/filterSample/drunk.cc b/src/filterSample/drunk.cc new file mode 100644 index 0000000..d6217fd --- /dev/null +++ b/src/filterSample/drunk.cc @@ -0,0 +1,33 @@ +#include "drunk.hh" + +#include "opencv2/opencv.hpp" + +void* Drunk::operator()(void* para) +{ + cv::Mat* mat = (cv::Mat*)para; + + if (mat == nullptr) + return nullptr; + + if (this->last_ == nullptr) + { + this->last_ = new cv::Mat(); + *this->last_ = mat->clone(); + } + + auto it1 = mat->begin(); + auto it2 = this->last_->begin(); + while (it1 != mat->end() && it2 != this->last_->end()) + { + (*it2)[0] = (*it1)[0] / 8 + (*it2)[0] * 7 / 8; + (*it2)[1] = (*it1)[1] / 8 + (*it2)[1] * 7 / 8; + (*it2)[2] = (*it1)[2] / 8 + (*it2)[2] * 7 / 8; + (*it1)[0] = (*it2)[0]; + (*it1)[1] = (*it2)[1]; + (*it1)[2] = (*it2)[2]; + ++it1; + ++it2; + } + + return mat; +} diff --git a/src/filterSample/drunk.hh b/src/filterSample/drunk.hh new file mode 100644 index 0000000..189956c --- /dev/null +++ b/src/filterSample/drunk.hh @@ -0,0 +1,16 @@ +#ifndef DRUNK_HH_ +# define DRUNK_HH_ + +# include "tbb/pipeline.h" +# include "opencv2/opencv.hpp" + +class Drunk: public tbb::filter +{ + public: + Drunk(): filter(tbb::filter::parallel), last_(nullptr) {} + void* operator()(void*); + private: + cv::Mat* last_; +}; + +#endif /* !DRUNK_HH_ */ diff --git a/src/main.cc b/src/main.cc index 8f365c3..a76029b 100644 --- a/src/main.cc +++ b/src/main.cc @@ -19,8 +19,8 @@ bool parse_cli(Configuration& conf, int argc, char** argv) desc.add_options() ("help,h", "produce help message") ("filter,f", po::value>(), "apply a filter; " - "choose between grey, reverse, cartoon, count, color=B,G,R, sepia, " - "blur[=X], merge, interlace, inlay=B,G,R, strictinlay=B,G,R") + "choose between grey, reverse, cartoon, drunk, count, color=B,G,R, sepia," + " blur[=X], merge, interlace, inlay=B,G,R, strictinlay=B,G,R") ("input-file,i", po::value>(), "file to treat") ("output,o", po::value(), "output file") ("codec,c", po::value(), "output codec") diff --git a/src/pipeline.cc b/src/pipeline.cc index 7fc61d1..6f0713a 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -16,6 +16,7 @@ #include "filterSample/count.hh" #include "filterSample/color.hh" #include "filterSample/rotate.hh" +#include "filterSample/drunk.hh" Pipeline::Pipeline(std::list input, VideoWriter output) : input_(input), output_(output) @@ -35,6 +36,8 @@ bool Pipeline::add_filter(std::string filter, std::vector args) this->pipeline_.add_filter(*(new Cartoon())); else if (filter == "count") this->pipeline_.add_filter(*(new Count())); + else if (filter == "drunk") + this->pipeline_.add_filter(*(new Drunk())); else if (filter == "rotate-h") this->pipeline_.add_filter(*(new Rotate(0))); else if (filter == "rotate-v")