diff options
| author | Tim Redfern <tim@eclectronics.org> | 2013-09-03 17:04:32 +0100 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2013-09-03 17:04:32 +0100 |
| commit | f316c9f73a63df12def9a640038bd526c470f5fd (patch) | |
| tree | 2f91117b623fc7d3dd0db3be3ce25462242559f6 /rotord/src | |
| parent | 2469ddabe2b6e7746984339db84dbe0e7b069255 (diff) | |
stop blocking on audio analysis
Diffstat (limited to 'rotord/src')
| -rwxr-xr-x | rotord/src/libavwrapper.cpp | 34 | ||||
| -rwxr-xr-x | rotord/src/libavwrapper.h | 1 | ||||
| -rw-r--r-- | rotord/src/nodes_filters.h | 35 | ||||
| -rw-r--r-- | rotord/src/rendercontext.cpp | 16 | ||||
| -rwxr-xr-x | rotord/src/rotor.cpp | 1 |
5 files changed, 75 insertions, 12 deletions
diff --git a/rotord/src/libavwrapper.cpp b/rotord/src/libavwrapper.cpp index 6081ed6..180032d 100755 --- a/rotord/src/libavwrapper.cpp +++ b/rotord/src/libavwrapper.cpp @@ -361,12 +361,13 @@ int libav::decoder::seekToFrame(int targetFrameIndex) return -1; } int result = avformat_seek_file( container, //format context - videoStream,//stream id - 0, //min timestamp 0? + videoStream,//stream id + 0, //min timestamp 0? ts, //target timestamp ts, //max timestamp - 0);//flags AVSEEK_FLAG_ANY //doesn't seem to work great - if (result < 0) + 0);//flags AVSEEK_FLAG_ANY // + + if (result< 0) return -1; avcodec_flush_buffers(pCtx); @@ -376,6 +377,31 @@ int libav::decoder::seekToFrame(int targetFrameIndex) return targetFrameIndex; } +// \returns current frame on success, otherwise -1 +int libav::decoder::seekToFrameNew(int targetFrameIndex) +{ + int64_t duration = container->streams[videoStream]->duration; + int64_t ts = av_rescale(duration,targetFrameIndex,numFrames); + int64_t tol = av_rescale(duration,1,2*numFrames); + if ( (targetFrameIndex < 0) || (targetFrameIndex >= numFrames) ) { + return -1; + } + + int flags = AVSEEK_FLAG_BACKWARD; + if (ts > 0 && ts < duration) + flags |= AVSEEK_FLAG_ANY; // H.264 I frames don't always register as "key frames" in FFmpeg + + int ret = av_seek_frame(container, videoStream, ts, flags); + if (ret < 0) + ret = av_seek_frame(container, videoStream, ts, AVSEEK_FLAG_ANY); + + + if (ret< 0) + return -1; + + return targetFrameIndex; +} + bool libav::decoder::readNextFrame(int targetFrameIndex) { AVPacket packet = {0}; diff --git a/rotord/src/libavwrapper.h b/rotord/src/libavwrapper.h index ea2e0c6..6ae6bd2 100755 --- a/rotord/src/libavwrapper.h +++ b/rotord/src/libavwrapper.h @@ -112,6 +112,7 @@ namespace libav { bool readNextFrame(int targetFrameIndex = 0); bool readNextFrameWithPacket(int targetFrameIndex, AVPacket& packet, AVFrame* pYuv); int seekToFrame(int targetFrameIndex = 0); + int seekToFrameNew(int targetFrameIndex = 0); // make certain members public, for use by Fast3DTexture class AVFrame *pFrameRGB; diff --git a/rotord/src/nodes_filters.h b/rotord/src/nodes_filters.h index 4e2826f..b96c78e 100644 --- a/rotord/src/nodes_filters.h +++ b/rotord/src/nodes_filters.h @@ -31,6 +31,41 @@ namespace Rotor { private: float size; }; + class VHS: public Image_node { + public: + VHS(){ + title="VHS"; + description="VHS degradation filter"; + create_parameter("generation_loss","number","VHS generation loss amount","Generation loss",1.0f); + create_image_input("image input","Image input"); + }; + VHS(map<string,string> &settings):VHS() { + base_settings(settings); + }; + ~VHS(){ + }; + VHS* clone(map<string,string> &_settings) { return new VHS(_settings);}; + Image *output(const Frame_spec &frame){ + Image *in=image_inputs[0]->get(frame); + if (in) { + cvtColor(in->rgb, hsv, CV_RGB2YUV); + vector<cv::Mat> chans; + split(hsv,chans); + int ksize=max((ceil(parameters["generation_loss"]->value/2.0)*2)+1,1.0); + //no blurring in place? + GaussianBlur(chans[2],chans[2],cvSize(ksize,ksize),parameters["generation_loss"]->value); + GaussianBlur(chans[1],chans[1],cvSize(ksize,ksize),parameters["generation_loss"]->value); + //if (ksize>7) GaussianBlur(chans[0],chans[0],cvSize(ksize/4,ksize/4),parameters["generation_loss"]->value/4); + merge(chans,hsv); + cvtColor(hsv, image.rgb, CV_YUV2RGB); + return ℑ + } + return nullptr; + } + private: + float size; + cv::Mat hsv,hsv1; + }; class Luma_levels: public Image_node { public: Luma_levels(){ diff --git a/rotord/src/rendercontext.cpp b/rotord/src/rendercontext.cpp index 679cea1..63e6f4c 100644 --- a/rotord/src/rendercontext.cpp +++ b/rotord/src/rendercontext.cpp @@ -102,7 +102,7 @@ void Render_context::session_command(const Session_command& command,xmlIO& XML,H //pass to worker thread ??if engine is ready?? ??what if engine has finished but results aren't read?? add_queue(Session_task(command.uid,ANALYSE_AUDIO)); status=HTTPResponse::HTTP_OK; - logger.information("Starting audio analysis: "+command.body); + logger.information("Audio analysis: "+command.body); XML.addValue("status","Starting audio analysis: "+command.body); } else { @@ -260,7 +260,7 @@ void Render_context::session_command(const Session_command& command,xmlIO& XML,H if (command.commands[1]=="video") { if (command.method=="PUT") { //get vide file location and initiate analysis if (command.body!="") { //there should be a filename + a destination node - if (state==IDLE) { + //if (state==IDLE) { string video_filename=media_dir+command.body; //check file exists Poco::File f=Poco::File(video_filename); @@ -283,12 +283,12 @@ void Render_context::session_command(const Session_command& command,xmlIO& XML,H logger.error("ERROR: "+command.body+" not found"); XML.addValue("error",command.body+" not found"); } - } - else { - status=HTTPResponse::HTTP_BAD_REQUEST; - logger.error("ERROR: Session busy"); - XML.addValue("error","Session busy"); - } + //} + //else { + // status=HTTPResponse::HTTP_BAD_REQUEST; + // logger.error("ERROR: Session busy"); + // XML.addValue("error","Session busy"); + //} } else { status=HTTPResponse::HTTP_BAD_REQUEST; diff --git a/rotord/src/rotor.cpp b/rotord/src/rotor.cpp index 3246240..23f82d7 100755 --- a/rotord/src/rotor.cpp +++ b/rotord/src/rotor.cpp @@ -38,6 +38,7 @@ Node_factory::Node_factory(){ add_type("waves",new Waves()); //nodes_filters.h add_type("blur",new Blur()); + add_type("vhs",new VHS()); add_type("luma_levels",new Luma_levels()); add_type("echo_trails",new Echo_trails()); add_type("rgb_levels",new RGB_levels()); |
