summaryrefslogtreecommitdiff
path: root/rotord
diff options
context:
space:
mode:
Diffstat (limited to 'rotord')
-rwxr-xr-xrotord/src/libavwrapper.cpp2
-rwxr-xr-xrotord/src/rotor.cpp22
-rwxr-xr-xrotord/src/rotor.h39
3 files changed, 53 insertions, 10 deletions
diff --git a/rotord/src/libavwrapper.cpp b/rotord/src/libavwrapper.cpp
index 1b18769..6081ed6 100755
--- a/rotord/src/libavwrapper.cpp
+++ b/rotord/src/libavwrapper.cpp
@@ -1566,7 +1566,7 @@ bool libav::audioloader::setup(const std::string &filename){
return &packet;
}
- uint16_t* libav::audioloader::get_samples(int num){ //presumes 16bpc here
+ uint16_t* libav::audioloader::get_samples(int num){ //presumes 16bpc here and outputs interleaved samples
//std::cerr << "request "<<num<<" samples: "<<(ready?"ready":"not ready")<<std::endl;
//if(!ready) return nullptr;
//shuffle down samples
diff --git a/rotord/src/rotor.cpp b/rotord/src/rotor.cpp
index 7ab9e54..73ef0cc 100755
--- a/rotord/src/rotor.cpp
+++ b/rotord/src/rotor.cpp
@@ -199,12 +199,8 @@ bool Video_output::render(const float duration, const float framerate,const stri
libav::audioloader audioloader;
- bool usingaudio=false;
+ bool usingaudio=audioloader.setup(audio_filename);
float *avframe=nullptr;
- if (audioloader.setup(audio_filename)){
- bool usingaudio=true;
- //avframe=new float[audioloader.channels*]
- }
Logger& logger = Logger::get("Rotor");
@@ -216,6 +212,11 @@ bool Video_output::render(const float duration, const float framerate,const stri
gettimeofday(&start, NULL);
+ //does audioloader output interleaved samples?
+ int samples_in_frame=(audioloader.codecContext->channels*audioloader.codecContext->sample_rate)/framerate;
+ string whether=usingaudio?"Loading":"Cannot load";
+ logger.information(whether+" audio file: "+audio_filename+", each frame contains "+ofToString(samples_in_frame)+" samples at "+ofToString(audioloader.codecContext->sample_rate)+" hz");
+
float vstep=1.0f/framerate;
float v=0.0f;
float vf=0.0f;
@@ -302,7 +303,16 @@ Image* Video_loader::output(const Frame_spec &frame){
float clipspeed=(clipframerate/frame.framerate)*parameters["speed"]->value;
- int wanted=(((int) ((frame.time*frame.framerate*clipspeed)+0.5))%(player.getNumberOfFrames()-1))+1; //+1 is necessary because 1st frame in a video is number 1?
+ int wanted;
+ if (attributes["mode"]->intVal==VIDEOFRAMES_frame) {
+ wanted=(((int) ((frame.time*frame.framerate)+0.5))%(player.getNumberOfFrames()-1))+1; //+1 is necessary because 1st frame in a video is number 1?
+ }
+ if (attributes["mode"]->intVal==VIDEOFRAMES_blend) {
+ wanted=(((int) ((frame.time*frame.framerate*clipspeed)+0.5))%(player.getNumberOfFrames()-1))+1; //+1 is necessary because 1st frame in a video is number 1?
+ }
+
+ cerr<<"Video_loader: wanted frame "<<wanted<<endl;
+
if (wanted!=lastframe){
if (!player.fetchFrame(frame.w,frame.h,wanted)) { //seek fail
Logger& logger = Logger::get("Rotor");
diff --git a/rotord/src/rotor.h b/rotord/src/rotor.h
index a2e5876..fc557cd 100755
--- a/rotord/src/rotor.h
+++ b/rotord/src/rotor.h
@@ -126,6 +126,7 @@ namespace Rotor {
virtual ~Attribute(){};
Attribute(const string &_desc,const string &_title,const string &_value,std::vector<std::string> _vals={}): description(_desc),title(_title),value(_value),intVal(0){
vals=_vals;
+ init(_value);
};
void init(const string &_key){ //inits int value from set::string vals index
value=_key;
@@ -157,6 +158,14 @@ namespace Rotor {
void create_attribute(const string &_attr,const string &_desc,const string &_title,const string &_value,std::vector<std::string> _vals={}) {
attributes[_attr]=new Attribute(_desc,_title,_value,_vals);
};
+ void create_attribute(string *alias,const string &_attr,const string &_desc,const string &_title,const string &_value,std::vector<std::string> _vals={}) {
+ attributes[_attr]=new Attribute(_desc,_title,_value,_vals);
+ alias=&(attributes[_attr]->value);
+ };
+ void create_attribute(int *alias,const string &_attr,const string &_desc,const string &_title,const string &_value,std::vector<std::string> _vals={}) {
+ attributes[_attr]=new Attribute(_desc,_title,_value,_vals);
+ alias=&(attributes[_attr]->intVal);
+ };
string description;
string type;
string ID;
@@ -227,6 +236,29 @@ namespace Rotor {
virtual void print_summary(){};
int channels,bits,samples,rate;
};
+ class LUT {
+ LUT(){
+ lut=nullptr;
+ };
+ ~LUT(){if (lut) { delete[] lut;} };
+ void generate(float black_in,float white_in,float black_out,float white_out,float gamma){
+ //can check here if anything has changed
+ if (lut) delete[] lut;
+ lut=new unsigned char[256];
+ float fltmax=(255.0f/256.0f);
+ for (int i=0;i<256;i++){
+ lut[i]=(unsigned char)(((pow(min(fltmax,max(0.0f,(((((float)i)/256.0f)-black_in)/(white_in-black_in)))),(1.0/gamma))*(white_out-black_out))+black_out)*255.0f);
+ }
+ }
+ void apply(const cv::Mat& in,cv::Mat &out){ //facility to apply to other images for inherited classes
+ out.create(in.rows,in.cols,in.type());
+ for (int i=0;i<in.rows*in.cols*in.channels();i++){
+ out.data[i]=lut[in.data[i]];
+ }
+ }
+ protected:
+ unsigned char *lut;
+ };
//actual nodes-------------------------------------------------
class Time: public Signal_node {
public:
@@ -752,6 +784,8 @@ namespace Rotor {
}
else image.alpha_from_cv(mask);
return &image;
+
+ //cv::cvtColor
}
//if there aren't 2 image inputs connected just return the first
return in1;
@@ -761,7 +795,7 @@ namespace Rotor {
private:
cv::Mat greyfg,greybg,greyDiff,mask;
};
-#define VIDEOFRAMES_still 1
+#define VIDEOFRAMES_frame 1
#define VIDEOFRAMES_blend 2
class Video_loader: public Image_node {
public:
@@ -769,7 +803,7 @@ namespace Rotor {
create_parameter("speed","number","video playback speed","Speed",1.0f,0.0f,0.0f);
create_parameter("framerate","number","framerate override","Frame rate",0.0f,0.0f,0.0f);
create_attribute("filename","name of video file to load","File name","");
- create_attribute("mode","frame mode","Mode","still",{"still","blend"});
+ create_attribute("mode","frame mode","Mode","frame",{"frame","blend"});
title="Video loader";
description="Loads a video file";
};
@@ -788,7 +822,6 @@ namespace Rotor {
bool isLoaded;
private:
libav::decoder player;
- int mode;
int lastframe;
};
class Video_output: public Image_node {