summaryrefslogtreecommitdiff
path: root/rotord
diff options
context:
space:
mode:
authorComment <tim@gray.(none)>2013-03-21 07:43:40 +0000
committerComment <tim@gray.(none)>2013-03-21 07:43:40 +0000
commit21d64e94be3112ea95dbe62a165fb6e2a67ef1e1 (patch)
tree85f116d3196cf8cf933606fc966bf75670d038bc /rotord
parent2b7aa6e5084441cdd82a2c7060e510ea423c0381 (diff)
working on avcodec interface
Diffstat (limited to 'rotord')
-rw-r--r--rotord/rotor.cpp50
-rwxr-xr-xrotord/rotor.h2
-rwxr-xr-xrotord/rotord.cpp14
3 files changed, 53 insertions, 13 deletions
diff --git a/rotord/rotor.cpp b/rotord/rotor.cpp
index 931bfa9..0a3a502 100644
--- a/rotord/rotor.cpp
+++ b/rotord/rotor.cpp
@@ -32,9 +32,10 @@ void Render_context::runTask() {
//audio_analyser.process(audio_filename);
//vampHost::runPlugin("","qm-vamp-plugins","qm-tempotracker", "",0, audio_filename, cerr,true);
vector<base_audio_processor*> proc;
- load_audio(audio_filename,proc);
-
- state=AUDIO_READY;
+ if (load_audio(audio_filename,proc)) {
+ state=AUDIO_READY;
+ }
+ else state=IDLE;
}
sleep(100);
}
@@ -269,7 +270,7 @@ Command_response Render_context::session_command(const std::vector<std::string>&
//http://blog.tomaka17.com/2012/03/libavcodeclibavformat-tutorial/
//great to use c++11 features
-bool Render_context::load_audio(string &filename,vector<base_audio_processor*> processors){
+bool Render_context::load_audio(const string &filename,vector<base_audio_processor*> processors){
//load audio data from file
//what's the best way to use this? the model is background processing, and we want to update a progress bar
//could pass a function pointer to call when each chunk of data becomes available?
@@ -279,7 +280,17 @@ bool Render_context::load_audio(string &filename,vector<base_audio_processor*> p
//there could even be an array of audio analysis functions to perform simultaneously?
//how about a vector of objects that subclass the base audio processor class?
- av_register_all();
+ //1st get parameters and initialise the processors
+ //then begin data loop locking progress variable after each frame
+
+ //
+ //
+ //the example in ffmpeg works, but it isn't one that identifies a codec- it is hard coded to look for a codec for AV_CODEC_ID_MP2
+ //it also doesn't load through libavformat - which opens containers- it just loads a naked .mp2 stream
+ //
+ //
+
+ av_register_all();
std::shared_ptr<AVFormatContext> avFormat(avformat_alloc_context(), &avformat_free_context);
@@ -294,7 +305,7 @@ bool Render_context::load_audio(string &filename,vector<base_audio_processor*> p
return false;
}
- av_dump_format(avFormat.get(), 0, 0, false);
+ av_dump_format(avFormat.get(), 0, 0, false); //avformat.h line 1256
AVStream* stream = nullptr;
for (unsigned int i = 0; i < avFormat->nb_streams; ++i) {
@@ -337,7 +348,6 @@ bool Render_context::load_audio(string &filename,vector<base_audio_processor*> p
//avcodec.h line 1026
- cerr << "audio codec context - sample rate: "<< audioCodec->sample_rate <<" ,channels: "<<audioCodec->channels<<" ,sample format: "<<audioCodec->sample_fmt<<endl;
Packet packet(avFormat.get());
if (packet.packet.data == nullptr) {
@@ -345,6 +355,9 @@ bool Render_context::load_audio(string &filename,vector<base_audio_processor*> p
return true;
}
+ cerr << "audio codec context - sample rate: "<< audioCodec->sample_rate <<", channels: "<<audioCodec->channels<<", sample format: "<<audioCodec->sample_fmt<<endl;
+
+
do {
packet.reset(avFormat.get());
if (packet.packet.stream_index != stream->index)
@@ -360,18 +373,25 @@ bool Render_context::load_audio(string &filename,vector<base_audio_processor*> p
size_t offsetInData = 0;
-
- /*
+ bool foundPacket=false;
+
// the decoding loop, running until EOF
while (true) {
// reading a packet using libavformat
if (offsetInData >= packet.packet.size) {
do {
packet.reset(avFormat.get());
- if (packet.stream_index != videoStream->index)
+ if (packet.packet.stream_index != stream->index)
continue;
} while(0);
+ if (!foundPacket){
+ cerr << "audio codec context - sample rate: "<< audioCodec->sample_rate <<", channels: "<<audioCodec->channels<<", sample format: "<<audioCodec->sample_fmt<<endl;
+ foundPacket=true;
+ }
+
}
+
+
// preparing the packet that we will send to libavcodec
AVPacket packetToSend;
@@ -380,13 +400,17 @@ bool Render_context::load_audio(string &filename,vector<base_audio_processor*> p
// sending data to libavcodec
int isFrameAvailable = 0;
- const auto processedLength = avcodec_decode_video2(avVideoCodec.get(), avFrame.get(), &isFrameAvailable, &packetToSend);
+ //const auto processedLength = avcodec_decode_video2(avVideoCodec.get(), avFrame.get(), &isFrameAvailable, &packetToSend);
+ const auto processedLength = avcodec_decode_audio4(audioCodec.get(), avFrame.get(), &isFrameAvailable, &packetToSend);
+
+
if (processedLength < 0) {
av_free_packet(&packet);
throw std::runtime_error("Error while processing the data");
}
offsetInData += processedLength;
+ /*
// processing the image if available
if (isFrameAvailable) {
// display image on the screen
@@ -395,8 +419,10 @@ bool Render_context::load_audio(string &filename,vector<base_audio_processor*> p
const auto msToWait = avVideoContext->ticks_per_frame * 1000 * avVideoContext->time_base.num / avVideoContext->time_base.den;
std::this_thread::sleep(std::chrono::milliseconds(msToWait));
}
+ */
+
}
- */
+
return true;
}
diff --git a/rotord/rotor.h b/rotord/rotor.h
index c7d25b2..5667b62 100755
--- a/rotord/rotor.h
+++ b/rotord/rotor.h
@@ -359,7 +359,7 @@ namespace Rotor {
int load_graph(Poco::UUID uid);
bool load_graph(string &graph_filename); //should eventually be as above
UUID save_graph(); //returns UUID of saved graph
- bool load_audio(string &filename,vector<base_audio_processor*> processors);
+ bool load_audio(const string &filename,vector<base_audio_processor*> processors);
Render_requirements get_requirements();
int load_video(int num,string &filename); //can be performance or clip
diff --git a/rotord/rotord.cpp b/rotord/rotord.cpp
index f0bcc0d..734e159 100755
--- a/rotord/rotord.cpp
+++ b/rotord/rotord.cpp
@@ -29,6 +29,20 @@ save a movie
how do we deal with frames in libavcodec - can we request a frame by number
how do we deal with resolution
+
+
+avcodec class
+what does it have to do?
+
+-open files (could be video, audio, or both)
+-process files i.e. thumbnail the audio or do audio analysis, make a no-keyframe proxy of a movie
+-retrieve video frames (with caching- what's the best way to approach this)
+
+just for a quick think through: signal data is trivial: 1 floating point number per frame.
+to store a whole uncompressed video track for a 3 minute @ 720.25p in RGB \= 12GB
+caching the whole thing isn't a goer
+
+
*/
RotorRequestHandler::RotorRequestHandler(const std::string& format): _format(format){