diff options
Diffstat (limited to 'rotord/rotor.cpp')
| -rwxr-xr-x | rotord/rotor.cpp | 94 |
1 files changed, 70 insertions, 24 deletions
diff --git a/rotord/rotor.cpp b/rotord/rotor.cpp index ee170f0..cffb929 100755 --- a/rotord/rotor.cpp +++ b/rotord/rotor.cpp @@ -486,6 +486,19 @@ bool Graph::load(string &filename){ } else cerr << "Rotor: linking input " << i2 << " of node: '" << nodeID << "', cannot find target '" << fromID << "'" << endl; } + int n3=xml.getNumTags("image_input"); + for (int i3=0;i3<n3;i3++){ + nodes[nodeID]->create_image_input(xml.getValue("image_input","",i3)); + string fromID=xml.getAttribute("image_input","from","",i2); + if (nodes.find(fromID)!=nodes.end()) { + if (!nodes[nodeID]->inputs[i3]->connect((Image_node*)nodes[fromID])){ + cerr << "Rotor: graph loader cannot connect input " << i3 << " of node '" << nodeID << "' to node '" << fromID << "'" << endl; + return false; + } + else cerr << "Rotor: linked input " << i3 << " of node '" << nodeID << "' to node '" << fromID << "'" << endl; + } + else cerr << "Rotor: linking input " << i3 << " of node: '" << nodeID << "', cannot find target '" << fromID << "'" << endl; + } xml.popTag(); } } @@ -507,6 +520,7 @@ Node_factory::Node_factory(){ add_type("divide",new Signal_divide()); add_type("bang",new Is_new_integer()); add_type("signal_output",new Signal_output()); + add_type("testcard",new Testcard()); add_type("video_output",new Video_output()); } bool Audio_thumbnailer::init(int _channels,int _bits,int _samples,int _rate) { @@ -742,18 +756,47 @@ bool Video_output::render(const float duration, const float framerate,const stri */ bool Video_output::render(const float duration, const float framerate,const string &output_filename,const string &audio_filename){ + // + //setup defaults + int outW=640; + int outH=480; + int bitRate=4000000; + int frameRate=25; + AVCodecID codecId=AV_CODEC_ID_H264; + std::string container ="mov"; + + + if (exporter->setup(outW,outH,bitRate,frameRate,codecId,container)) { + if (exporter->record(output_filename)) { + + cerr << "Rotor: Video_output rendering " << duration << " seconds at " << framerate << " fps" << endl; + float step=1.0f/framerate; + float v=0.0f; + for (float f=0.0f;f<duration;f+=step) { + exporter->encodeFrame(get_output(Frame_spec(f,framerate,outW,outH))->RGBdata); + } + exporter->finishRecord(); + return true; + } + } + + return false; +} + +//new version from libav examples +/* AVOutputFormat *fmt; AVFormatContext *oc; AVStream *audio_st, *video_st; double audio_pts, video_pts; int i; - /* Initialize libavcodec, and register all codecs and formats. */ + //Initialize libavcodec, and register all codecs and formats. // av_register_all(); //think about this: when to register and unregister? - /* Autodetect the output format from the name. default is MPEG. */ + //Autodetect the output format from the name. default is MPEG. // fmt = av_guess_format(NULL, output_filename.c_str(), NULL); if (!fmt) { printf("Could not deduce output format from file extension: using MPEG.\n"); @@ -764,7 +807,7 @@ bool Video_output::render(const float duration, const float framerate,const stri return false; } - /* Allocate the output media context. */ + //Allocate the output media context. // oc = avformat_alloc_context(); if (!oc) { cerr <<"Rotor: memory error"<< endl; @@ -773,8 +816,8 @@ bool Video_output::render(const float duration, const float framerate,const stri oc->oformat = fmt; snprintf(oc->filename, sizeof(oc->filename), "%s", filename); - /* Add the audio and video streams using the default format codecs - * and initialize the codecs. */ + //Add the audio and video streams using the default format codecs + * and initialize the codecs. // video_st = NULL; audio_st = NULL; if (fmt->video_codec != AV_CODEC_ID_NONE) { @@ -784,8 +827,8 @@ bool Video_output::render(const float duration, const float framerate,const stri audio_st = add_audio_stream(oc, fmt->audio_codec); } - /* Now that all the parameters are set, we can open the audio and - * video codecs and allocate the necessary encode buffers. */ + //Now that all the parameters are set, we can open the audio and + * video codecs and allocate the necessary encode buffers. // if (video_st) open_video(oc, video_st); if (audio_st) @@ -793,19 +836,19 @@ bool Video_output::render(const float duration, const float framerate,const stri av_dump_format(oc, 0, filename, 1); - /* open the output file, if needed */ + //open the output file, if needed // if (!(fmt->flags & AVFMT_NOFILE)) { if (avio_open(&oc->pb, filename, AVIO_FLAG_WRITE) < 0) { - fprintf(stderr, "Could not open '%s'\n", filename); - return 1; + cerr <<"Could not open "<<output_filename<<endl; + return false; } } - /* Write the stream header, if any. */ + //Write the stream header, if any. // avformat_write_header(oc, NULL); for (;;) { - /* Compute current audio and video time. */ + //Compute current audio and video time. // if (audio_st) audio_pts = (double)audio_st->pts.val * audio_st->time_base.num / audio_st->time_base.den; else @@ -821,7 +864,7 @@ bool Video_output::render(const float duration, const float framerate,const stri (!video_st || video_pts >= STREAM_DURATION)) break; - /* write interleaved audio and video frames */ + //write interleaved audio and video frames // if (!video_st || (video_st && audio_st && audio_pts < video_pts)) { write_audio_frame(oc, audio_st); } else { @@ -829,30 +872,33 @@ bool Video_output::render(const float duration, const float framerate,const stri } } - /* Write the trailer, if any. The trailer must be written before you - * close the CodecContexts open when you wrote the header; otherwise - * av_write_trailer() may try to use memory that was freed on - * av_codec_close(). */ - av_write_trailer(oc); + //Write the trailer, if any. The trailer must be written before you + // close the CodecContexts open when you wrote the header; otherwise + // av_write_trailer() may try to use memory that was freed on + // av_codec_close(). // + //av_write_trailer(oc); - /* Close each codec. */ + //Close each codec. // if (video_st) close_video(oc, video_st); if (audio_st) close_audio(oc, audio_st); - /* Free the streams. */ + //Free the streams. // for (i = 0; i < oc->nb_streams; i++) { av_freep(&oc->streams[i]->codec); av_freep(&oc->streams[i]); } if (!(fmt->flags & AVFMT_NOFILE)) - /* Close the output file. */ + //Close the output file. // avio_close(oc->pb); - /* free the stream */ + //free the stream // av_free(oc); - return 0; -}
\ No newline at end of file + return true; + */ + + + |
