diff options
| author | Tim Redfern <tim@eclectronics.org> | 2013-10-31 14:05:48 +0000 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2013-10-31 14:05:48 +0000 |
| commit | 3fc55826cad90c650787e31c1726d5fc49b83892 (patch) | |
| tree | 896b386dd46c13e14feb8a14840e0db8565e370a /rotord | |
| parent | 834835c99dd9fd182ca3116b5bc3e7ae8b3815ad (diff) | |
audio thumbnails
Diffstat (limited to 'rotord')
| -rw-r--r-- | rotord/src/graph.cpp | 9 | ||||
| -rw-r--r-- | rotord/src/graph.h | 34 | ||||
| -rw-r--r-- | rotord/src/rendercontext.cpp | 1 |
3 files changed, 41 insertions, 3 deletions
diff --git a/rotord/src/graph.cpp b/rotord/src/graph.cpp index c33c59d..3f1d02b 100644 --- a/rotord/src/graph.cpp +++ b/rotord/src/graph.cpp @@ -566,9 +566,12 @@ bool Graph::load_audio(const string &filename,vector<Audio_processor*> processor Logger& logger = Logger::get("Rotor"); logger.information("Analysing "+filename); - audio_loaded=false; + //audio_loaded=false; libav::audio_decoder loader; - loader.open(filename); + if (!loader.open(filename)) { + logger.error("ERROR: Could not open audio: "+filename); + return false; + } duration=loader.get_duration(); @@ -612,7 +615,7 @@ bool Graph::load_audio(const string &filename,vector<Audio_processor*> processor } logger.information("Finished audio analysis"); - audio_loaded=true; + //audio_loaded=true; return true; } bool Graph::load_video(const string &nodeID,const string &filename){ diff --git a/rotord/src/graph.h b/rotord/src/graph.h index 2f8843d..70a7e3a 100644 --- a/rotord/src/graph.h +++ b/rotord/src/graph.h @@ -144,6 +144,40 @@ namespace Rotor { return true; } } + //fall back to audio + libav::audio_decoder loader; + if (loader.open(inputfilename)) { + Audio_thumbnailer at; + at.width=w; + at.height=h; + int rate = loader.get_sample_rate(); + int samples = loader.get_number_samples(); + int channels= loader.get_number_channels(); + int bits = loader.get_bit_depth(); + at.init(channels,bits,samples,rate); + bool finished=false; + uint16_t *audio=new uint16_t[1024*loader.get_number_channels()]; + uint64_t sample=0; + while (loader.get_samples(audio,sample,1024)) { + at.process_frame((uint8_t*)audio,1024); + sample+=1024; + } + cv::Mat co=cv::Mat(h,w,CV_8UC3); + uchar op; + for (int i=0;i<h;i++){ + uchar* r=co.ptr(i); //pointer to row + for (int j=0;j<w;j++){ + //audio rms in 0..1 range + if (at.audiodata[j]>abs(((float)i-h/2)/(h/2))) op=0xFF; + else op=0x00; + r[j*3]=op/4; + r[j*3+1]=op; + r[j*3+2]=op/4; + } + } + cv::imwrite(outputfilename.c_str(),co); + return true; + } return false; } private: diff --git a/rotord/src/rendercontext.cpp b/rotord/src/rendercontext.cpp index 359116f..779a1b7 100644 --- a/rotord/src/rendercontext.cpp +++ b/rotord/src/rendercontext.cpp @@ -24,6 +24,7 @@ void Render_context::runTask() { } } if (graph.load_audio(graph.audio_filename,processors)) { + graph.audio_loaded=false; state=IDLE; } else { |
