From 74d1f70bcde75dd1c1ef4d4a1673aa62014d4278 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Thu, 11 Apr 2013 18:34:59 +0100 Subject: first attempt to output video craqshes --- rotord/02.xml | 14 +++++ rotord/ValgrindOut.xml | 51 ++++++++++++++++++ rotord/rotor.cpp | 142 ++++++++++++++++++++++++++++++++++++++++++++++--- rotord/rotor.h | 2 +- rotord/style01.xml | 7 +++ rotord/style02.xml | 7 +++ 6 files changed, 215 insertions(+), 8 deletions(-) create mode 100644 rotord/02.xml create mode 100644 rotord/ValgrindOut.xml create mode 100644 rotord/style01.xml create mode 100644 rotord/style02.xml (limited to 'rotord') diff --git a/rotord/02.xml b/rotord/02.xml new file mode 100644 index 0000000..79c1b6c --- /dev/null +++ b/rotord/02.xml @@ -0,0 +1,14 @@ + +Off and on template ©Rotor 2013 + beats + + outputs 0 except when signal first passes a new integer: then 1 + signal to analyse + + outputs data when changed + signal to output + + renders the video + video to output + + diff --git a/rotord/ValgrindOut.xml b/rotord/ValgrindOut.xml new file mode 100644 index 0000000..f0b4b6d --- /dev/null +++ b/rotord/ValgrindOut.xml @@ -0,0 +1,51 @@ + + + + +4 +memcheck + + + Memcheck, a memory error detector + Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al. + Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info + Command: rotord + + +21214 +18095 +memcheck + + + + /usr/bin/valgrind.bin + --suppressions=/usr/lib/valgrind/debian-libc6-dbg.supp + --leak-check=yes + --xml=yes + --xml-file=ValgrindOut.xml + + + rotord + + + + + + RUNNING + + + + + + FINISHED + + + + + + + + + + + diff --git a/rotord/rotor.cpp b/rotord/rotor.cpp index 5736c2f..2da6a8b 100755 --- a/rotord/rotor.cpp +++ b/rotord/rotor.cpp @@ -25,7 +25,7 @@ void Render_context::runTask() { processors.push_back(audio_thumb); vector analysers=graph.find_nodes("audio_analysis"); for (auto a: analysers) { - processors.push_back(a); + processors.push_back(dynamic_cast(a)); } if (load_audio(audio_filename,processors)) { state=AUDIO_READY; @@ -308,7 +308,7 @@ bool Render_context::load_audio(const string &filename,vectorcodec == NULL) { av_free(frame); - av_close_input_file(formatContext); + avformat_close_input(&formatContext); std::cout << "Couldn't find a proper decoder" << std::endl; return false; } else if (avcodec_open2(codecContext, codecContext->codec, NULL) != 0) { av_free(frame); - av_close_input_file(formatContext); + avformat_close_input(&formatContext); std::cout << "Couldn't open the context with the decoder" << std::endl; return false; } @@ -378,7 +378,8 @@ bool Render_context::load_audio(const string &filename,vector"+ofToString(u)+"\n"); + v=u; + } + } + return true; + */ + //set up output context + //then iterate through frames + //querying graph at each frame + + av_register_all(); + + AVCodec *codec; + AVCodecContext *c= NULL; + int i, out_size, size, x, y, outbuf_size; + FILE *f; + AVFrame *picture; + uint8_t *outbuf, *picture_buf; + + cerr << "Rotor: rendering " << output_filename << " , " << duration << " seconds at " << framerate << " frames per second" << endl; + + /* find the mpeg1 video encoder */ + codec = avcodec_find_encoder(AV_CODEC_ID_H264); + if (!codec) { + cerr<< "codec not found" << endl; + return false; + } + + c= avcodec_alloc_context3(codec); + picture= avcodec_alloc_frame(); + + /* put sample parameters */ + c->bit_rate = 400000; + /* resolution must be a multiple of two */ + c->width = 640; + c->height = 250; + /* frames per second */ + c->time_base= (AVRational){1,25}; + c->gop_size = 10; /* emit one intra frame every ten frames */ + c->max_b_frames=1; + c->pix_fmt = PIX_FMT_YUV420P; //AV_PIX_FMT_RGB24 + + AVDictionary *options; + + /* open it */ + if (avcodec_open2(c, codec, &options) < 0) { + cerr << "could not open codec" << endl; + return false; + } + + f = fopen(output_filename.c_str(), "wb"); + if (!f) { + cerr << "could not open "<< output_filename<width * c->height; + picture_buf = malloc((size * 3) / 2); /* size for YUV 420 */ + + picture->data[0] = picture_buf; + picture->data[1] = picture->data[0] + size; + picture->data[2] = picture->data[1] + size / 4; + picture->linesize[0] = c->width; + picture->linesize[1] = c->width / 2; + picture->linesize[2] = c->width / 2; + + /* encode 1 second of video */ + for(i=0;i<25;i++) { + fflush(stdout); + /* prepare a dummy image */ + /* Y */ + for(y=0;yheight;y++) { + for(x=0;xwidth;x++) { + picture->data[0][y * picture->linesize[0] + x] = x + y + i * 3; + } + } + + /* Cb and Cr */ + for(y=0;yheight/2;y++) { + for(x=0;xwidth/2;x++) { + picture->data[1][y * picture->linesize[1] + x] = 128 + y + i * 2; + picture->data[2][y * picture->linesize[2] + x] = 64 + x + i * 5; + } + } + + /* encode the image */ + out_size = avcodec_encode_video(c, outbuf, outbuf_size, picture); + printf("encoding frame %3d (size=%5d)\n", i, out_size); + fwrite(outbuf, 1, out_size, f); + } + + /* get the delayed frames */ + for(; out_size; i++) { + fflush(stdout); + + out_size = avcodec_encode_video(c, outbuf, outbuf_size, NULL); + printf("write frame %3d (size=%5d)\n", i, out_size); + fwrite(outbuf, 1, out_size, f); + } + + /* add sequence end code to have a real mpeg file */ + outbuf[0] = 0x00; + outbuf[1] = 0x00; + outbuf[2] = 0x01; + outbuf[3] = 0xb7; + fwrite(outbuf, 1, 4, f); + fclose(f); + free(picture_buf); + free(outbuf); + + avcodec_close(c); + av_free(c); + av_free(picture); + printf("\n"); + + return true; } \ No newline at end of file diff --git a/rotord/rotor.h b/rotord/rotor.h index b0bfad2..4bba577 100755 --- a/rotord/rotor.h +++ b/rotord/rotor.h @@ -144,7 +144,7 @@ namespace Rotor { Time_spec(float _seconds,float _framerate){ seconds=_seconds; framerate=_framerate; }; float seconds; float framerate; - const Time_spec lastframe(){ + Time_spec lastframe(){ return Time_spec(seconds-(1.0f/framerate),framerate); } }; diff --git a/rotord/style01.xml b/rotord/style01.xml new file mode 100644 index 0000000..d2d2f46 --- /dev/null +++ b/rotord/style01.xml @@ -0,0 +1,7 @@ + diff --git a/rotord/style02.xml b/rotord/style02.xml new file mode 100644 index 0000000..d2d2f46 --- /dev/null +++ b/rotord/style02.xml @@ -0,0 +1,7 @@ + -- cgit v1.2.3