summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2013-09-03 17:04:32 +0100
committerTim Redfern <tim@eclectronics.org>2013-09-03 17:04:32 +0100
commitf316c9f73a63df12def9a640038bd526c470f5fd (patch)
tree2f91117b623fc7d3dd0db3be3ce25462242559f6
parent2469ddabe2b6e7746984339db84dbe0e7b069255 (diff)
stop blocking on audio analysis
-rw-r--r--rotord/rotord.cbp5
-rwxr-xr-xrotord/src/libavwrapper.cpp34
-rwxr-xr-xrotord/src/libavwrapper.h1
-rw-r--r--rotord/src/nodes_filters.h35
-rw-r--r--rotord/src/rendercontext.cpp16
-rwxr-xr-xrotord/src/rotor.cpp1
6 files changed, 80 insertions, 12 deletions
diff --git a/rotord/rotord.cbp b/rotord/rotord.cbp
index ece9709..9c76a19 100644
--- a/rotord/rotord.cbp
+++ b/rotord/rotord.cbp
@@ -58,12 +58,17 @@
<Unit filename="src/image.h" />
<Unit filename="src/libavwrapper.cpp" />
<Unit filename="src/libavwrapper.h" />
+ <Unit filename="src/nodes_audio_analysis.cpp" />
<Unit filename="src/nodes_audio_analysis.h" />
<Unit filename="src/nodes_drawing.h" />
+ <Unit filename="src/nodes_filters.h" />
+ <Unit filename="src/nodes_maths.h" />
+ <Unit filename="src/nodes_transform.h" />
<Unit filename="src/ofUtils.cpp" />
<Unit filename="src/ofUtils.h" />
<Unit filename="src/params.h" />
<Unit filename="src/rendercontext.cpp" />
+ <Unit filename="src/rendercontext.h" />
<Unit filename="src/rotor.cpp" />
<Unit filename="src/rotor.h" />
<Unit filename="src/rotord.cpp" />
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 &image;
+ }
+ 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());